Announcement Announcement Module
Collapse
No announcement yet.
How to validade form with AbstractCommandController ? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to validade form with AbstractCommandController ?

    Hi, I need help.
    It's possible validate a form using a AbstractCommandController ?
    How ? Please !
    Thanks.
    Carlos

  • #2
    Carlos,

    You should probably use SimpleFormController and use the built in validation workflow. Check out the JavaDocs for SFC for more details on how validation works.

    Rob

    Comment


    • #3
      Ok Rob.
      However, I have a form to display a list of Object, before it's submited !
      So, I use a AbstractCommandController that have a ModelAndView that show a form with a list.
      The submit of form go to SimpleFormController, however my context config not have a parameter "formView".
      See:
      <bean id="pedidosAutorizadosControlador" class="br.com.rodobens.web.pedidospecas.PedidosAut orizadosControlador">
      <property name="pedidosAutorizados" ref="pedidosAutorizados"/> <property name="commandName" value="pedidosAutorizadosBean" /> <property name="commandClass" value="br.com.rodobens.beans.pedidospecas.PedidosA utorizadosBean"/><property name="validator" ref="pedidosAutorizadosValidacao"/>
      </bean>
      So, not run OK.

      Comment


      • #4
        Carlos,

        You can still use just the SimpleFormController. Overriding the referenceData() method will allow you to set up your list of Objects for display in the form view.

        Rob

        Comment


        • #5
          Sorry Rob, but I not understand !
          Can show me an exemplo , please ?
          Thank's.
          Carlos

          Comment


          • #6
            Rob, I overring referenceData(), like this:
            Code:
            	protected Map referenceDate&#40;HttpServletRequest request&#41;&#123;
            	    Map lista = new HashMap&#40;&#41;;
            	    lista.put&#40;"pedidos", pedidosAutorizados.getListaPedidosAutorizados&#40;&#41;&#41;;
            	    return lista;
            	&#125;
            It's correct ?

            "pedidos" is the name of may collection in jsp.

            Code:
                    <c&#58;forEach var="pedidos" items="$&#123;pedidos&#125;">
                      <tr>
                        <td width="126"><c&#58;out value="$&#123;pedidos.numeroSinistro&#125;"/></td>
                        <td width="78"><a href="<c&#58;url value="/pedidosPecas/alteraPedido.lpw"/>"><c&#58;out value="$&#123;pedidos.numeroPedido&#125;"/></a>
                        
                         <FONT color="red" size="1">
                				<c&#58;out value="$&#123;status.errorMessage&#125;"/><br>
              			</FONT>
                        </td>
                        <td width="75"><c&#58;out value="$&#123;pedidos.placa&#125;"/></td>
                        <td width="133"><c&#58;out value="$&#123;pedidos.nomeOficina&#125;"/> </td>
                        <td width="145"><c&#58;out value="$&#123;pedidos.dsVeiculo&#125;"/> </td>
                      </tr>
            		</c&#58;forEach>
            My Controller:
            Code:
            	protected ModelAndView onSubmit&#40;Object obj, BindException erros&#41; throws Exception &#123;
            
            	    System.out.println&#40;"Entrei no Controlador ! "&#41;;
            	    
            		/* pega as informações do form e seta no bean */
            		PedidosAutorizadosBean bean = &#40;PedidosAutorizadosBean&#41;obj;
            		List pedidos = new ArrayList&#40;&#41;;
            
            		/* verifica qual botão de radio foi selecionado */
            		if&#40;bean.getBotaoRadio&#40;&#41;.equals&#40;DominioForm.PEDIDO&#41;&#41;
            			bean = pedidosAutorizados.getPedidosAutorizadosByNumeroPedido&#40;new Integer&#40;bean.getCampo&#40;&#41;&#41;&#41;;
            		else if&#40;bean.getBotaoRadio&#40;&#41;.equals&#40;DominioForm.SINISTRO&#41;&#41;
            			bean = pedidosAutorizados.getPedidosAutorizadosByNumeroSinistro&#40;bean.getCampo&#40;&#41;&#41;;
            		else if&#40;bean.getBotaoRadio&#40;&#41;.equals&#40;DominioForm.PLACA&#41;&#41;
            			bean = pedidosAutorizados.getPedidosAutorizadosByPlaca&#40;bean.getCampo&#40;&#41;&#41;;
            		
            		/* verifica se existe dados no bean */
            		if&#40;bean.getNumeroPedido&#40;&#41; > 0&#41;
            			pedidos.add&#40;bean&#41;;
            		
            		return new ModelAndView&#40;getSuccessView&#40;&#41;, "pedidos", pedidos&#41;;
            	&#125;
            However, I return to the same jsp, but with "pedidos" to iterate, it's possible with SimpleFormController ?
            Thank's
            Carlos

            Comment


            • #7
              Carlos,

              The referenceData() method will be called any time the form view is shown so you will always have your reference list data available.

              Rob

              Comment


              • #8
                It forgives Rod, but this is not happening.
                I changed mine return for
                Code:
                return new ModelAndView&#40;getSuccessView&#40;&#41;, "pedidos", pedidos&#41;.addAllObjects&#40;erros.getModel&#40;&#41;&#41;;
                and I obtain to show it my list, but in the first time where form is called it does not load the list and nor passes for referenceDate().
                What more he can be wrong?
                In my context:
                <bean id="urlMapping" class="org.springframework.web.servlet.handler.Sim pleUrlHandlerMapping">
                <property name="mappings">
                <props>
                <prop key="/pedidosPecas/pedidosAutorizados.lpw">pedidosAutorizadosControla dor</prop>
                </props>
                </property>
                </bean>
                .
                .
                .
                <bean id="pedidosAutorizadosControlador" class="br.com.rodobens.web.pedidospecas.PedidosAut orizadosControlador">
                <property name="sessionForm" value="true"/>
                <property name="commandName" value="pedidos"/>
                <property name="commandClass" value="br.com.rodobens.beans.pedidospecas.PedidosA utorizadosBean"/>
                <property name="validator" ref="pedidosAutorizadosValidacao"/>
                <property name="formView" value="pedidosPecas/PedidosAutorizados"/>
                <property name="successView" value="pedidosPecas/PedidosAutorizados"/>
                <property name="pedidosAutorizados" ref="pedidosAutorizados"/>
                </bean>
                Thank's
                Carlos

                Comment


                • #9
                  Lack of attention!
                  I did not see that referendeDatE(), would have to be referenceDatA(HttpServletRequest request)!
                  The application functions well.
                  Thank's Rod !

                  Comment

                  Working...
                  X