You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ted Husted <hu...@apache.org> on 2001/07/31 15:48:44 UTC

Re: action-mapping: why must the action-Attribute path be equivalent to the name of the jsp?

At this time, the current ActionMapping is not exposed to the JSP, so it
really can't tell which ActionMapping was used to call it. (Though, it
would be cool they could;-)

You might want to route control first through an Action, and then to the
JSP. This way you can put something in the request context to help write
the control. Right now, the simplest thing would be to put two copies of
the button in your JSP, enclosed within logic:equal tags. The tags could
then check to see if they should write the button for TheFirstAction or
TheSecondAction. 

+ Action inserts "fire" bean into rquest context
+ Forward to JSP
+ JSP checks to see if fire==first. If so, write TheFirstAction button
+ JSP checks to see if fire==second. If so, write TheSecondActon button 

-Ted.


Peter.Spiessbach@bank-verlag.de wrote:
> 
> Hello,
> does anyone have an idea, how to use the same physical jsp page in different
> action mappings (with different actions).
> I do not see a way to describe that my action path should be a locigal path
> using a page, which does not fit to
> the pathname of the page.
> 
> Example:
>         JSP is page1.jsp with one button
>         if I call this page as /page1 it should fire TheFirstAction,
>         if I call this page as /page2 it should fire TheSecondAction
>         But which parameter in the action mapping gives me a possibilty to declare
> that page1.jsp
>         should be found as page1.jsp AND as page2.jsp?
> 
> <action-mappings>
>         <action path="/page1"
>                 type="TheFirstAction"
>                 name="Page1Form"
>                 NOTKNOWNATTRIBUTE="page1.jsp"
>                 <forward name="success" path="/page3.jsp"/>
>         </action>
> 
>         <action path="/page2"
>                 type="TheSecondAction"
>                 name="Page1Form"
>                 NOTKNOWNATTRIBUTE="page1.jsp"
>                 <forward name="success" path="/page4.jsp"/>
>         </action>
> <action-mappings>
> 
> The problem is: why must the action-Attribute path be equivalent to the name
> of the jsp?
> 
> If anyone has understood what I am looking for, I would be very happy and
> thankful for help....
> 
> Peter

Re: AW: AW: action-mapping: why must the action-Attribute path be equivalent to the name of the jsp?

Posted by John Yu <jo...@scioworks.com>.
Thanks for the explanation, Craig.
--
John

At 02:13 PM 8/5/2001 -0700, you wrote:
> >
> > Oh, I see. That's what the "parameter" attribute is for! Thanks.
>
>Well, that is what the "parameter" value is used for in this case, at
>least :-).  In practice, the "parameter" attribute is a way to pass a
>single string configuration value into an Action, and means whatever your
>action interprets it to mean.  This covers the common case of needing to
>be able to pass some special parameter from struts-config.xml to an
>action, without having to mess around with subclassing ActionMapping.
>
>
> >
> > At 10:26 AM 8/1/2001 -0700, you wrote:
> > >This mechanism is already available in Struts. Take a look at the
> > >DispatchAction class:
> > >
> > >http://jakarta.apache.org/struts/api/org/apache/struts/actions/Dispatch 
> Actio
> > >n.html
> > >
> > >--
> > >Martin Cooper
> > >

John Yu                       Scioworks Technologies
e: john@scioworks.com         w: +(65) 873 5989
w: http://www.scioworks.com   m: +(65) 9782 9610 

Re: AW: AW: action-mapping: why must the action-Attribute path be equivalent to the name of the jsp?

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Thu, 2 Aug 2001, John Yu wrote:

> Martin,
> 
> Oh, I see. That's what the "parameter" attribute is for! Thanks.

Well, that is what the "parameter" value is used for in this case, at
least :-).  In practice, the "parameter" attribute is a way to pass a
single string configuration value into an Action, and means whatever your
action interprets it to mean.  This covers the common case of needing to
be able to pass some special parameter from struts-config.xml to an
action, without having to mess around with subclassing ActionMapping.


> --
> John
> 

Craig



> 
> At 10:26 AM 8/1/2001 -0700, you wrote:
> >This mechanism is already available in Struts. Take a look at the
> >DispatchAction class:
> >
> >http://jakarta.apache.org/struts/api/org/apache/struts/actions/DispatchActio
> >n.html
> >
> >--
> >Martin Cooper
> >
> >
> >----- Original Message -----
> >From: "John Yu" <jo...@scioworks.com>
> >To: <st...@jakarta.apache.org>
> >Sent: Wednesday, August 01, 2001 1:48 AM
> >Subject: Re: AW: AW: action-mapping: why must the action-Attribute path be
> >equivalent to the name of the jsp?
> >
> >
> > > I share a similar concern.
> > >
> > > I'm wondering if it makes sense to extend Struts' mapping architecture
> > > so that it will also look into a 'magic' url parameter and dispatch
> > > accordingly.
> > >
> > > For example, if the URL is
> > >
> > >
> > >
> > > MyAction.do?subAction=Create
> > >
> > >
> > >
> > >
> > > the ActionServlet will dispatch the request to the MyActionCreate class
> > > given the following (enhanced) action mapping.
> > >
> > >   <action path="MyAction" subAction="Create" type="MyActionCreate" .../>
> > >
> > > This will make it easily to have forms with multiple buttons which
> > > require different actions.
> > > --
> > > John
> > >
> > >
> > > At 10:18 AM 8/1/2001 +0200, you wrote:
> > >
> > >
> > > Isn't it against the mvc philosophy to put navigation code (e.g.
> > > control)
> > > into
> > > a tag (e.g. view) ?
> > >
> > > -----Ursprungliche Nachricht-----
> > > Von: Ted Husted [ mailto:husted@apache.org <ma...@apache.org> ]
> > > Gesendet: Dienstag, 31. Juli 2001 18:42
> > > An: struts-user@jakarta.apache.org
> > > Betreff: Re: AW: action-mapping: why must the action-Attribute path be
> > > equivalent to the name of the jsp?
> > >
> > >
> > > The usual solution would be to design your forms to contain hidden
> > > fields that tell the Action which operation to perform with the next
> > > request. So typically, there would be one button with a hidden field
> > > that conveyed whether this was the "FirstAction" or the "SecondAction".
> > > These would all go back to a single Action that either performed all the
> > > operations, or forwarded onto another Action.
> > >
> > > If you will be using this button that much, you might also consider
> > > writing your own custom tag so the button could program itself from the
> > > request. In general, the request is meant to convey information to the
> > > presentation layer about how it is suppose to write itself.
> > >
> > > In my own projects, I am experimenting with ways to make the current
> > > ActionMappings available to the JSP, as they are to perform() and
> > > validate(), which starts to open several doors.
> > >
> > >
> > > Peter.Spiessbach@bank-verlag.de wrote:
> > > >
> > > > Thanks, at least it's a working work-around. But the ugly thing is,
> > > that
> > > in
> > > > both cases the same action is called and I am forced to call the
> > > "real"
> > > > action
> > > > from the first action depending on the pushed button.
> > > >
> > > > + Action inserts "fire" bean into rquest context
> > > > + Forward to JSP
> > > > + JSP checks to see if fire==first. If so, write TheFirstAction button
> > > > + JSP checks to see if fire==second. If so, write TheSecondActon
> > > button
> > > > + submit "fires" action
> > > > + action does nothing and forwards to the "real" action depending on
> > > the
> > > > button.
> > > >
> > > > In my real world the page will be reused at least 5 or six times. So
> > > rather
> > > > than
> > > > putting the "Control" part of MVC in the struts-config.xml I start
> > > > piggypacking info
> > > > in the request and analysing this in the dummy action.
> > > >
> > > > However again thanks.
> > > > Peter
> > >
> > > --
> > > John Yu                       Scioworks Technologies
> > > e: john@scioworks.com         w: +(65) 873 5989
> > > w:  <http://www.scioworks.com  /> http://www.scioworks.com
> > > <http://www.scioworks.com  />   m: +(65) 9782 9610
> > >
> > >
> 
> -- 
> John Yu                       Scioworks Technologies
> e: john@scioworks.com         w: +(65) 873 5989
> w: http://www.scioworks.com   m: +(65) 9782 9610 


Re: AW: AW: action-mapping: why must the action-Attribute path be equivalent to the name of the jsp?

Posted by John Yu <jo...@scioworks.com>.
Martin,

Oh, I see. That's what the "parameter" attribute is for! Thanks.
--
John


At 10:26 AM 8/1/2001 -0700, you wrote:
>This mechanism is already available in Struts. Take a look at the
>DispatchAction class:
>
>http://jakarta.apache.org/struts/api/org/apache/struts/actions/DispatchActio
>n.html
>
>--
>Martin Cooper
>
>
>----- Original Message -----
>From: "John Yu" <jo...@scioworks.com>
>To: <st...@jakarta.apache.org>
>Sent: Wednesday, August 01, 2001 1:48 AM
>Subject: Re: AW: AW: action-mapping: why must the action-Attribute path be
>equivalent to the name of the jsp?
>
>
> > I share a similar concern.
> >
> > I'm wondering if it makes sense to extend Struts' mapping architecture
> > so that it will also look into a 'magic' url parameter and dispatch
> > accordingly.
> >
> > For example, if the URL is
> >
> >
> >
> > MyAction.do?subAction=Create
> >
> >
> >
> >
> > the ActionServlet will dispatch the request to the MyActionCreate class
> > given the following (enhanced) action mapping.
> >
> >   <action path="MyAction" subAction="Create" type="MyActionCreate" .../>
> >
> > This will make it easily to have forms with multiple buttons which
> > require different actions.
> > --
> > John
> >
> >
> > At 10:18 AM 8/1/2001 +0200, you wrote:
> >
> >
> > Isn't it against the mvc philosophy to put navigation code (e.g.
> > control)
> > into
> > a tag (e.g. view) ?
> >
> > -----Ursprungliche Nachricht-----
> > Von: Ted Husted [ mailto:husted@apache.org <ma...@apache.org> ]
> > Gesendet: Dienstag, 31. Juli 2001 18:42
> > An: struts-user@jakarta.apache.org
> > Betreff: Re: AW: action-mapping: why must the action-Attribute path be
> > equivalent to the name of the jsp?
> >
> >
> > The usual solution would be to design your forms to contain hidden
> > fields that tell the Action which operation to perform with the next
> > request. So typically, there would be one button with a hidden field
> > that conveyed whether this was the "FirstAction" or the "SecondAction".
> > These would all go back to a single Action that either performed all the
> > operations, or forwarded onto another Action.
> >
> > If you will be using this button that much, you might also consider
> > writing your own custom tag so the button could program itself from the
> > request. In general, the request is meant to convey information to the
> > presentation layer about how it is suppose to write itself.
> >
> > In my own projects, I am experimenting with ways to make the current
> > ActionMappings available to the JSP, as they are to perform() and
> > validate(), which starts to open several doors.
> >
> >
> > Peter.Spiessbach@bank-verlag.de wrote:
> > >
> > > Thanks, at least it's a working work-around. But the ugly thing is,
> > that
> > in
> > > both cases the same action is called and I am forced to call the
> > "real"
> > > action
> > > from the first action depending on the pushed button.
> > >
> > > + Action inserts "fire" bean into rquest context
> > > + Forward to JSP
> > > + JSP checks to see if fire==first. If so, write TheFirstAction button
> > > + JSP checks to see if fire==second. If so, write TheSecondActon
> > button
> > > + submit "fires" action
> > > + action does nothing and forwards to the "real" action depending on
> > the
> > > button.
> > >
> > > In my real world the page will be reused at least 5 or six times. So
> > rather
> > > than
> > > putting the "Control" part of MVC in the struts-config.xml I start
> > > piggypacking info
> > > in the request and analysing this in the dummy action.
> > >
> > > However again thanks.
> > > Peter
> >
> > --
> > John Yu                       Scioworks Technologies
> > e: john@scioworks.com         w: +(65) 873 5989
> > w:  <http://www.scioworks.com  /> http://www.scioworks.com
> > <http://www.scioworks.com  />   m: +(65) 9782 9610
> >
> >

-- 
John Yu                       Scioworks Technologies
e: john@scioworks.com         w: +(65) 873 5989
w: http://www.scioworks.com   m: +(65) 9782 9610 

Re: AW: AW: action-mapping: why must the action-Attribute path be equivalent to the name of the jsp?

Posted by Martin Cooper <ma...@tumbleweed.com>.
This mechanism is already available in Struts. Take a look at the
DispatchAction class:

http://jakarta.apache.org/struts/api/org/apache/struts/actions/DispatchActio
n.html

--
Martin Cooper


----- Original Message -----
From: "John Yu" <jo...@scioworks.com>
To: <st...@jakarta.apache.org>
Sent: Wednesday, August 01, 2001 1:48 AM
Subject: Re: AW: AW: action-mapping: why must the action-Attribute path be
equivalent to the name of the jsp?


> I share a similar concern.
>
> I'm wondering if it makes sense to extend Struts' mapping architecture
> so that it will also look into a 'magic' url parameter and dispatch
> accordingly.
>
> For example, if the URL is
>
>
>
> MyAction.do?subAction=Create
>
>
>
>
> the ActionServlet will dispatch the request to the MyActionCreate class
> given the following (enhanced) action mapping.
>
>   <action path="MyAction" subAction="Create" type="MyActionCreate" .../>
>
> This will make it easily to have forms with multiple buttons which
> require different actions.
> --
> John
>
>
> At 10:18 AM 8/1/2001 +0200, you wrote:
>
>
> Isn't it against the mvc philosophy to put navigation code (e.g.
> control)
> into
> a tag (e.g. view) ?
>
> -----Ursprungliche Nachricht-----
> Von: Ted Husted [ mailto:husted@apache.org <ma...@apache.org> ]
> Gesendet: Dienstag, 31. Juli 2001 18:42
> An: struts-user@jakarta.apache.org
> Betreff: Re: AW: action-mapping: why must the action-Attribute path be
> equivalent to the name of the jsp?
>
>
> The usual solution would be to design your forms to contain hidden
> fields that tell the Action which operation to perform with the next
> request. So typically, there would be one button with a hidden field
> that conveyed whether this was the "FirstAction" or the "SecondAction".
> These would all go back to a single Action that either performed all the
> operations, or forwarded onto another Action.
>
> If you will be using this button that much, you might also consider
> writing your own custom tag so the button could program itself from the
> request. In general, the request is meant to convey information to the
> presentation layer about how it is suppose to write itself.
>
> In my own projects, I am experimenting with ways to make the current
> ActionMappings available to the JSP, as they are to perform() and
> validate(), which starts to open several doors.
>
>
> Peter.Spiessbach@bank-verlag.de wrote:
> >
> > Thanks, at least it's a working work-around. But the ugly thing is,
> that
> in
> > both cases the same action is called and I am forced to call the
> "real"
> > action
> > from the first action depending on the pushed button.
> >
> > + Action inserts "fire" bean into rquest context
> > + Forward to JSP
> > + JSP checks to see if fire==first. If so, write TheFirstAction button
> > + JSP checks to see if fire==second. If so, write TheSecondActon
> button
> > + submit "fires" action
> > + action does nothing and forwards to the "real" action depending on
> the
> > button.
> >
> > In my real world the page will be reused at least 5 or six times. So
> rather
> > than
> > putting the "Control" part of MVC in the struts-config.xml I start
> > piggypacking info
> > in the request and analysing this in the dummy action.
> >
> > However again thanks.
> > Peter
>
> --
> John Yu                       Scioworks Technologies
> e: john@scioworks.com         w: +(65) 873 5989
> w:  <http://www.scioworks.com  /> http://www.scioworks.com
> <http://www.scioworks.com  />   m: +(65) 9782 9610
>
>



Re: [LONG] Re: action-mapping: why must the action-Attributepath be equivalent to the name of the jsp?

Posted by John Yu <jo...@scioworks.com>.
Thanks, Ted.
--
John


At 08:01 AM 8/1/2001 -0400, you wrote:
>John Yu wrote:
> > I'm wondering if it makes sense to extend Struts' mapping architecture
> > so that it will also look into a 'magic' url parameter and dispatch
> > accordingly.
> >
> > For example, if the URL is
> >
> >      MyAction.do?subAction=Create
> >
> > the ActionServlet will dispatch the request to the MyActionCreate
> > class given the following (enhanced) action mapping.
> >
> >   <action path="MyAction" subAction="Create" type="MyActionCreate"
> > .../>
>
>
>Actions can forward to other ActionMappings, if the mappings are exposed
>as ActionForwards. If that's something you would like to do, you can use
>a generic dispatcher that would look for the "subaction" parameter and
>return the appropriate forward to another mapping.
>
>Here's an example perform() that can forward anywhere given
>"/do/Dispatch?forward=forwardName".
>
>   // -- Locals
>   ActionForward thisForward = null;
>   String wantForward = null;
>
>   // -- Check check request for forward
>   wantForward = request.getParameter("forward");
>
>   // -- If found, consult mappings
>   if (wantForward!=null)
>       thisForward = mapping.findForward(wantForward);
>
>   // -- If anything not found, dispatch error
>   if (thisForward==null) {
>       thisForward = mapping.findForward("error");
>       ActionErrors errors = new ActionErrors();
>       errors.add(ActionErrors.GLOBAL_ERROR,
>           new ActionError("action.missing.parameter"));
>       saveErrors(request, errors);
>   }
>
>   return thisForward;
>
>Here's a simple "Hello World" action to test it:
>
>     response.setContentType("text/plain");
>     PrintWriter writer = response.getWriter();
>     writer.println("Hello from: " + mapping.getPath());
>     return(null);
>
>And some sample mappings:
>
>     <!-- Dispatcher action mapping -->
>     <action
>         path="/Dispatch"
>         type="ext.http.DispatchForward"
>         scope="request"
>         validate="false">
>        <forward
>             name="test1"
>             path="/do/Test1"/>
>        <forward
>             name="test2"
>             path="/do/Test2"/>
>     </action>
>
>     <action
>         path="/Test1"
>         type="ext.http.Test1"
>         scope="request"
>         validate="false">
>     </action>
>
>     <action
>         path="/Test2"
>         type="ext.http.Test1"
>         scope="request"
>         validate="false">
>     </action>
>
>If you ask for "do/Dispatch?task=test1" you get "Hello from test1" if
>you open "do/Dispatch?task=test2" you get "Hello from test2". (Note that
>an Action knows which path is used to call it, which is another way you
>can have Actions do different things based on the mapping context.)
>
>I only just wrote this, and it seems OK, but be warned that it is alpha
>code ;o)
>
>A couple of things to keep in mind:
>
>+ You never really call an Action. You reference an ActionMapping, and
>the Controller calls the Action from that.
>
>+ The ActionForms are populated from the request when the controller
>invokes the Action for a mapping. So if you forward the request to
>another mapping, it would populate the form for that mapping from the
>forwarded request.
>
>+ Actions are not bound to ActionForms. The form is bound by the
>ActionMapping, and an Action can be used in any number of mappings.
>
>+ Many times developers use the same or related names for an Action and
>the path to an ActionMapping. That is only a convenience. In Struts, you
>can only specify a "logical" path to an ActionMapping. What is behind
>that mapping is determined by the configuration file, and therefore
>belongs to the controller layer.
>
>Meanwhile ... a similar thing to the DispatchForward class given above
>can be done using the optional DispatchAction class in Struts 1.0
>(org.apache.struts.actions.DispatchAction). Here you can create
>alternate "perform" methods in a single action, and call one or the
>another in the request. So you could have
>
>     public ActionForward retrieve(ActionMapping mapping, ...
>     public ActionForward update(ActionMapping mapping, ...
>
>and then call one or the other using "myDispatchAction?method=retrieve"
>or "myDispatchAction?method=update". See the Struts JavaDoc for details.
>
>Very neat, really.
>
>-Ted.

-- 
John Yu                       Scioworks Technologies
e: john@scioworks.com         w: +(65) 873 5989
w: http://www.scioworks.com   m: +(65) 9782 9610 

[LONG] Re: action-mapping: why must the action-Attributepath be equivalent to the name of the jsp?

Posted by Ted Husted <hu...@apache.org>.
John Yu wrote:
> I'm wondering if it makes sense to extend Struts' mapping architecture
> so that it will also look into a 'magic' url parameter and dispatch
> accordingly.
> 
> For example, if the URL is
> 
>      MyAction.do?subAction=Create
> 
> the ActionServlet will dispatch the request to the MyActionCreate
> class given the following (enhanced) action mapping.
> 
>   <action path="MyAction" subAction="Create" type="MyActionCreate"
> .../>


Actions can forward to other ActionMappings, if the mappings are exposed
as ActionForwards. If that's something you would like to do, you can use 
a generic dispatcher that would look for the "subaction" parameter and 
return the appropriate forward to another mapping.

Here's an example perform() that can forward anywhere given
"/do/Dispatch?forward=forwardName".

  // -- Locals
  ActionForward thisForward = null;
  String wantForward = null;

  // -- Check check request for forward
  wantForward = request.getParameter("forward");

  // -- If found, consult mappings
  if (wantForward!=null)
      thisForward = mapping.findForward(wantForward);

  // -- If anything not found, dispatch error
  if (thisForward==null) {
      thisForward = mapping.findForward("error");
      ActionErrors errors = new ActionErrors();
      errors.add(ActionErrors.GLOBAL_ERROR,
          new ActionError("action.missing.parameter"));
      saveErrors(request, errors);
  }

  return thisForward;

Here's a simple "Hello World" action to test it:

    response.setContentType("text/plain");
    PrintWriter writer = response.getWriter();
    writer.println("Hello from: " + mapping.getPath());
    return(null);

And some sample mappings:

    <!-- Dispatcher action mapping -->
    <action 
        path="/Dispatch"
        type="ext.http.DispatchForward"
        scope="request"
        validate="false">
       <forward
            name="test1"
            path="/do/Test1"/>
       <forward 
            name="test2"  
            path="/do/Test2"/>
    </action>

    <action 
        path="/Test1"
        type="ext.http.Test1"
        scope="request"
        validate="false">
    </action>

    <action 
        path="/Test2"
        type="ext.http.Test1"
        scope="request"
        validate="false">
    </action>

If you ask for "do/Dispatch?task=test1" you get "Hello from test1" if
you open "do/Dispatch?task=test2" you get "Hello from test2". (Note that
an Action knows which path is used to call it, which is another way you
can have Actions do different things based on the mapping context.) 

I only just wrote this, and it seems OK, but be warned that it is alpha
code ;o)

A couple of things to keep in mind: 

+ You never really call an Action. You reference an ActionMapping, and
the Controller calls the Action from that. 

+ The ActionForms are populated from the request when the controller
invokes the Action for a mapping. So if you forward the request to
another mapping, it would populate the form for that mapping from the
forwarded request. 

+ Actions are not bound to ActionForms. The form is bound by the 
ActionMapping, and an Action can be used in any number of mappings.

+ Many times developers use the same or related names for an Action and
the path to an ActionMapping. That is only a convenience. In Struts, you
can only specify a "logical" path to an ActionMapping. What is behind
that mapping is determined by the configuration file, and therefore 
belongs to the controller layer. 

Meanwhile ... a similar thing to the DispatchForward class given above 
can be done using the optional DispatchAction class in Struts 1.0
(org.apache.struts.actions.DispatchAction). Here you can create
alternate "perform" methods in a single action, and call one or the
another in the request. So you could have 

    public ActionForward retrieve(ActionMapping mapping, ...
    public ActionForward update(ActionMapping mapping, ...

and then call one or the other using "myDispatchAction?method=retrieve"
or "myDispatchAction?method=update". See the Struts JavaDoc for details.

Very neat, really.

-Ted.

Re: AW: AW: action-mapping: why must the action-Attribute path be equivalent to the name of the jsp?

Posted by John Yu <jo...@scioworks.com>.
I share a similar concern.

I'm wondering if it makes sense to extend Struts' mapping architecture so 
that it will also look into a 'magic' url parameter and dispatch accordingly.

For example, if the URL is
MyAction.do?subAction=Create

the ActionServlet will dispatch the request to the MyActionCreate class 
given the following (enhanced) action mapping.

   <action path="MyAction" subAction="Create" type="MyActionCreate" .../>

This will make it easily to have forms with multiple buttons which require 
different actions.
--
John


At 10:18 AM 8/1/2001 +0200, you wrote:
>Isn't it against the mvc philosophy to put navigation code (e.g. control)
>into
>a tag (e.g. view) ?
>
>-----Ursprungliche Nachricht-----
>Von: Ted Husted [mailto:husted@apache.org]
>Gesendet: Dienstag, 31. Juli 2001 18:42
>An: struts-user@jakarta.apache.org
>Betreff: Re: AW: action-mapping: why must the action-Attribute path be
>equivalent to the name of the jsp?
>
>
>The usual solution would be to design your forms to contain hidden
>fields that tell the Action which operation to perform with the next
>request. So typically, there would be one button with a hidden field
>that conveyed whether this was the "FirstAction" or the "SecondAction".
>These would all go back to a single Action that either performed all the
>operations, or forwarded onto another Action.
>
>If you will be using this button that much, you might also consider
>writing your own custom tag so the button could program itself from the
>request. In general, the request is meant to convey information to the
>presentation layer about how it is suppose to write itself.
>
>In my own projects, I am experimenting with ways to make the current
>ActionMappings available to the JSP, as they are to perform() and
>validate(), which starts to open several doors.
>
>
>Peter.Spiessbach@bank-verlag.de wrote:
> >
> > Thanks, at least it's a working work-around. But the ugly thing is, that
>in
> > both cases the same action is called and I am forced to call the "real"
> > action
> > from the first action depending on the pushed button.
> >
> > + Action inserts "fire" bean into rquest context
> > + Forward to JSP
> > + JSP checks to see if fire==first. If so, write TheFirstAction button
> > + JSP checks to see if fire==second. If so, write TheSecondActon button
> > + submit "fires" action
> > + action does nothing and forwards to the "real" action depending on the
> > button.
> >
> > In my real world the page will be reused at least 5 or six times. So
>rather
> > than
> > putting the "Control" part of MVC in the struts-config.xml I start
> > piggypacking info
> > in the request and analysing this in the dummy action.
> >
> > However again thanks.
> > Peter

-- 
John Yu                       Scioworks Technologies
e: john@scioworks.com         w: +(65) 873 5989
w: http://www.scioworks.com   m: +(65) 9782 9610 

Re: Included Actions

Posted by Dan Connelly <ds...@adelphia.net>.
Gregor says:     Output of an "included action" in a JSP.  I think I understand this.

I do something like it for my "Struts Inside of Struts" project.  In doing so I am pushing the FormBean concept to its logical (and absurd) conclusion.

My FormBean contains only a StringBuffer attribute.  The View JSP for this is extirely empty (almost) except for the expression of the StringBuffer.

The function of my (outer) Action is to just invoke an HTTP session on an inner Action (a Struts Action in some other application on some other server), then to capture the HTML output of that HTTP session, to modify some of its critical tag attributes and, finally, to stuff that HTML character stream into the StringBuffer of the ActionForm.

I really thought that this would have horrible display latency before I tried it.   Not really.  Its almost bearable.  But don't try it 3 deep.  


Dan Connelly    (who is not Dan Connolly)



PS.  

By the way, Struts works nicely for this absurd usage.  I will still claim I honored MVC, although my View is vacuous and the Model knows damn well how it is to be rendered (almost).   One disappointment in all this is java.net.HTTPSession.  It doesn't deal cookies, so this implementation has problems for Session Tracking under Struts.   

I am not the only person displeased by java.net.HTTPSession.  There are alternative classes that produce can transfer cookie values (from Tigris, for example).  I just haven't tried any of them yet.     

N.B., however, with respect to Struts, that if my action form's (viewable) text is really huge, StringBuffer is not goint to work out.  Struts would have to be re-architected into producer-consumer threads for the Model logic and the View (rendering) logic, respectively.  This is an interesting thought.

  

----- Original Message ----- 
From: "Gregor Rayman" <gr...@gmx.net>
To: <st...@jakarta.apache.org>
Sent: Tuesday, July 31, 2001 1:03 PM
Subject: Included Actions


> Hi all,
> 
> is it somehow possible to include the output of an action in one JSP?
> 
> Now, when I try to include a *.do page, the server complains, it cannot
> forward to the action's jsp (of course, since I don't want to forward,
> I want to inlcude).
> 
> The only "solution" I've found, is to len the Action's perform method
> return null and include the action (*.do) as well as the jsp. (Which
> I really do not like, since then the including page plays the role of
> the controller)
> 
> Where should I start if I wanted to change the Action servlet, to include
> instead of forward?
> 
> (I include actions' output in my templates. Where one part is the content
> and another part is the in an action generated menu)
> 
> --
> gR
> 
> 

Included Actions

Posted by Gregor Rayman <gr...@gmx.net>.
Hi all,

is it somehow possible to include the output of an action in one JSP?

Now, when I try to include a *.do page, the server complains, it cannot
forward to the action's jsp (of course, since I don't want to forward,
I want to inlcude).

The only "solution" I've found, is to len the Action's perform method
return null and include the action (*.do) as well as the jsp. (Which
I really do not like, since then the including page plays the role of
the controller)

Where should I start if I wanted to change the Action servlet, to include
instead of forward?

(I include actions' output in my templates. Where one part is the content
and another part is the in an action generated menu)

--
gR



Re: AW: AW: action-mapping: why must the action-Attribute path be equivalent to the name of the jsp?

Posted by Ted Husted <hu...@apache.org>.
Peter.Spiessbach@bank-verlag.de wrote:
> Isn't it against the mvc philosophy to put navigation code (e.g. control)
> into a tag (e.g. view) ?

Generally, it's the view's job to capture user gestures, and the
controller's job to interpret them. Presentation code that says "next" 
or "prev" is a gesture. Code that says "next.jsp" or "prev.jsp" is 
interpreting a gesture.

So far this discussion has been about constructing a dynamic view that
presents the buttons needed to capture the user gestures: they want to
do this or they want to do that. A core problem is that a HTML
button's label and its value are the same, so we have to use hidden
fields, and other smoke-and-mirror techniques, to get buttons with the
same labels to represent different gestures. 

In real life, we still need to use logic to program the view. Otherwise,
we would have to a different page for every combination of application
state. One form for input. Another for update. Of course, this would
violate the MVC prime directive: optimize for long-term maintenance
(or "change is the only constant" ;0). 

The cutting edge is whether the view "knows" anything about other views.
When this happens, changes start to cascade between pages, and
maintenance is not optimal. 

So long as all links pass through ActionForwards (forward="") and
mappings (*.do or /do/*), then the flow is being determined by
controller 
layer, and could be reconfigured without changing the presentation code. 

Thus, the MVC gods are appeased ;-)

-Ted.

AW: AW: action-mapping: why must the action-Attribute path be equivalent to the name of the jsp?

Posted by Pe...@bank-verlag.de.
Isn't it against the mvc philosophy to put navigation code (e.g. control)
into
a tag (e.g. view) ?

-----Ursprungliche Nachricht-----
Von: Ted Husted [mailto:husted@apache.org]
Gesendet: Dienstag, 31. Juli 2001 18:42
An: struts-user@jakarta.apache.org
Betreff: Re: AW: action-mapping: why must the action-Attribute path be
equivalent to the name of the jsp?


The usual solution would be to design your forms to contain hidden
fields that tell the Action which operation to perform with the next
request. So typically, there would be one button with a hidden field
that conveyed whether this was the "FirstAction" or the "SecondAction".
These would all go back to a single Action that either performed all the
operations, or forwarded onto another Action.

If you will be using this button that much, you might also consider
writing your own custom tag so the button could program itself from the
request. In general, the request is meant to convey information to the
presentation layer about how it is suppose to write itself.

In my own projects, I am experimenting with ways to make the current
ActionMappings available to the JSP, as they are to perform() and
validate(), which starts to open several doors.


Peter.Spiessbach@bank-verlag.de wrote:
>
> Thanks, at least it's a working work-around. But the ugly thing is, that
in
> both cases the same action is called and I am forced to call the "real"
> action
> from the first action depending on the pushed button.
>
> + Action inserts "fire" bean into rquest context
> + Forward to JSP
> + JSP checks to see if fire==first. If so, write TheFirstAction button
> + JSP checks to see if fire==second. If so, write TheSecondActon button
> + submit "fires" action
> + action does nothing and forwards to the "real" action depending on the
> button.
>
> In my real world the page will be reused at least 5 or six times. So
rather
> than
> putting the "Control" part of MVC in the struts-config.xml I start
> piggypacking info
> in the request and analysing this in the dummy action.
>
> However again thanks.
> Peter


Re: AW: action-mapping: why must the action-Attribute path be equivalent to the name of the jsp?

Posted by Ted Husted <hu...@apache.org>.
The usual solution would be to design your forms to contain hidden
fields that tell the Action which operation to perform with the next
request. So typically, there would be one button with a hidden field
that conveyed whether this was the "FirstAction" or the "SecondAction".
These would all go back to a single Action that either performed all the
operations, or forwarded onto another Action. 

If you will be using this button that much, you might also consider
writing your own custom tag so the button could program itself from the
request. In general, the request is meant to convey information to the
presentation layer about how it is suppose to write itself.

In my own projects, I am experimenting with ways to make the current
ActionMappings available to the JSP, as they are to perform() and
validate(), which starts to open several doors. 


Peter.Spiessbach@bank-verlag.de wrote:
> 
> Thanks, at least it's a working work-around. But the ugly thing is, that in
> both cases the same action is called and I am forced to call the "real"
> action
> from the first action depending on the pushed button.
> 
> + Action inserts "fire" bean into rquest context
> + Forward to JSP
> + JSP checks to see if fire==first. If so, write TheFirstAction button
> + JSP checks to see if fire==second. If so, write TheSecondActon button
> + submit "fires" action
> + action does nothing and forwards to the "real" action depending on the
> button.
> 
> In my real world the page will be reused at least 5 or six times. So rather
> than
> putting the "Control" part of MVC in the struts-config.xml I start
> piggypacking info
> in the request and analysing this in the dummy action.
> 
> However again thanks.
> Peter

AW: action-mapping: why must the action-Attribute path be equivalent to the name of the jsp?

Posted by Pe...@bank-verlag.de.
Thanks, at least it's a working work-around. But the ugly thing is, that in
both cases the same action is called and I am forced to call the "real"
action
from the first action depending on the pushed button.

+ Action inserts "fire" bean into rquest context
+ Forward to JSP
+ JSP checks to see if fire==first. If so, write TheFirstAction button
+ JSP checks to see if fire==second. If so, write TheSecondActon button
+ submit "fires" action
+ action does nothing and forwards to the "real" action depending on the
button.

In my real world the page will be reused at least 5 or six times. So rather
than
putting the "Control" part of MVC in the struts-config.xml I start
piggypacking info
in the request and analysing this in the dummy action.

However again thanks.
Peter


-----Ursprungliche Nachricht-----
Von: Ted Husted [mailto:husted@apache.org]
Gesendet: Dienstag, 31. Juli 2001 15:49
An: struts-user@jakarta.apache.org
Betreff: Re: action-mapping: why must the action-Attribute path be
equivalent to the name of the jsp?


At this time, the current ActionMapping is not exposed to the JSP, so it
really can't tell which ActionMapping was used to call it. (Though, it
would be cool they could;-)

You might want to route control first through an Action, and then to the
JSP. This way you can put something in the request context to help write
the control. Right now, the simplest thing would be to put two copies of
the button in your JSP, enclosed within logic:equal tags. The tags could
then check to see if they should write the button for TheFirstAction or
TheSecondAction.

+ Action inserts "fire" bean into rquest context
+ Forward to JSP
+ JSP checks to see if fire==first. If so, write TheFirstAction button
+ JSP checks to see if fire==second. If so, write TheSecondActon button

-Ted.


Peter.Spiessbach@bank-verlag.de wrote:
>
> Hello,
> does anyone have an idea, how to use the same physical jsp page in
different
> action mappings (with different actions).
> I do not see a way to describe that my action path should be a locigal
path
> using a page, which does not fit to
> the pathname of the page.
>
> Example:
>         JSP is page1.jsp with one button
>         if I call this page as /page1 it should fire TheFirstAction,
>         if I call this page as /page2 it should fire TheSecondAction
>         But which parameter in the action mapping gives me a possibilty to
declare
> that page1.jsp
>         should be found as page1.jsp AND as page2.jsp?
>
> <action-mappings>
>         <action path="/page1"
>                 type="TheFirstAction"
>                 name="Page1Form"
>                 NOTKNOWNATTRIBUTE="page1.jsp"
>                 <forward name="success" path="/page3.jsp"/>
>         </action>
>
>         <action path="/page2"
>                 type="TheSecondAction"
>                 name="Page1Form"
>                 NOTKNOWNATTRIBUTE="page1.jsp"
>                 <forward name="success" path="/page4.jsp"/>
>         </action>
> <action-mappings>
>
> The problem is: why must the action-Attribute path be equivalent to the
name
> of the jsp?
>
> If anyone has understood what I am looking for, I would be very happy and
> thankful for help....
>
> Peter