struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eddie Bush <ekb...@swbell.net>
Subject Re: How-- html::form whose action is whatever action caused its display?
Date Mon, 25 Feb 2002 19:47:35 GMT
I believe the typical solution to this is an attribute set in either request
or session scope.  Your login action could then check to see if the
attribute exists, and forward to it if it does (and remove it, if it is in
the session).

Of course, your action knows it's own mapping, so it would set the attribute
before redirecting to login.

You'll probably need a hidden field in your login form if you choose to use
a request attribute - so you can keep the path across requests.

Of course, there is likely a better way - if someone knows one please chip
in =)

Hope that helps,

Eddie
----- Original Message -----
From: "Jeff" <jeff@tiaxa.net>
To: <struts-user@jakarta.apache.org>
Sent: Monday, February 25, 2002 1:30 PM
Subject: How-- html::form whose action is whatever action caused its
display?


> What's the best/proper way to create a HTML:form whose "action" property
is
> set to whatever action caused the jsp template containing it to be
displayed
> in the first place?
>
> For example, suppose a form submission to /admin_action.do triggers an
> action class (say, "AdminAction") which determines that the user needs to
> log in before doing whatever it was that his original form submission was
> supposed to achieve. As luck would have it, the form bean just submitted
was
> a subclass of the login form bean (in fact, ALL of the application's form
> beans are subclasses of the login form bean so they'll be capable of doing
> double-duty as a login form bean while preserving the state of the
remaining
> formvars during a login sidetrip should the need arise). Anyway, the
action
> class returns mapping.findForward("login"), which is mapped to
> /templates/login.jsp. No sweat.
>
> Here's where things get sticky. The action class above ("AdminAction") is
> not the only one that might plausibly return mapping.findForward("login").
> Actually, every single action class (including "AdminAction" above) is a
> subclass of the abstract LoggedInUserAction class, which verifies that the
> user is logged in (and/or tries to log them in, if a username and password
> happens to have been submitted) before calling its own
> performLoggedInAction() abstract class, and returns
> mapping.findForward("login") if the user needs to log in.
>
> In other words, form submissions to /admin_item.do, /admin_preview.do,
> /admin_something_else.do, and numerous other URLs map to Action classes
that
> are subclasses of LoggedInUserAction, any of which might plausibly result
in
> the return of mapping.findForward("login") if LoggedInUserAction realizes
> that the user hasn't logged in.
>
> The challenge is making sure that when login.jsp gets displayed because
> /admin_preview.do fell through to login.jsp, the submitted login form gets
> sent to /admin_preview.do. If login.jsp gets displayed because
> /admin_item.do fell through to login.jsp, the submitted login form should
> get sent to /admin_item.do. I know I -could- create a separate login form
> for every possible action, but I'm pretty sure that there's GOT to be a
> better way to do it. Like maybe a scripting variable whose value is
whatever
> URL resulted in the display of the current page?
>
> Suggestions?
>
>
>
> sample struts.xml excerpt:
>
> <form-beans type="org.apache.struts.action.ActionFormBean">
> <!-- all three form beans are subclasses of LoginFormBean -->
>  <form-bean name="createForm" type="pkg.CreateFormBean">
>  <form-bean name="previewForm" type="pkg.PreviewFormBean">
>  <form-bean name="updateForm" type="pkg.UpdateFormBean">
> </form-beans>
>
> <global-forwards type="org.apache.struts.action.ActionForward>
>  <forward name="peon" path="/not_allowed.jsp">
>  <!-- when the "login" mapping is called, it needs to use whatever
bean -->
>  <!-- was associated with the original action in the action-mappings
> below -->
>  <forward name="login" path="/login.jsp">
> </global-forwards>
>
> <action-mappings type="org.apache.struts.action.ActionMapping">
>  <action path="/create" type="pkg.CreateAction" name="createForm">
>   <forward name="create" path="/create.jsp">
>  </action>
>  <action path="/preview" type="pkg.PreviewAction" name="previewForm">
>   <forward name="preview" path="/preview.jsp">
>  </action>
>  <action path="/update" type="pkg.UpdateAction" name="updateForm">
>   <forward name="update" path="/update.jsp">
>  </action>
> </action/mappings>
>
> sample login.jsp excerpt:
>
> <html:form action="/create.do">
> <!-- assuming this jsp was displayed as a result of a form submission
> to /create.do. If the form submission resulting in this page's display
> were to /update.do, the action needs to be "/update.do", and so on.
> Perhaps something like... -->
> <%--
> <html:form
> action="<%=URL_from_which_the_display_of_this_page_was_launched%>">
> --%>
> </html:form>
>
>
>
> --
> To unsubscribe, e-mail:
<mailto:struts-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
<mailto:struts-user-help@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>


Mime
View raw message