Announcement Announcement Module
Collapse
No announcement yet.
Custom editor configurer Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Custom editor configurer

    How do I make a custom editor configurer to convert an object type to a String?
    I already did what is written here, it gave me these error:
    Code:
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'net.streambuffer.kelurahan.model.Perumahan' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyAccessExceptionsException: PropertyAccessExceptionsException (1 errors); nested propertyAccessExceptions are: [org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [net.streambuffer.kelurahan.model.Rt] for property 'rt']
    	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:939)
    	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:731)
    	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:340)
    	org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBeanDefinition(BeanDefinitionValueResolver.java:147)
    	org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:96)
    	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:920)
    	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:731)
    	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:340)
    	org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:226)
    	org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:147)
    	org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:270)
    	org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:312)
    	org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:134)
    	org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:230)
    	org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:156)
    	org.springframework.web.context.ContextLoaderServlet.init(ContextLoaderServlet.java:81)
    	javax.servlet.GenericServlet.init(GenericServlet.java:211)
    	org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:625)
    	org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:431)
    	org.apache.catalina.startup.HostConfig.checkContextLastModified(HostConfig.java:849)
    	org.apache.catalina.startup.HostConfig.check(HostConfig.java:1085)
    	org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:327)
    	org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    	java.lang.Thread.run(Thread.java:595)
    This is my kelurahan-servlet.xml
    Code:
    <beans>
        <bean id="customEditorConfigurer" class="org.springframework.beans.factory.config.CustomEditorConfigurer">
      	<property name="customEditors">
        <map>
          <entry key="net.streambuffer.kelurahan.model.Rt">
            <bean class="net.streambuffer.kelurahan.logic.RtPropsEditor">
              <property name="format" value="upperCase"/>
            </bean>
          </entry>
        </map>
      	</property>
    	</bean>
    	
    </beans>
    And my applicationContext.xml
    Code:
    <beans>
        <bean id="perumahan" parent="baseTransactionProxy">
        <property name="target">
    		<bean class="net.streambuffer.kelurahan.dao.PerumahanDao">
    			<property name="sessionFactory" ref="sessionFactory" />
    		</bean>
    	</property>
    	<property name="rumahRt">
    		<bean class="net.streambuffer.kelurahan.model.Perumahan">
    			<property name="rt"><value>rt</value></property>
    		</bean>
    	</property>
        </bean>
    </beans>
    My net.streambuffer.kelurahan.logic.RtPropsEditor:
    Code:
    public class RtPropsEditor extends PropertyEditorSupport &#123;
        private String format;
    
        public void setFormat&#40;String format&#41; &#123;
            this.format = format;
        &#125;
        
    	public void setAsText&#40;Integer text&#41; throws IllegalArgumentException &#123;
    	    Rt rt=new Rt&#40;text&#41;;
    	    setValue&#40;rt&#41;;
    	&#125;
    
    	public String getAsText&#40;&#41; &#123;
    		Object value = getValue&#40;&#41;;
    		if &#40;value != null&#41; &#123;
    			return value.toString&#40;&#41;;
    		&#125; else &#123;
    			return "";
    		&#125;
    	&#125;
    &#125;
    Could anyone give me a clue of what I need to do?
    Thanks in advance.

  • #2
    I've got it fixed now, but what made me curious is that Hibernate forces Rt to have default constructor.

    Comment


    • #3
      See HB reference documentation - HB uses CGLib which requires a default constructor (in order to do clazz.newInstance()).

      Comment


      • #4
        Is there anyway I could disable this since I have to write

        Code:
        public myConstructor&#40;&#41;&#123;
           this.id=getId&#40;&#41;;
        &#125;
        I'm not sure whether that is the right way :-D

        Comment


        • #5
          What are you trying to do? why do you set your id using getId() - isn't the id already set (that's what getId() does no?)

          Comment


          • #6
            I'm making a default constructor. I've read hibernate doc saying that I should have a constructor with at least package visibility. But I still don't know what to write in a default constructor.

            Comment


            • #7
              But I still don't know what to write in a default constructor.
              Then maybe you should read the java tutorial. A default constructor exists by default in every class if you don't declare one. A constructor can be empty but that's something you should know before getting into HB, IMO.

              Comment

              Working...
              X