Results 1 to 4 of 4

Thread: My own ConversationService.addConverter(Converter c) throws Exception

  1. #1

    Default My own ConversationService.addConverter(Converter c) throws Exception

    Hi,
    i have implemented my own conversationService to add a own StringToObject-Converter.
    Now i get a Exception. Has anybody a idea whats wrong?

    If i remove the addConverter(myownConverter) within the Constructor of my conversationService the applikation runs fine.
    I believe the error is inside my Converter.

    Second Question:
    Does anybody know how i inject the converter with my service? Can i use the @Autowire?

    Because my exception was very long an my message to long (over 10000 chars), I cut it a little bit.

    Thanks for help,
    alex


    The Coding:
    ===========


    weblow-config.xml
    Code:
    ...
        <!-- Configures the Spring Web Flow JSF integration -->
    	<faces:flow-builder-services id="facesFlowBuilderServices" conversion-service="conversionService"/>
    	
    	<bean id="conversionService" class="de.myapp.web.springframework.myappConversationService" />
    	...
    conversationService
    Code:
    	
    package de.myapp.web.springframework;
    
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    import org.springframework.binding.convert.service.DefaultConversionService;
    import de.myapp.bean.impl.UnterkunftTypImpl;
    import de.myapp.web.springframework.converter.StringToUnterkunftTyp;
    
    public class myappConversationService extends DefaultConversionService {
    	private final static Log LOGGER = LogFactory
    			.getLog(myappConversationService.class);
    
    	public myappConversationService() {
    		super();
    		// add my own converter here.
    		addConverter(new StringToUnterkunftTyp());
    		// add my own Aliases
    		//addAlias("unterkunftTyp", UnterkunftTypImpl.class);
    	}
    }
    my Converter StringToUnterkunftTyp
    Code:
    package de.myapp.web.springframework.converter;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.binding.convert.converters.InvalidFormatException;
    import org.springframework.binding.convert.converters.StringToObject;
    import org.springframework.util.StringUtils;
    
    import de.myapp.bean.UnterkunftTyp;
    import de.myapp.bean.impl.UnterkunftTypImpl;
    import de.myapp.service.UnterkunftTypService;
    
    public class StringToUnterkunftTyp extends StringToObject {
    
    	private transient UnterkunftTypService unterkunftTypService;
    	
    	public StringToUnterkunftTyp() {
    		super(UnterkunftTypImpl.class);
    	}
    	
    	/* (non-Javadoc)
    	 * @see org.springframework.binding.convert.converters.StringToObject#toObject(java.lang.String, java.lang.Class)
    	 */
    	@Override
    	public Object toObject(String string, Class targetClass) throws Exception {
    		if (!StringUtils.hasText(string)) {
    			return null;
    		}
    		try {
    			return unterkunftTypService.getUnterkunftTypById(new Integer(string));
    		} catch (Exception e) {
    			throw new InvalidFormatException(string, "unterkunftTyp", e);
    		}
    	}
    
    	public String toString(Object target) throws Exception {
    		UnterkunftTyp unterkunftTyp = (UnterkunftTyp) target;
    		if (unterkunftTyp == null) {
    			return "";
    		}
    		return unterkunftTyp.getOid().toString();
    	}
    
    	/**
    	 * @param unterkunftTypService the unterkunftTypService to set
    	 */
    	public void setUnterkunftTypService(UnterkunftTypService unterkunftTypService) {
    		this.unterkunftTypService = unterkunftTypService;
    	}
    	
    }
    exception:
    Code:
    ERROR: org.springframework.web.context.ContextLoader - Context initialization failed
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#0' defined in ServletContext resource [/WEB-INF/config/webmvc-config.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flowController' defined in ServletContext resource [/WEB-INF/config/webmvc-config.xml]: Cannot resolve reference to bean 'flowExecutor' while setting bean property 'flowExecutor'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flowExecutor': Cannot resolve reference to bean 'flowRegistry' while setting bean property 'flowDefinitionLocator'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flowRegistry': Cannot resolve reference to bean 'facesFlowBuilderServices' while setting bean property 'flowBuilderServices'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'facesFlowBuilderServices': Cannot resolve reference to bean 'conversionService' while setting bean property 'conversionService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'conversionService' defined in ServletContext resource [/WEB-INF/config/webflow-config.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [de.myapp.web.springframework.myappConversationService]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: de.myapp.web.springframework.myappConversationService.addConverter(Lorg/springframework/binding/convert/converters/Converter;)V
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:478)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    	at java.security.AccessController.doPrivileged(Native Method)
    ...
    ...
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'conversionService' defined in ServletContext resource [/WEB-INF/config/webflow-config.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [de.myapp.web.springframework.myappConversationService]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: de.myapp.web.springframework.myappConversationService.addConverter(Lorg/springframework/binding/convert/converters/Converter;)V
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:881)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:837)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:220)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:269)
    	... 91 more
    Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [de.myapp.web.springframework.myappConversationService]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: de.myapp.web.springframework.myappConversationService.addConverter(Lorg/springframework/binding/convert/converters/Converter;)V
    	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:111)
    	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:61)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:875)
    	... 102 more
    Caused by: java.lang.NoSuchMethodError: de.myapp.web.springframework.myappConversationService.addConverter(Lorg/springframework/binding/convert/converters/Converter;)V
    	at de.myapp.web.springframework.myappConversationService.<init>(myappConversationService.java:19)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    	at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
    	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:96)
    	... 104 more
    20.08.2008 17:29:58 org.apache.catalina.core.StandardContext start

  2. #2
    Join Date
    Aug 2004
    Location
    Melbourne, FL
    Posts
    2,794

    Default

    Looks like you have a environment problem - you might have an older version of spring-binding in your classpath. Make sure you have 2.0.3 or a 2.0.4 nightly build.
    Keith Donald
    Core Spring Development Team

  3. #3

    Default Konvertierungs-Fehler: Wert 'de.myApp.bean.impl.UnterkunftTypImpl@ac0a60[oid=2,bezeic

    Thanks.
    Now my application is starting (cleaned workdirectory of my server).

    One more Question about converter please.

    SWF don't call my own StringToUnterkunftTyp-Converter. Instead of i get an errormessage like this:
    Code:
    Konvertierungs-Fehler: Wert 'de.myApp.bean.impl.UnterkunftTypImpl@ac0a60[oid=2,bezeichnung=Haus]' für Modell 'null Converter'.

    I use facelets and JSF. Should i use the new converter feature of SWF or should i use the JSF-Converter Interface? I have read inside the reference.pdf that binder only for Spring MVC. Is it correct or can i use it with facelets too?

    my flow:
    Code:
    	<view-state id="add" model="Controller">
    		<binder>
    			<binding property="unterkunftTyp" converter="unterkunftTyp" />
    		</binder>
    		
    		<transition on="save" to="commitAndEnd">
    			<evaluate expression="Controller.save(flowRequestContext)" />
    		</transition>	
    		<transition on="chooseregion" to="regionchooser">
    		</transition>	
    		<transition on="reload" to="add">
    		</transition>	
    	</view-state>
    facelet:
    Code:
    	<h:selectOneListbox id="unterkunftTyp" value="#{bean.unterkunftTyp}">
    		<f:selectItems id="item" value="#{backingbean.unterkunftTypList}"/> 
    	</h:selectOneListbox>
    backingbean:
    Code:
    	private void initUnterkunftTypList(){
    		Collection list = unterkunftTypService.loadAll();
    		UnterkunftTyp unterkunftTyp;
    		this.unterkunftTypList = new ArrayList(10);
    		// put the Businessobjects in the map
    		for (Iterator iter=list.iterator();iter.hasNext();) {
    			unterkunftTyp = (UnterkunftTyp)iter.next();
    			SelectItem item = new SelectItem(unterkunftTyp, unterkunftTyp.getBezeichnung());
    			unterkunftTypList.add(item);
    		}
    	}
    thanks,
    alex

  4. #4
    Join Date
    Aug 2004
    Location
    Melbourne, FL
    Posts
    2,794

    Default

    Right now in a JSF env you have to use JSF's own converters. Watch http://jira.springframework.org/browse/SWF-799 though where we'll also allow binding converters to be work in a JSF env, too.

    Keith
    Keith Donald
    Core Spring Development Team

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •