You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Kevin Duffey <kd...@buymedia.com> on 2000/06/21 07:12:16 UTC

Struts - latest build

Hi,

Sorry..posted this to the wrong subject in the group...trying again. If your
reading this twice..I apologize for the mixup.


I just downloaded the latest Struts. Damned if Craig implemented my
suggestion! The ActionForward class for a return type from perform(). The
only downside is..all my actions now have to be edited to return this type.
Other than that..pretty kewl.

So question to Craig...first, does each of my actions need to create a new
ActionForward object, and populate it, then return that to use the
forwarding capability that I assume is worked into ActionServlet (is it?).

A thought..return an Object type, instead of ActionForward. In
ActionServlet, use instanceof to see if it is of type String. If it
is..forward to that page. If not, check if it is of type ActionForward..and
if so..typecast it and use that object. The reason I ask for this is..its
often nice to just return a String of the page to forward to, instead of
having to create a new object then return that. While returning a string
creates a new object, its a bit less code for every action to just return
the String.

Ofcourse..I would much rather use a "mapping" in the action.xml file, which
I see you added as well..so that I can just have a lookup done based on the
action being called. But I am not quite sure how that works. Do I still need
to create an ActionForward object, populate only the "forward" name, and the
ActionServlet checks to see if the relative path is empty..if so, do a
lookup on the name from the action, or what?


A feature request:

  Ability to NOT use the international classes, via an init param. In other
words, conditionalize the use of a resource bundle, getMessage() calls, etc.
That way..if my app is strictly US bound, I don't have to worry about the
JDK 1.3 bug with ResourceBundle that apparently exists, so that I can run my
code under JDK 1.3. I found out that Orion works fine with Struts, except
when running Orion under JDK 1.3, because there is a bug in JDK 1.3
assocated with the getResourceBundle() call or something. Is this true?


Thanks.


Re: Struts - latest build

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
"Craig R. McClanahan" wrote:

> [snip]
> If you use the new capabilities of the action.xml method (the <forward>
> element), you can set up a set of logical mappings that you can just look up,
> instead of having to create one every time.  See the usage in the example
> application -- for example, LogonAction does this when it sees a successful user
> authentication:
>
>     return (mapping.findForward("success"));
>
> which returns the configured mapping for the logical name "forward" that was set
> up at initialization time.
>

Actually, that's the logical name "success" rather than the logical name "forward".

I didn't mention one other new feature in tonight's build -- you can declare global
<forward> declarations for the entire application as well as local <forward>
declarations relevant to a particular mapping.  This is useful for things like the
mapping to the logon page, which might be required from pretty much anywhere.  See
the example app for an example of this usage.

Craig



Re: Struts - latest build

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
"Craig R. McClanahan" wrote:

> [snip]
> If you use the new capabilities of the action.xml method (the <forward>
> element), you can set up a set of logical mappings that you can just look up,
> instead of having to create one every time.  See the usage in the example
> application -- for example, LogonAction does this when it sees a successful user
> authentication:
>
>     return (mapping.findForward("success"));
>
> which returns the configured mapping for the logical name "forward" that was set
> up at initialization time.
>

Actually, that's the logical name "success" rather than the logical name "forward".

I didn't mention one other new feature in tonight's build -- you can declare global
<forward> declarations for the entire application as well as local <forward>
declarations relevant to a particular mapping.  This is useful for things like the
mapping to the logon page, which might be required from pretty much anywhere.  See
the example app for an example of this usage.

Craig



Re: Struts - latest build

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Kevin Duffey wrote:

> Hi,
>
> Sorry..posted this to the wrong subject in the group...trying again. If your
> reading this twice..I apologize for the mixup.
>
> I just downloaded the latest Struts. Damned if Craig implemented my
> suggestion! The ActionForward class for a return type from perform(). The
> only downside is..all my actions now have to be edited to return this type.
> Other than that..pretty kewl.
>
> So question to Craig...first, does each of my actions need to create a new
> ActionForward object, and populate it, then return that to use the
> forwarding capability that I assume is worked into ActionServlet (is it?).
>

If you use the new capabilities of the action.xml method (the <forward>
element), you can set up a set of logical mappings that you can just look up,
instead of having to create one every time.  See the usage in the example
application -- for example, LogonAction does this when it sees a successful user
authentication:

    return (mapping.findForward("success"));

which returns the configured mapping for the logical name "forward" that was set
up at initialization time.

>
> A thought..return an Object type, instead of ActionForward. In
> ActionServlet, use instanceof to see if it is of type String. If it
> is..forward to that page. If not, check if it is of type ActionForward..and
> if so..typecast it and use that object. The reason I ask for this is..its
> often nice to just return a String of the page to forward to, instead of
> having to create a new object then return that. While returning a string
> creates a new object, its a bit less code for every action to just return
> the String.
>

The reason it returns ActionForward instead of String is -- at the suggestion of
someone else on the list -- sometimes you want to forward and sometimes you want
to redirect.  The ActionForward object lets you specify both the destination URL
and the redirect flag.

In ActionServlet, the current implementation looks like this:

    ActionForward forward =
        actionInstance.perform(this, mapping, formInstance,
            request, response);
    if (forward != null) {
        String path = forward.getPath();
        if (forward.getRedirect())
            response.sendRedirect(path);
        else {
            RequestDispatcher rd =
                getServletContext().getRequestDispatcher(path);
            rd.forward(request, response);
        }
    }

so if you want to redirect instead of forward, set your <forward> entry up like
this:

    <forward name="success" path="logon.jsp" redirect="true"/>

and that will happen for you (this also answers your second email question about
whether Struts can redirect instead of forward).

>
> Ofcourse..I would much rather use a "mapping" in the action.xml file, which
> I see you added as well..so that I can just have a lookup done based on the
> action being called. But I am not quite sure how that works. Do I still need
> to create an ActionForward object, populate only the "forward" name, and the
> ActionServlet checks to see if the relative path is empty..if so, do a
> lookup on the name from the action, or what?
>

See the example application, and the discussion above.

>
> A feature request:
>
>   Ability to NOT use the international classes, via an init param. In other
> words, conditionalize the use of a resource bundle, getMessage() calls, etc.
> That way..if my app is strictly US bound, I don't have to worry about the
> JDK 1.3 bug with ResourceBundle that apparently exists, so that I can run my
> code under JDK 1.3. I found out that Orion works fine with Struts, except
> when running Orion under JDK 1.3, because there is a bug in JDK 1.3
> assocated with the getResourceBundle() call or something. Is this true?
>

I will look at the implications of this.

>
> Thanks.

Craig



Re: Struts - latest build

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Kevin Duffey wrote:

> Hi,
>
> Sorry..posted this to the wrong subject in the group...trying again. If your
> reading this twice..I apologize for the mixup.
>
> I just downloaded the latest Struts. Damned if Craig implemented my
> suggestion! The ActionForward class for a return type from perform(). The
> only downside is..all my actions now have to be edited to return this type.
> Other than that..pretty kewl.
>
> So question to Craig...first, does each of my actions need to create a new
> ActionForward object, and populate it, then return that to use the
> forwarding capability that I assume is worked into ActionServlet (is it?).
>

If you use the new capabilities of the action.xml method (the <forward>
element), you can set up a set of logical mappings that you can just look up,
instead of having to create one every time.  See the usage in the example
application -- for example, LogonAction does this when it sees a successful user
authentication:

    return (mapping.findForward("success"));

which returns the configured mapping for the logical name "forward" that was set
up at initialization time.

>
> A thought..return an Object type, instead of ActionForward. In
> ActionServlet, use instanceof to see if it is of type String. If it
> is..forward to that page. If not, check if it is of type ActionForward..and
> if so..typecast it and use that object. The reason I ask for this is..its
> often nice to just return a String of the page to forward to, instead of
> having to create a new object then return that. While returning a string
> creates a new object, its a bit less code for every action to just return
> the String.
>

The reason it returns ActionForward instead of String is -- at the suggestion of
someone else on the list -- sometimes you want to forward and sometimes you want
to redirect.  The ActionForward object lets you specify both the destination URL
and the redirect flag.

In ActionServlet, the current implementation looks like this:

    ActionForward forward =
        actionInstance.perform(this, mapping, formInstance,
            request, response);
    if (forward != null) {
        String path = forward.getPath();
        if (forward.getRedirect())
            response.sendRedirect(path);
        else {
            RequestDispatcher rd =
                getServletContext().getRequestDispatcher(path);
            rd.forward(request, response);
        }
    }

so if you want to redirect instead of forward, set your <forward> entry up like
this:

    <forward name="success" path="logon.jsp" redirect="true"/>

and that will happen for you (this also answers your second email question about
whether Struts can redirect instead of forward).

>
> Ofcourse..I would much rather use a "mapping" in the action.xml file, which
> I see you added as well..so that I can just have a lookup done based on the
> action being called. But I am not quite sure how that works. Do I still need
> to create an ActionForward object, populate only the "forward" name, and the
> ActionServlet checks to see if the relative path is empty..if so, do a
> lookup on the name from the action, or what?
>

See the example application, and the discussion above.

>
> A feature request:
>
>   Ability to NOT use the international classes, via an init param. In other
> words, conditionalize the use of a resource bundle, getMessage() calls, etc.
> That way..if my app is strictly US bound, I don't have to worry about the
> JDK 1.3 bug with ResourceBundle that apparently exists, so that I can run my
> code under JDK 1.3. I found out that Orion works fine with Struts, except
> when running Orion under JDK 1.3, because there is a bug in JDK 1.3
> assocated with the getResourceBundle() call or something. Is this true?
>

I will look at the implications of this.

>
> Thanks.

Craig