Results 1 to 4 of 4

Thread: Strategy Controller, the probem !

  1. #1
    Join Date
    Jul 2005
    Location
    Cuiaba/MT - Brazil
    Posts
    41

    Default Strategy Controller, the probem !

    I have one jsp that he has several checkbox and a list of registers must be presented when the page is presented the first time.
    For this I am using a SimpleFormControler and overrinding its referenceData to set one map with the registers.
    However this jps has two icons that can be click to submit the selected data of checkbox.
    I submit these data for a AbstractCommandController and process these data, but my controller does not show jsp of success.
    Submit for the AbstractCommandController is made through Javascript. Which the best strategy of controller for this situation?
    Resume:
    I have a SimpleFormController that he shows jsp with the registers and in this jsp one javascript that submits form for a AbstractCommandController, and this functions well.
    However, the AbstractCommandController does not return any view that she is inserted in ModelAndView, also views that they do not exist do not launch errors.
    I do not know what he can be happening or if he is possible to make this with the Spring.
    Any aid will be coming well.
    My codes:
    the SimpleFormController
    Code:
    public class ListaFornecedoresControlador extends SimpleFormController {
        private Fornecedor fornecedor;
    
        protected Map referenceData(HttpServletRequest request) {
            return fornecedor.listaFornecedores();
        }
    
        protected ModelAndView onSubmit(HttpServletRequest request,
                HttpServletResponse response, Object obj, BindException erros)
                throws Exception {
            FornecedorBean bean = (FornecedorBean) obj;
    
            Map lista = fornecedor.listaFornecedoresPorTipo(new Integer(bean
                    .getTipoFornecedor()));
            return new ModelAndView(getSuccessView(), lista).addAllObjects(erros
                    .getModel());
        }
    
        /**
         * @param fornecedor
         *            seta o valor de fornecedor na variƔvel fornecedor.
         */
        public void setFornecedor(Fornecedor fornecedor) {
            this.fornecedor = fornecedor;
        }
    }
    the configuration file for this controller:
    <bean id="listaFornecedoresControlador" class="br.com.rodobens.web.fornecedor.ListaFornece doresControlador">
    <property name="sessionForm" value="true"/>
    <property name="commandName" value="fornecedor"/>
    <property name="commandClass" value="br.com.rodobens.beans.fornecedor.Fornecedor Bean"/>
    <property name="formView" value="fornecedor/ListaFornecedores"/>
    <property name="successView" value="fornecedor/ListaFornecedores"/>
    <property name="fornecedor" ref="fornecedor"/>
    </bean>
    .
    .
    .
    <bean id="statusFornecedoresControlador" class="br.com.rodobens.web.fornecedor.StatusFornec edoresControlador">
    <property name="fornecedor" ref="fornecedor"/>
    </bean>
    .
    .
    .
    <bean id="urlMapping" class="org.springframework.web.servlet.handler.Sim pleUrlHandlerMapping">
    <property name="mappings">
    <props>
    <prop key="/fornecedores/listaFornecedores.lpw">listaFornecedoresControlado r</prop>
    <prop key="/fornecedores/statusFornecedores.lpw">statusFornecedoresControla dor</prop>
    </props>
    </property>
    </bean>
    My AbstractCommandController:
    Code:
    public class StatusFornecedoresControlador extends AbstractCommandController&#123;
    
        private Fornecedor fornecedor;
        private static final String EXCLUIR = "excluir";
        private static final String INCLUIR = "incluir";
        
        public StatusFornecedoresControlador&#40;&#41;&#123;
            this.setCommandClass&#40;FornecedorBean.class&#41;;
        &#125;
    
        protected ModelAndView handle&#40;HttpServletRequest request,  HttpServletResponse response, 
                Object obj,  BindException erros&#41;  throws Exception &#123;
            FornecedorBean bean = &#40;FornecedorBean&#41;obj;
    
            if&#40;request.getParameter&#40;"parametro"&#41;.equals&#40;INCLUIR&#41;&#41;
                fornecedor.mudaStatusFornecedores&#40;new Integer&#40;DominioStatus.ATIVO&#41;, bean.getCodigoFornecedor&#40;&#41;&#41;;
            else if&#40;request.getParameter&#40;"parametro"&#41;.equals&#40;EXCLUIR&#41;&#41;
                fornecedor.mudaStatusFornecedores&#40;new Integer&#40;DominioStatus.INATIVO&#41;, bean.getCodigoFornecedor&#40;&#41;&#41;;
    
            return new ModelAndView&#40;"Sucesso"&#41;;
        &#125;
    
        /**
         * @param fornecedor  seta o valor de fornecedor na variƔvel fornecedor.
         */
        public void setFornecedor&#40;Fornecedor fornecedor&#41; &#123;
            this.fornecedor = fornecedor;
        &#125;
    &#125;
    and, finally, my jsp with javascript function:

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http&#58;//www.w3.org/TR/html4/loose.dtd">
    <%@ include file="/WEB-INF/views/includes.jsp" %>
    <html>
    
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    <script>
    	function enviaConsulta&#40;valor&#41;&#123;
    		document.forms&#91;0&#93;.tipoFornecedor.value=valor; 
    		document.forms&#91;0&#93;.submit&#40;&#41;; 
    	&#125;
    
    </script>
    
    <SCRIPT>
    function submitFunction&#40;valor&#41; &#123;
       if &#40;valor==1&#41;
       	document.forms&#91;0&#93;.action="listaFornecedores.lpw?parametro=excluir";
       
       if&#40;valor == 2&#41;
       	document.forms&#91;0&#93;.action="listaFornecedores.lpw?parametro=incluir";
    
       document.forms&#91;0&#93;.submit&#40;&#41;;
       &#125;
    </SCRIPT>
    <script language="JavaScript1.2" src="<c&#58;url value="/scripts/mm_menu.js"/>"></script>
    <%@ include file="/WEB-INF/views/menuLinkPecas.jsp"%>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title><fmt&#58;message key="title"/></title>
    <link rel="stylesheet"type="text/css" href="<c&#58;url value="/css/layout.css"/>" />
    </head>
    
    <body>
    
    <%@ include file="/WEB-INF/views/cabecalho.jsp"%>
    
    <FORM method="POST" action="listaFornecedores.lpw"/>
    
    <table width="768" height="27" border="0" cellpadding="0" cellspacing="0">
      <!--DWLayoutTable-->
      <tr>
        <td width="157" align="center"><!--DWLayoutEmptyCell--></td>
        <td width="611"><table width="584" border="0" class=fonte01>
            <tr>
        <td width="621"><img src="<c&#58;url value="/img/t_lst_fornecedor.gif"/>" width="248" height="30">
          <table width="554" border="0" class=fonte01>
            <tr>
              <td width="359" height="23">Selecione um fornecedor. <strong></strong></td>
              <td width="185"><div align="right">
                  <select class=fonte01 name="tipoFornecedor" onchange="enviaConsulta&#40;this.value&#41;">
                  <option>Selecione</option>
                    <option value=<%=DominioTipoFornecedor.TODOS %>>Todos os tipos</option>
                		<option value=<%=DominioTipoFornecedor.PRINCIPAL %>>Principal</option>
                		<option value=<%=DominioTipoFornecedor.SECUNDARIO %>>Secund&aacute;rio</option>
                  </select>
              </div></td>
            </tr>
          </table>
          <br>
          <table width="602" border="1" bordercolor="#999999" bgcolor="#999999" class=fonte01>
            <tr bordercolor="#999999" bgcolor="#999999">
              <td width="14"></td>
              <td width="130" bordercolor="#999999"><div align="left"><span class="style6">Nome</span></div></td>
              <td width="98" bordercolor="#999999"><div align="left"><span class="style6">Cidade</span></div></td>
              <td width="104" bordercolor="#999999"><div align="left"><span class="style6">Telefone</span></div></td>
              <td width="152" bordercolor="#999999"><div align="left"><span class="style6">Vendedor</span></div></td>
              <td width="64" bordercolor="#999999" class="style6">Status</td>
            </tr>
          </table>
          <table width="603" border="1" cellpadding="0" cellspacing="0" bordercolor="#F0F0F0" bgcolor="#F7F7F7" class=fonte01>
          
          <c&#58;forEach var="fornecedor" items="$&#123;listaFornecedoresAtivos&#125;">
            <tr>
              <td width="22"><div align="center">
              <spring&#58;bind path="fornecedor.codigoFornecedor">
                  <input type="checkbox" name="codigoFornecedor" value="<c&#58;out value="$&#123;fornecedor.codigoFornecedor&#125;"/>">
                            <!-- erro do campo -->
    			     <FONT color="red" size="0"><c&#58;out value="$&#123;status.errorMessage&#125;"/></FONT>
    			 </spring&#58;bind>
              </div></td>
              
    	          <td width="132"><div align="left"><c&#58;out value="$&#123;fornecedor.nomeFornecedor&#125;"/></div></td>
    	          <td width="103"><div align="left"><c&#58;out value="$&#123;fornecedor.cidade&#125;"/> </div></td>
    	          <td width="107"><div align="left"><c&#58;out value="$&#123;fornecedor.telefone&#125;"/> </div></td>
    	          <td width="156"><div align="left"><c&#58;out value="$&#123;fornecedor.nomeVendedor1&#125;"/> </div></td>          
    	          <td width="69">Ativo</td>
             
            </tr>    
            </c&#58;forEach>
    
          </table>
          <table width="58" border="0" cellspacing="0" cellpadding="0">
            <!--DWLayoutTable-->
            <tr valign="bottom">
              <td width="20" height="25"><div align="center"><a href=""  onClick="submitFunction&#40;1&#41;"><img src="<c&#58;url value="/img/trash.gif"/>" width="20" height="25" border="0"></a></div></td>
              <td width="38" class="fonte01">Excluir</td>
            </tr>
          </table>
          <br>
          <table width="602" border="1" bordercolor="#999999" bgcolor="#999999" class=fonte01>
            <tr bordercolor="#999999" bgcolor="#999999">
              <td width="14"></td>
              <td width="130" bordercolor="#999999"><div align="left"><span class="style6">Nome</span></div></td>
              <td width="98" bordercolor="#999999"><div align="left"><span class="style6">Cidade</span></div></td>
              <td width="104" bordercolor="#999999"><div align="left"><span class="style6">Telefone</span></div></td>
              <td width="152" bordercolor="#999999"><div align="left"><span class="style6">Vendedor</span></div></td>
              <td width="64" bordercolor="#999999" class="style6">Status</td>
            </tr>
          </table>
          <table width="603" border="1" cellpadding="0" cellspacing="0" bordercolor="#F0F0F0" bgcolor="#F7F7F7" class=fonte01>
          
          <c&#58;forEach var="fornecedor" items="$&#123;listaFornecedoresInativos&#125;">
            <tr>
              <td width="22"><div align="center">
                  <input type="checkbox" name="codigoFornecedor" value="<c&#58;out value="$&#123;fornecedor.codigoFornecedor&#125;"/>">
              </div></td>
    	          <td width="132"><div align="left"><c&#58;out value="$&#123;fornecedor.nomeFornecedor&#125;"/></div></td>
    	          <td width="103"><div align="left"><c&#58;out value="$&#123;fornecedor.cidade&#125;"/> </div></td>
    	          <td width="107"><div align="left"><c&#58;out value="$&#123;fornecedor.telefone&#125;"/> </div></td>
    	          <td width="156"><div align="left"><c&#58;out value="$&#123;fornecedor.nomeVendedor1&#125;"/> </div></td> 
              	  <td width="69">Inativo</td>
            </tr>
          </c&#58;forEach>
    
          </table>
          <table width="61" border="0" cellspacing="0" cellpadding="0">
            <!--DWLayoutTable-->
            <tr valign="bottom">
              <td width="24" height="25" class="fonte01"><a href=""  onClick="submitFunction&#40;2&#41;"><img src="<c&#58;url value="/img/certo.gif"/>" width="20" height="25" border="0"></a></td>
              <td width="37" class="fonte01">Incluir</td>
            </tr>
          </table>
          <p></p></td>
      </tr>
    </table>
    
    </body>
    </html>
    Carlos Santiago
    Sun Certified Professional
    my blog: http://macjava.blogspot.com/

  2. #2
    Join Date
    Jul 2005
    Location
    Cuiaba/MT - Brazil
    Posts
    41

    Default

    Help me, please !
    Carlos Santiago
    Sun Certified Professional
    my blog: http://macjava.blogspot.com/

  3. #3
    Join Date
    Jul 2005
    Location
    Cuiaba/MT - Brazil
    Posts
    41

    Default

    Hi again....
    It will be that nobody of the Spring type can help me in this question?
    An addend that I make is that I moved my to controller for a AbstractFormController, functions well, but also it does not redirect for view correct.
    It will be that I go to have that to come back to use Struts?
    Please....
    Carlos Santiago
    Sun Certified Professional
    my blog: http://macjava.blogspot.com/

  4. #4
    Join Date
    Jul 2005
    Location
    Cuiaba/MT - Brazil
    Posts
    41

    Default

    Observe this code:
    Code:
    public class StatusGrupoControlador extends AbstractFormController&#123;
        
        private Grupo grupo;
        private static final String EXCLUIR = "excluir";
        private static final String INCLUIR = "incluir";
        
        public StatusGrupoControlador&#40;&#41; &#123;
            setCommandClass&#40;GrupoBean.class&#41;;
        &#125;
        
        public ModelAndView showForm&#40;HttpServletRequest request, HttpServletResponse response, BindException errors&#41;
         throws Exception&#123;
            
            return new ModelAndView&#40;"Sucesso"&#41;;
        &#125;
         
        public ModelAndView processFormSubmission&#40;HttpServletRequest request,  HttpServletResponse response, 
                Object obj,  BindException erros&#41;  throws Exception &#123;
            
            GrupoBean bean = &#40;GrupoBean&#41;obj;
            
            if&#40;request.getParameter&#40;"parametro"&#41;.equals&#40;INCLUIR&#41;&#41;
                grupo.atualizaStatus&#40;new Integer&#40;DominioStatus.ATIVO&#41;, bean.getCodigoGrupo&#40;&#41;&#41;;
            else if&#40;request.getParameter&#40;"parametro"&#41;.equals&#40;EXCLUIR&#41;&#41;
                grupo.atualizaStatus&#40;new Integer&#40;DominioStatus.INATIVO&#41;, bean.getCodigoGrupo&#40;&#41;&#41;;
    
            return null;
        &#125;
    
        /**
         * @param grupo  seta o valor de grupo na variƔvel grupo.
         */
        public void setGrupo&#40;Grupo grupo&#41; &#123;
            this.grupo = grupo;
        &#125; 
    &#125;
    return null;
    This exactly, returns null and it does not give any error and no redirects for no place!
    Because it will be?[/code]
    Carlos Santiago
    Sun Certified Professional
    my blog: http://macjava.blogspot.com/

Similar Threads

  1. View to forward to another controller?
    By justinp in forum Web
    Replies: 6
    Last Post: Apr 2nd, 2010, 01:53 PM
  2. Question on Multi-Action Controller
    By jcheung in forum Container
    Replies: 3
    Last Post: Nov 26th, 2009, 06:58 AM
  3. Replies: 6
    Last Post: Jul 20th, 2007, 05:56 AM
  4. Controller forwaring
    By ojs in forum Web
    Replies: 5
    Last Post: Jul 11th, 2005, 02:10 AM
  5. Replies: 0
    Last Post: Sep 24th, 2004, 08:03 AM

Posting Permissions

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