Announcement Announcement Module
Collapse
No announcement yet.
SWF 2.0 dont recognize my PropertyEditorRegistrar Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • SWF 2.0 dont recognize my PropertyEditorRegistrar

    Dear Members

    I am trying to reuse my PropertyEditorRegistrar and PropertyEditorSupport used with Spring MVC for SWF 2.0.x

    Below all my code

    Code:
    @Component("controlprematriculapropertyeditorregistrar")
    public class ControlPreMatriculaPropertyEditorRegistrar implements PropertyEditorRegistrar {
    	
    	private static final Logger logger = LoggerFactory.getLogger(ControlPreMatriculaPropertyEditorRegistrar.class);
    
    	public void registerCustomEditors(PropertyEditorRegistry registry) {
    		
    		SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
    		dateFormat.setLenient(false);		
    		registry.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
    		registry.registerCustomEditor(ControlPreMatricula.class, new ControlPreMatriculaPropertyEditorSupport());
    		registry.registerCustomEditor(Local.class, new LocalPropertyEditorSupport());
    		registry.registerCustomEditor(Curso.class, new CursoPropertyEditorSupport());
    		registry.registerCustomEditor(TipoTurno.class, new TipoTurnoPropertyEditorSupport());
    		registry.registerCustomEditor(Turno.class, new TurnoPropertyEditorSupport());
    
    	}
    }
    where for example a PropertyEditorSupport has the follow structure

    Code:
    @Component("localpropertyeditorsupport")
    public class LocalPropertyEditorSupport extends PropertyEditorSupport{
    
    	private static final Logger logger = LoggerFactory.getLogger(LocalPropertyEditorSupport.class);
    	
    	private LocalBoService localBoService;
    	
    	@Autowired
    	@Qualifier("localbo")
    	public void setLocalBoService(LocalBoService localBoService) {
    		this.localBoService = localBoService;
    	}
    	
    	public LocalPropertyEditorSupport() {		
    		super();	
    	}
    
    	public void setAsText(String text) throws IllegalArgumentException {
    		Integer idLocal = Integer.parseInt(text);
    		try{
    			Local local = this.localBoService.getLocalByIdLocal(idLocal);
    			setValue(local);
    		}
    		catch(MyGlobalException mge){
    		}
    	}
    	
    }
    Where such class is


    Code:
    @Table(name = "local")
    public class Local implements Serializable {
    
    	private static final long serialVersionUID = 1L;
    
    	private Integer idLocal;
    
    	private String estadoLocal;
    	
    	private String nombreLocal;
    ...
    My Action class is the follow (FormAction) (BTW I got the same results if the bold part below I move it into a constructor)

    Code:
    @Component("controlprematriculaaction")
    public class ControlPreMatriculaAction extends FormAction{
    
      ....
    
      @Override
      protected Object createFormObject(RequestContext context) throws Exception{
    				
    	logger.info("createFormObject");
    		
    	this.setValidator(this.controlPreMatriculaValidator);		    
            this.setPropertyEditorRegistrar(this.controlPreMatriculaPropertyEditorRegistrar);
    	this.setFormObjectClass(ControlPreMatricula.class);
    	this.setFormObjectName("controlPreMatriculaModel");
    	this.setFormObjectScope(ScopeType.FLOW);
    		
    	ControlPreMatricula controlPreMatricula = 
    		this.controlPreMatriculaBoService.crearControlPreMatricula();
    	controlPreMatricula.setFechaControlPreMatricula(new Date());
    					
    	return controlPreMatricula;
    }
    Below the view state

    Code:
    <view-state id="generarcontrolprematricula" 
                view="generarcontrolprematricula" 
                model="controlPreMatriculaModel">
       <on-render>
    	<evaluate expression="controlprematriculaaction.setupForm(flowRequestContext)" />
    	<evaluate expression="controlprematriculaaction.getAllRelationCollection(flowRequestContext)" />
       </on-render>
    	<transition on="next" to="controlprematriculacancelado" bind="true" validate="true"/>
    	<transition on="cancel" to="controlprematriculacancelado" bind="false" validate="false"/>		
    </view-state>
    Same result if I use only
    Code:
    <evaluate expression="controlprematriculaaction.setupForm" />
    The Web Form is

    Code:
    <form:form modelAttribute="controlPreMatriculaModel">		
         <table>
    	<tr>
    	<td><spring:message code="localSeleccion" text="No deberia aparecer" /></td>
    	<td>
    	<form:select path="local" id="listalocales" style="width: 300px" 
    			  items="${listalocales}"  
                              itemValue="idLocal"
                 		  itemLabel="nombreLocal" />
    	</td>
    	<td><form:errors path="local" class="error" /></td>
    	</tr>
    
               .....
               
             <tr>
    	 <td><spring:message code="fechaInicioDeseado"  /></td>
    	 <td>												  
    		<form:input path="fechaControlPreMatricula" size="45" readonly="readonly" />									
    	</td>
    	 <td><form:errors path="fechaControlPreMatricula" class="error" /></td>
    	</tr>
    About the date field always I got Wed Jul 06 00:00:00 COT 2011 format when the page is rendered.

    Therefore is not detected the follow
    Code:
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
    dateFormat.setLenient(false);		
    registry.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
    BTW I use this same code for Spring MVC and work fine, I see the expected format when the jsp page is rendered, therefore is not mandatory use <fmt:formatDate tag

    Other problem is when I do the submit event, I got for all my list or select tags or collections the follow error message typeMismatch on local, therefore my LocalPropertyEditorSupport are not working really, I wrote logger lines and always appear in my console/terminal, never I receive an error through there, (BTW even If I include logger lines in the catch scope, never appear when I execute the code, therefore none exception is thrown)


    why work for Spring MVC and not for SWF 2.0.x ?

    I have no ideas, please give me a hand

    Thanks in advanced

  • #2
    The problem here is you are mixing and old and new approach... Spring Web Flow uses Converters and Formatters (as Spring MVC 3 does) and not property editors anymore to do conversion. So instead of a PropertyEditorRegistrar you need a ConversionService to configure converts (I suggest the binding and type conversion chapter in the spring web flow reference guide).

    Comment


    • #3
      Hello Marten

      Thanks a lot for the guidance.

      I have already resolved this, I should write a tutorial on my Blog

      is really interesting how these new features does the things easier and reduce good amount of code

      Thank you

      Comment

      Working...
      X