struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@struts.apache.org
Subject [Apache Struts Wiki] New: ForwardingWithDifferentParameter
Date Tue, 01 Jun 2004 14:57:49 GMT
   Date: 2004-06-01T07:57:49
   Editor: IrfandhyFranciscus <enulljlist@yahoo.com.sg>
   Wiki: Apache Struts Wiki
   Page: ForwardingWithDifferentParameter
   URL: http://wiki.apache.org/struts/ForwardingWithDifferentParameter

     

New Page:

Describe ForwardingWithDifferentParameter here.

Acknowledgement:

This short tutorial is an extract from long discussion about forwarding to an action with
different parameters. Here are a list of people that contributed in the discussion:

 * Nimmons, Buster (originator)
 * Geeta Ramani
 * Arvind Rajpurohit
 * Robert Taylor
 * None None


Here is a snippet of the original question from Nimmons:

" ''I have an Action which is usualy accessed from an html form page... It
requires 4 request parameters. I need to forward to this action from another
action but the action I'm forwarding from does not have all 4 of the required
request parameters. I know what the value of the parameters should be but I
cannot put them in the request scope unless I use request.setAttribute()
however the action being forwarded to is not looking for the required
parameters from the Attributes but the requestParametes.. has anyone figured
out an easy way to modify the available requestParameters before forwarding'' " 

I encounter this problem when I was coding my soon to be personal homegrown weblog. This is
my problem:

I want to build a forum discussion for my weblog. In the forum I allow people to post replies
on certain threads. So I created a simple form for them to key in their post reply's title
(text field) and post's message (text area). After they finish filling in all the necessary
fields, I want to redirect them back to the ''topic page'' that they reply ? 

Topic page is a page where the user can view the full content of a topic message in the forum.


The way i show my topic content page is by including a parameter in my request ....do?dipatch=OpenTopic&'''topicID=123'''
The topic id is use to identify which forum topic that they are opeing so that I can load
the appropriate topic message from the database.

When user submit their post reply I direct them to my Action:

{{{

public class PostAction extends DispatchAction
{

    public ActionForward savePost(
                ActionMapping mapping,
                ActionForm form,
                HttpServletRequest request,
                HttpServletResponse response){

            //Saving the post
            return findMapping ( ??? ); //ooops how do I forward to the topic page, because
the topic page need a                              parameter?

    }
 


}

}}}

After reading the discussion in Struts mailing list I realize that the solution is so simple.
Geeta is the one who shed some light to this ActionForward thing.

So here what I do :

{{{

public class PostAction extends DispatchAction
{

    public ActionForward savePost(
                ActionMapping mapping,
                ActionForm form,
                HttpServletRequest request,
                HttpServletResponse response){

            //Saving the post
            ActionForward af = new ActionForward();
            af.setContextRelative(true);
            af.setPath("[my application relative path]/viewTopic.do?dispatch=viewTopic&topicID=123");

            return af;
    }

}

}}}

So now I can direct my user to view their post reply in the topic page.



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Mime
View raw message