Announcement Announcement Module
Collapse
No announcement yet.
Problem With Custom Property Editor Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem With Custom Property Editor

    I'm new comer on swf. I try to use custom property editor but not success yet.
    I have a entity BorrowingBook with two field have a Date property. I try to use propertyEditorRegistrar in my flow config look like this :

    Code:
     <bean id="borrowBookAction" class="org.springframework.webflow.action.FormAction">
            <property name="formObjectClass" value="org.kris.entity.BorrowingRecord"/>
            <property name="propertyEditorRegistrar" value="org.test.util.PropertyEditors"/>
        </bean>
    And this is my PropertyEditors implementation :
    Code:
    public class PropertyEditors implements PropertyEditorRegistrar{
    
        public void registerCustomEditors(PropertyEditorRegistry registry) {
            SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-mm-dd");
            dateFormat.setLenient(false);
            registry.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
        }
    }
    This class entity :
    Code:
    @Entity
    public class BorrowingRecord implements Serializable {
    
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        private Long id;
        private String isbn;
        @Temporal(javax.persistence.TemporalType.DATE)
        private Date borrowDate;
        @Temporal(javax.persistence.TemporalType.DATE)
        private Date returnDate;
        private String reader;
    but if i try to run this code i getting error look like this :
    Code:
    Caused by: java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [org.springframework.beans.PropertyEditorRegistrar] for property 'propertyEditorRegistrar': no matching editors or conversion strategy found
    I don't know how to use it with proper value with my entity class property. How to use property editor for spesific value ?
    Is there another way to use it ?

    Thanks lot before...
    Last edited by nyuby; Jan 31st, 2010, 08:06 AM.

  • #2
    i'm sory,, this is my little mistake,
    Problem solve....

    Comment


    • #3
      I am having difficulty with custom property editors using webflow. I followed the steps included in the documentation as well as numerous forms to setup the custom property editors in webflow. However, I was not successful in implementing the custom editors.
      • My requirement is when user enters a value into the amount attribute the custom property editor should strip off any $ or coma signs before validation
      • The custom attribute is of type "int" primitive data type

      The followins are my stup steps:

      1. I have registered the custom property editor using PropertyEditorRegistrar:

      Code:
      package com.ui.protools.web.customEditors;
      
      import org.springframework.beans.PropertyEditorRegistrar;
      import org.springframework.beans.PropertyEditorRegistry;
      
      public class AgencyLoginPropertyEditorRegistrar implements PropertyEditorRegistrar {
      	
      	/**
      	 * method to register custom property editors.
      	 */
      	public void registerCustomEditors(PropertyEditorRegistry registry) {
              registry.registerCustomEditor(int.class, new CustomIntEditor(Integer.class, true));
      	}	
      
      }
      2. I have injected the propertyEditorRegistrar into my FormAction:

      Code:
      <bean id="agencySearchDetailsAction" scope="prototype"
      		class="com.ui.protools.agency.web.controller.AgencySearchDetailsAction">
      		<property name="propertyEditorRegistrar" ref="agencyLoginPropertyEditorRegistrar" />
      		<property name="formObjectClass" value="com.ui.protools.domain.Bonds"/>
      		<property name="formObjectName" value="bondData"/>
      		<property name="formObjectScope" value="FLOW"/>
      	 </bean>
      3. I am calling setupForm method in my flow:

      Code:
      <view-state id="bondDetails" view="agency/bond_details"
      		model="bondData">
      
      		<on-entry>
      			<evaluate
      				expression="agencySearchDetailsAction.processBonds(flowRequestContext)" />
      		</on-entry>
      		<on-render>
      		     <evaluate
      				expression="agencySearchDetailsAction.setupForm(flowRequestContext)" />
      		</on-render>
      		<transition on="save" to="bondFinish">
      		  <evaluate
      				expression="agencySearchDetailsAction.bind(flowRequestContext)" />
      		 <evaluate
      				expression="agencySearchDetailsAction.saveBondData(flowRequestContext)" />
      		</transition>
      		<transition on="back" to="bondFinish" validate="false" />
      	</view-state>
      When I run the application in the debug mode, the custom editor is being registered and the formObject is getting bound.

      However, during the form submission, the custom editor setAsText() and getAsText() methods are not being called to strip off the additional characters within the amount filed before it reaches the validation class.

      Hence the amount attribute does not pass the validation and therefore, asks the user to re-enter the amount value.

      Just for your information, the validator class is build based on the webflow 2.0.7 documentation.
      create a class whose name has the pattern ${model}Validator, where ${model} is the capitialized form of the model expression, such as booking. Then define a public method with the name validate${state}, where ${state} is the id of your view-state, such as enterBookingDetails. The class should then be deployed as a Spring bean.
      What am I doing wrong? Why isn't the custom editor being invoked before the validator class? Any help is appreciated.

      Comment

      Working...
      X