Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Problems with ModelAndView in AbstractCommandController

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

    Default 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
    Carlos Santiago
    Sun Certified Professional
    my blog: http://macjava.blogspot.com/

  2. #2
    Join Date
    Aug 2004
    Location
    Southampton, UK
    Posts
    826

    Default

    Can you post the rest of your MVC related configuration?

    Rob
    Rob Harrop
    Lead Engineer, dm Server
    SpringSource
    http://www.springsource.com

    Co-Author - Pro Spring

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

    Default

    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
    Carlos Santiago
    Sun Certified Professional
    my blog: http://macjava.blogspot.com/

  4. #4
    Join Date
    Aug 2004
    Location
    Southampton, UK
    Posts
    826

    Default

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

    Rob
    Rob Harrop
    Lead Engineer, dm Server
    SpringSource
    http://www.springsource.com

    Co-Author - Pro Spring

  5. #5
    Join Date
    Sep 2005
    Location
    Toronto, Canada
    Posts
    42

    Default

    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

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

    Default

    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]
    Carlos Santiago
    Sun Certified Professional
    my blog: http://macjava.blogspot.com/

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

    Default

    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
    Carlos Santiago
    Sun Certified Professional
    my blog: http://macjava.blogspot.com/

  8. #8
    Join Date
    Jul 2005
    Location
    Idaho
    Posts
    231

    Default

    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

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

    Default

    Yes Steve may mapping is:
    Code:
    	<servlet-mapping>
        		<servlet-name>linkPecas</servlet-name>
        		<url-pattern>*.lpw</url-pattern>
      	</servlet-mapping>
    Carlos Santiago
    Sun Certified Professional
    my blog: http://macjava.blogspot.com/

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

    Default

    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
    Carlos Santiago
    Sun Certified Professional
    my blog: http://macjava.blogspot.com/

Similar Threads

  1. Replies: 37
    Last Post: Dec 6th, 2007, 10:02 AM
  2. RFE? Create fixed ModelAndView in XML
    By wangjammer5 in forum Container
    Replies: 4
    Last Post: Oct 5th, 2005, 09:07 AM
  3. simpleformcontroller & modelandview
    By yuer2084 in forum Web
    Replies: 2
    Last Post: Jul 27th, 2005, 04:07 AM
  4. MVC step-by-step problems
    By joegaber in forum Web
    Replies: 2
    Last Post: Jul 25th, 2005, 10:16 AM
  5. dependency problems?
    By asaf.lahav in forum Data
    Replies: 3
    Last Post: Jul 21st, 2005, 03:36 PM

Posting Permissions

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