Results 1 to 4 of 4

Thread: Forwarding to another controller?

  1. #1

    Default Forwarding to another controller?

    Im struggling to understand the exact use of Controllers for forwarding in Spring. I have worked through the simple tutorial ok but it doesnt cover the next stage, we cant use Webflow because we need to use an Offcial release.

    If I give an example could somebody please explain the correct controller to use, particular in reference to forwarding to another controller rathe than returning a view and model.

    I start off witha pseudo login.jsp
    This then calls the Spring Dispatcher
    This dispatches it to a Controller (Im not sure what type)
    This should then validate the login
    if the login is ok I want then forward to another controller which retrieve some data and then will return a model and a view (the data and a jsp to render it)
    If the login fails redisplay the login.jsp.

  2. #2

    Default

    Hi,

    in your case, you do not need to forward to another Controller. Making this could be done by something like:

    Code:
    return new ModelAndView(new RedirectView(...))
    However, simple validation can be done by creating an additional class that inherits Validator. By setting this validator for your Controller in the servlet definition, all you need is done automatically.

    Code:
    <bean id="myValidator" class="my.package.my.validator" />
    
    ...
    	<bean name="/myAction.do" class="my.package.myAction">
    		<property name="formView"><value>login</value></property>
    		<property name="commandName"><value>whatEverYouWant</value></property>
    		<property name="validator"><ref bean="myValidator" /></property>
    	</bean>
    So, when validation fails, it automatically returns to the formView; otherwise, it continues normally.

    Hope this helps.

    Kind regards,
    Simon

  3. #3

    Default

    Quote Originally Posted by simtin
    Hi,

    in your case, you do not need to forward to another Controller. Making this could be done by something like:

    Code:
    return new ModelAndView&#40;new RedirectView&#40;...&#41;&#41;
    Would this not then go to a jsp view for rendering. At this point I am not ready to display anything, I need to call a controller to retrieve the model. I needs to be another controller because it is dealing with stuff that is nothing to do with login and may be used in othe rplaces.

    Maybe RedirectDirect view can be used to go straight to this second controller, I dont know, but the name suggests it goes back to the client it would be more efficient to just foward onto another controller which would then return the view.

    Sorry,if ive completely misunderstood you.

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

    Default

    I think you want InternalResourceView.

    You can use "redirect:" and "forward:" as prefixed when returning the view name, or use RedirectView or InternalResourceView respectively to redirect or forward.

    I tend to use "redirect:" more than "forward:" so that if the user hits refresh, the browser then doesn't do another post.

Similar Threads

  1. Replies: 2
    Last Post: Dec 5th, 2006, 06:05 AM
  2. Replies: 17
    Last Post: Oct 4th, 2006, 09:44 AM
  3. Replies: 3
    Last Post: Sep 13th, 2005, 09:00 AM
  4. Replies: 4
    Last Post: Jun 30th, 2005, 11:28 PM
  5. Replies: 5
    Last Post: Dec 16th, 2004, 01:50 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
  •