Announcement Announcement Module
Collapse
No announcement yet.
Problems with ModelAndView in AbstractCommandController Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problems with ModelAndView in AbstractCommandController

    Hi, I'm with problems to show my view success in AbstractCommandController.
    I insert any value in return new ModelAndView("any value"); and no errors occur and not show the correct view.
    My code is:

    Code:
        protected ModelAndView handle(HttpServletRequest request,  HttpServletResponse response, 
                Object obj,  BindException erros)  throws Exception {
            
            UsuarioBean bean = (UsuarioBean)obj;
            
            usuario.atualizaStatus(new Integer(DominioStatus.ATIVO), bean.getCodigoUsuario());
    
            return new ModelAndView("Success");
        }
    But, any erros occur and no show my JSP !
    Why ?
    Thank's
    Carlos

  • #2
    Can you post the rest of your MVC related configuration?

    Rob

    Comment


    • #3
      Hi Rob, thank's for its attention. He would like to say that I am reading its book Pro Spring and has been very good.
      He follows my code all.
      Not I understood because the ModelAndView is not redirecting for correct jsp. And nor because any inserted URL there not cause errors.

      Code:
      public class ExcluirUsuariosControlador extends AbstractCommandController{
          
          private Usuario usuario;
          
          public ExcluirUsuariosControlador(){
              this.setCommandClass(UsuarioBean.class);
          }
          
          protected ModelAndView handle(HttpServletRequest request,  HttpServletResponse response, 
                  Object obj,  BindException erros)  throws Exception {
              
              UsuarioBean bean = (UsuarioBean)obj;
              
              usuario.atualizaStatus(new Integer(DominioStatus.INATIVO), bean.getCodigoUsuario());
      
              return new ModelAndView("Success");
          }
      
      
          public void setUsuario(Usuario usuario) {
              this.usuario = usuario;
          }
      
      }
      Code:
      	<bean id="listaUsuariosControlador" class="br.com.rodobens.web.usuario.ListaUsuariosControlador" >
      		<property name="sessionForm" value="true"/>
      		<property name="commandName" value="usuario"/>
      		<property name="commandClass" value="br.com.rodobens.beans.usuario.UsuarioBean"/>
      		<!-- <property name="validator" ref="usuarioValidacao"/> -->
      		<property name="formView" value="controleAcesso/ListaUsuarios"/>
      		<property name="successView" value="controleAcesso/ListaUsuarios"/>
      		<property name="usuario" ref="usuario"/>	
      		<property name="grupo" ref="grupo"/>
      	</bean>	
      	<bean id="excluirUsuariosControlador" class="br.com.rodobens.web.usuario.ExcluirUsuariosControlador">
      		<property name="usuario" ref="usuario"/>
      	</bean>
              .
              .
              .
      	 <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
      		<property name="mappings">
      			<props>
                      <prop key="/controleAcesso/excluirUsuarios.lpw">excluirUsuariosControlador</prop>
                       <prop key="/controleAcesso/listaUsuarios.lpw">listaUsuarios</prop>
      			</props>
      		</property>
      	</bean> 
              .
              .
              .
      	<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
      		<property name="viewClass"><value>org.springframework.web.servlet.view.JstlView</value></property> 
      		<property name="prefix"><value>/WEB-INF/views/</value></property>
      		<property name="suffix"><value>.jsp</value></property>
      	</bean>
      The Success.jsp, for example, is in /WEB-INF/views and any outhers controllers show it's view.
      In the truth I would like that this my ModelAndView was for/acontroleacesso/listaUsuarios.lpw

      Comment


      • #4
        Is the controller actually getting invoked? I can't see anything wrong with the code or configuration for your controller.

        Rob

        Comment


        • #5
          this line in your view resolver config:

          <prop key="/controleAcesso/listaUsuarios.lpw">listaUsuarios</prop>

          shouldn't it be like this?:

          <prop key="/controleAcesso/listaUsuarios.lpw">listaUsuariosControlador</prop>

          because that's the name you've given the controller bean

          Comment


          • #6
            this line in your view resolver config:

            <prop key="/controleAcesso/listaUsuarios.lpw">listaUsuarios</prop>

            shouldn't it be like this?:

            <prop key="/controleAcesso/listaUsuarios.lpw">listaUsuariosControlador</prop>

            because that's the name you've given the controller bean
            Shan, the problem is not this, therefore reverifiquei my file of context and it is same OK. Because if I had indicated one context missed I I would get one exception, what he does not happen.
            Carlos[/quote]

            Comment


            • #7
              Rob, my AbstractCommandController is invoked from of one jps that it was renderizing by a SimpleFormController.
              I make submit with Javascript of this:
              Code:
              <SCRIPT>
              function submitFunction&#40;valor&#41; &#123;
                 if &#40;valor==1&#41;
                 	document.forms&#91;0&#93;.action="statusUsuarios.lpw?parametro=excluir";
                 
                 if&#40;valor == 2&#41;
                 	document.forms&#91;0&#93;.action="statusUsuarios.lpw?parametro=incluir";
              
                 document.forms&#91;0&#93;.submit&#40;&#41;;
                 &#125;
              </SCRIPT>
              The steps are:
              first: it calls view SimpleFormController.
              second: form is filled and envoy to the AbstractCommandController through submir of Javascript.
              third: it enters in abstractFormController and the data correctly are processed.
              4: view indicated in ModelAndView de AbstractCommandController does not go for any (or to quaquer another Controller), also with url's made a mistake and error does not occur some!
              fifth: jsp is static in jsp of the SimpleFormController.
              I am not it's happen !
              Thank's
              Carlos

              Comment


              • #8
                Carlos,
                How do you have your servlet mapping setup?
                Code:
                <servlet-mapping>
                        <servlet-name>SERVLETNAME</servlet-name>
                        <url-pattern>*.LPW</url-pattern>
                </servlet-mapping>
                Steve O

                Comment


                • #9
                  Yes Steve may mapping is:
                  Code:
                  	<servlet-mapping>
                      		<servlet-name>linkPecas</servlet-name>
                      		<url-pattern>*.lpw</url-pattern>
                    	</servlet-mapping>

                  Comment


                  • #10
                    Now I have this exception:
                    javax.servlet.ServletException: Invalid key [null] in model Map - only Strings allowed as model keys
                    And may ModelAndView is:
                    Code:
                    return new ModelAndView&#40;"Sucesso"&#41;.addAllObjects&#40;erros.getModel&#40;&#41;&#41;;
                    What's happen ?
                    Thank's
                    Carlos

                    Comment


                    • #11
                      I decided the problem of invalid key, but still I did not obtain to make the ModelAndView to go for some view, either it which it will be, it does not work.
                      Carlos

                      Comment


                      • #12
                        Carlos,

                        Looking at your bits of code, could the validation be the root of the problem? You have the Validator commented out in your posted code...

                        If you are going to render a SuccessView, would that mean that it has passed validation and the "erros.getModel()" would be empty (NULL)? That could be causing your ServletException.
                        http://java.sun.com/j2se/1.4.2/docs/.../util/Map.html may help.
                        Beyond:
                        For example, some implementations prohibit null keys and values, and some have restrictions on the types of their keys. Attempting to insert an ineligible key or value throws an unchecked exception, typically NullPointerException or ClassCastException.
                        I get a bit hazy.

                        Good Luck,

                        Steve O

                        Comment

                        Working...
                        X