Announcement Announcement Module
Collapse
No announcement yet.
Binding object using form taglib in SWF? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Binding object using form taglib in SWF?

    Hi,
    please is there some way to use this in SWF?

    Code:
    <form:form commandName="user">
        <table>
            <tr>
                <td>First Name:</td>
                <td><form:input path="firstName" /></td>
            </tr>
            <tr>
                <td>Last Name:</td>
                <td><form:input path="lastName" /></td>
            </tr>
            <tr>
                <td colspan="3">
                    <input type="submit" value="Save Changes" />
                </td>
            </tr>
        </table>
    </form:form>
    The form tag is from Spring 2.0 e.g.:

    Code:
    <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
    I have a problem because this uses commandName and commandClass(SimpleFormController) but formObjectClass and formObjectName (FlowController) are used for binding in SWF.

    thanks

  • #2
    Shouldn't matter - the form tags should work with SWF despite the naming difference between "commandName" with SimpleFormController and "formObjectName" with FormAction. What error are you getting?

    Keith

    Comment


    • #3
      I agree with Keith. The naming differences in the attributes shouldn't make a difference - the concepts are the same as is the plumbing.

      Rob

      Comment


      • #4
        I use this class as FormAction
        Code:
        public class CustomerRegisterActionForm extends FormAction {
        	
        	public CustomerRegisterActionForm(){
        		setFormObjectClass(CustomerFormUser.class);
        		setFormObjectName("customerFormUser");
        	}
        }
        validator class
        Code:
        public class CustomerValidator implements Validator {
        
        	private UserService userService;
        
        	public void setUserService(UserService userService) {
        		this.userService = userService;
        	}
        
        	public boolean supports(Class candidate) {
        		return CustomerFormUser.class.isAssignableFrom(candidate);
        	}
        
        	public void validate(Object obj, Errors errors) {
        		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firsName", "errors.required", new String[]{"user.firstName"}, "");
        		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastName", "errors.required", new String[]{"user.lastName"}, "");
        		
        		CustomerFormUser customer = (CustomerFormUser) obj;
        
        		if (userService.isLoginFree(customer.getLogin()) == false) {
        			errors.rejectValue("login", "errors.existing.user");
        		}
        
        		if (customer.getPassword() != customer.getConfirmPassword()) {
        			errors.rejectValue("password", "errors.twofields", new String[]{"user.password", "user.confirmPassword"}, "");
        		}
        		
        		if (customer.getEmail().contains("@") == false){
        			errors.rejectValue("email", "errors.email", new String[]{customer.getEmail()}, "");
        		}
        		
        		try {
        			Integer.parseInt(customer.getTelephone());
        		} catch (NumberFormatException e) {
        			errors.rejectValue("telephone", "errors.integer", new String[]{customer.getTelephone()}, "");
        		}
        	}
        
        }

        my beans
        Code:
        <beans>
        
        	<bean id="flowExecutor" class="org.springframework.webflow.executor.FlowExecutorImpl">
                <constructor-arg ref="repositoryFactory"/>
            </bean>
        
            <bean id="repositoryFactory" class="org.springframework.webflow.execution.repository.continuation.ContinuationFlowExecutionRepositoryFactory">
                <constructor-arg ref="flowRegistry"/>
            </bean>
          
            <bean id="flowRegistry" class="org.springframework.webflow.registry.XmlFlowRegistryFactoryBean">
                <property name="flowLocations" value="/WEB-INF/flows/**/*-flow.xml"/>
            </bean>
                
                
                
            <!-- Validators -->
            <bean id="customerValidator" class="cz.sw.web.validator.CustomerValidator">
            	<property name="userService" ref="userService"/>
            </bean>
            
            
            <!-- FormActions -->
        	<bean id="customerRegisterAction" class="cz.sw.web.action.flow.CustomerRegisterActionForm">
        		<property name="validator" ref="customerValidator"/>
        	</bean>
        </beans>
        
        
        <bean id="flowController" class="org.springframework.webflow.executor.mvc.FlowController">
                 <property name="flowExecutor" ref="flowExecutor"/>
            </bean>
        
        <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
                <property name="mappings">
                    <props>
                        <prop key="/register.html">flowController</prop>
                    </props>
                </property>
            </bean>

        register-custromer-flow.xml
        Code:
        <flow start-state="enterCustomerDetails">
        
        	<view-state id="enterCustomerDetails" view="customerRegisterForm">
        		<transition on="submit" to="processCustomerDetails" />
        	</view-state>
        
        
        	<action-state id="processCustomerDetails">
        		<action bean="customerRegisterAction" method="bindAndValidate" />
        		<transition on="success" to="enterEnquiryDetails" />
        		<transition on="error" to="enterCustomerDetails" />
        	</action-state>
        	
        	
        	<view-state id="enterEnquiryDetails">
        		<transition on="submit" to="processEnquiryDetails" />
        	</view-state>
        
        
        	<action-state id="processEnquiryDetails">
        		<action bean="customerRegisterAction" method="bindAndValidate" />
        		<transition on="success" to="displayConfirmation" />
        		<transition on="error" to="enterEnquiryDetails" />
        	</action-state>
        
        
        	<view-state id="displayConfirmation" view="confirmation">
        		<transition on="back" to="enterCustomerDetails" />
        	</view-state>
        
        </flow>
        and on page ....app.html?_flowId=register-customer-flow
        Code:
        ERROR - Neither Errors instance nor plain target object for bean name 'customerFormUser' available as request attribute
        java.lang.IllegalStateException: Neither Errors instance nor plain target object for bean name 'customerFormUser' available as request attribute
        	at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:137)
        	at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:157)
        	at org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.resolveCssClass(AbstractHtmlElementTag.java:502)
        	at org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:479)
        	at org.springframework.web.servlet.tags.form.AbstractHtmlInputElementTag.writeDefaultAttributes(AbstractHtmlInputElementTag.java:171)
        	at org.springframework.web.servlet.tags.form.InputTag.writeTagContent(InputTag.java:187)
        	at org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:91)
        	at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:68)
        	at org.apache.jsp.WEB_002dINF.pages.customerRegisterForm_jsp._jspx_meth_form_input_0(customerRegisterForm_jsp.java:268)
        	at org.apache.jsp.WEB_002dINF.pages.customerRegisterForm_jsp._jspx_meth_form_form_0(customerRegisterForm_jsp.java:124)
        	at org.apache.jsp.WEB_002dINF.pages.customerRegisterForm_jsp._jspService(customerRegisterForm_jsp.java:88)
        	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
        	at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
        	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
        	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
        	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
        	at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
        	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
        	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        	at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:672)
        	at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:463)
        	at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:398)
        	at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301)
        	at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:112)
        	at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:248)
        	at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1055)
        	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:819)
        	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:728)
        	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:396)
        	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:350)
        	at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
        	at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
        	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
        	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:78)
        	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77)
        	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
        	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        	at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:174)
        	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77)
        	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
        	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        	at com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.java:118)
        	at com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:52)
        	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
        	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
        	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
        	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
        	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
        	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
        	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
        	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
        	at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
        	at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
        	at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
        	at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
        	at java.lang.Thread.run(Thread.java:595)

        thaks

        Comment


        • #5
          Now is working... I found two my errors. My backing object wasn't implement Serializable and in flow definition i add this

          Code:
          <entry-actions>
                          <action bean="customerRegisterAction" method="setupForm"/>
          </entry-actions>
          to the view state

          thaks to all

          Comment

          Working...
          X