Results 1 to 6 of 6

Thread: Form as View - Forwarding to another Controller

  1. #1
    Join Date
    Dec 2004
    Location
    Chesterfield, MO
    Posts
    2

    Default Form as View - Forwarding to another Controller

    Hello -

    I am fairly new to the Spring framework and have been working w/ it for the past couple of months. I selected it as the web framework for an off-hours project I am doing since it touts "simplicity" and that is kind of what I was looking for. I didn't really want the bloat of Struts for this particular project and had heard good things about Spring.

    Anyway, there is one simple thing that I am trying to do though that I just can't seem to find an example of anywhere.

    Basically, I have a search form where I would like the search form to remain in the same view (a JSP) as the results. Well, everything works fine and dandy until after the user submits their query and I try and hyrdrate the same JSP (as the form is in) w/ my results.

    The error I am getting seems to be related to the fact that the JSP no longer has access to the command object (i.e. formBackingObject) since i didn't route through the controller. I am also using the "bind" tag in my JSP.

    I also tried using a redirectView to go back to the controller and this doesn't work because then I lose my request scoped data that I put into the ModelAndView w/ the search results (the form backed object is created though).

    This seems simple (I know in Struts you can chain actions together to accomplish this) but I must be missing something.

    Any help at all would be greatly appreciated!
    Thanks, Greg

  2. #2
    Join Date
    Aug 2004
    Location
    Sydney
    Posts
    503

    Default

    what do you mean by this "...since i didn't route through the controller..."

    Maybe post some code?

    You're right in not using redirect view since that will reset your form state.

  3. #3
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    This seems simple (I know in Struts you can chain actions together to accomplish this) but I must be missing something.
    You can forward to another controller using the forward: prefix. This requires Spring 1.1.3.
    HTH
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  4. #4
    Join Date
    Oct 2004
    Location
    Palmas-TO, Brazil
    Posts
    92

    Default

    What about using the interface Controller instead of the class SimpleFormController?
    I did this way:
    Code:
    public class UnidadeController implements Controller {
        private final Log log = LogFactory.getLog(UnidadeController.class);
        private UnidadeManager mgr = null;
    
        public void setUnidadeManager(UnidadeManager unidadeManager) {
            this.mgr = unidadeManager;
        }
        
         public ModelAndView handleRequest(HttpServletRequest request,
                                          HttpServletResponse response)
        throws Exception {
            if (log.isDebugEnabled()) {
                log.debug("entering 'handleRequest' method...");
            }
            String cdClassificacaoInstitucional = null; 
            String cdEntidade = null;
            String dcEntidade = null;
            Map model = new HashMap();
            
    		cdClassificacaoInstitucional = request.getParameter("cdClassificacaoInstitucional");        
    		cdEntidade = request.getParameter("cdEntidade");
    		dcEntidade = request.getParameter("dcEntidade");
            //Primeira vez que este formulario for requisitado, a consulta será efetuada com valores default
            if (cdClassificacaoInstitucional == null){
              [u]model.put("entidades"[/u], mgr.getEntidadesPorCdClassificacao(new Integer(2)));        
               [u] model.put(Constants.UNIDADE_LIST[/u], mgr.getEntidadesPorCdClassificacao(new Integer(2)));        
            }else	if (cdEntidade == null){
                    model.put("entidades", mgr.getEntidadesPorCdClassificacao(Integer.valueOf(cdClassificacaoInstitucional)));        
                    model.put(Constants.UNIDADE_LIST, mgr.getEntidadesPorCdClassificacao(Integer.valueOf(cdClassificacaoInstitucional)));        
            	}else	if(cdEntidade == null || dcEntidade.length() == 0) {        
                        model.put("entidades", mgr.getEntidadesPorCdEntidadeMembroDE(Integer.valueOf(cdEntidade)));        
                        model.put(Constants.UNIDADE_LIST, mgr.getEntidadesPorCdEntidadeMembroDE(Integer.valueOf(cdEntidade)));        
            		}else  if (log.isDebugEnabled()) {
                            log.debug("Requisicoes subsequentes, neste caso o usuario OPTOU PELA CONSULTA PERSONALIZADA"+dcEntidade);
                        }
            			model.put("entidades", mgr.getEntidadesPorDcEntidade(Integer.valueOf(cdEntidade),dcEntidade));        
                        model.put(Constants.UNIDADE_LIST, mgr.getEntidadesPorDcEntidade(Integer.valueOf(cdEntidade),dcEntidade));        
            		}
            		
            	}
            }
            
            return new ModelAndView("unidadeList",model );
        }
    }
    I hope this help!
    Gilbeto

  5. #5

    Default

    Quote Originally Posted by irbouho
    You can forward to another controller using the forward: prefix. This requires Spring 1.1.3.
    HTH
    Please I don't understand, can you make a sample? forward:virtual address of controller ?
    One another question: I can use forward: also with SimpleMappingExceptionResolver ?

  6. #6
    Join Date
    Sep 2004
    Location
    Sacramento, CA
    Posts
    8

    Default

    If you want to return your command object to your form using a SimpleFormController, set sessionForm(true) for your controller then return showForm(request, errors, view) from your onSubmit method rather than returning a new ModelAndView. This will put the command object back into the session and make it available to the spring:bind tags.

Similar Threads

  1. Replies: 4
    Last Post: Sep 1st, 2010, 01:38 AM
  2. View to forward to another controller?
    By justinp in forum Web
    Replies: 6
    Last Post: Apr 2nd, 2010, 01:53 PM
  3. Replies: 6
    Last Post: Jul 20th, 2007, 05:56 AM
  4. Replies: 9
    Last Post: Nov 1st, 2005, 10:36 PM
  5. Replies: 0
    Last Post: Jun 10th, 2005, 08:22 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
  •