Results 1 to 3 of 3

Thread: PropertyEditors problems with 2.0.0.RC1

  1. #1

    Default PropertyEditors problems with 2.0.0.RC1

    Hi,

    I have a problem with the propertyEditors in swf RC01

    If I register a property editors

    Code:
    public class BaseAction extends FormAction
    {
        
        @Override
        protected void registerPropertyEditors(final PropertyEditorRegistry registry)
        {
            registry.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor());
            final String formatDate = "yyyy-MM-dd";
            registry.registerCustomEditor(Date.class, 
                    new CustomDateEditor(new SimpleDateFormat(formatDate), true , formatDate.length()));
        }
        
        
    }
    and use it in my form
    Code:
    <form:errors path="stocks[${stockStatus.index}].availability" />
    where availability is a java.util.Date field of the bean Stock.

    I can post the form the date is parsed and correctly set in the bean

    But when I redisplay the format is lost, instead I have the string representation of the date as obtained by Date.toString().

    Any idea.

    And I can't find in the sample booking mvc of RC1 where the property editors for date string is registered while I can find it in the previous version.
    mic

  2. #2

    Default

    Hi

    I solved the problem myself

    Here is the situation : I display the form in this view state

    Code:
    <view-state id="edit">	
    		<on-render>	 	
    	 		<evaluate expression="productManager.reattach(product)" result="flowScope.product" />	 		 			
    		</on-render>
                    <transition on="save" to="save">
    			<evaluate expression="productAction.bindAndValidate"/>
    			<evaluate expression="productManager.save(product)" />
    		</transition>
    </view>
    edit.jsp has a date field

    Code:
    <form:input path="endPromotion" cssErrorClass="errors" size="10" />
    productAction register a dateEditor, but it doesn't help, because the first time we display the form edit.jsp, we do not call productAction. And thus the editor is ignored and the date is diplayed in the field simply calling the toString() method of java.util.Date.

    To make sure on what I'm saying I correctly filled the date field and manage to have a validation errors on an other part of the form, in this case we passed by productAction thus triggering the date editor and the date is correctly displayed in the field.

    The solution was simple just call productAction.setupForm to trigger the date editor.

    Code:
    <view-state id="edit">	
    		<on-render>	 	
    	 		<evaluate expression="productManager.reattach(product)" result="flowScope.product" />
                             <!-- force the use of the date editor -->
    	 		 <evaluate expression="productAction.setupForm" />		
    		</on-render>
                    <transition on="save" to="save">
    			<evaluate expression="productAction.bindAndValidate"/>
    			<evaluate expression="productManager.save(product)" />
    		</transition>
    </view>
    And the problem is solved.

    But this solution let me think that something is not really consitent, in one hand we want to get rid of all the action class by setting the model directly from the layer service and in the other we are still forced to call them to have data properly binded and displaid.

    In the 2.0.0RC1 booking-mvc sample we don't even call any Action class, and I guess that's why we introduce the model attribute.

    But I could not figure how you say to the model how to edit the date. But I guess the documentation on this point is coming soon
    mic

  3. #3

    Default

    I'm sorry I think I've found the "how to edit a date" in the model attribute.

    Is it provided by the @Basic annotation in the Booking bean of booking-mvc samples of 2.0.0.RC1 sample ?
    mic

Posting Permissions

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