You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Andy Engle <st...@andyengle.com> on 2004/03/04 23:44:15 UTC

Returning fully-stocked Actions/JSPs from other Actions

Hi all,

I'm working on a web app where I have my JSPs hidden beneath WEB-INF.
In doing so, I of course have actions which RequestDispatch those pages
to the user.  In doing this I am running into a problem where beans in
those returned JSPs are not getting updated when they are returned from
other actions.  For example, on my login screen lets say I have a bean
"junkbean" that hold some data, which is loaded in LoginAction.  That
bean has data in it when I call /login.do directly. When I complete a
form on that screen and submit it to /update.do, I would like to return
the user to the /login.do screen.  But when I do that, "junkbean" is
nowhere to be found, as if the action behind /login.do is not doing
anything.  But, if I call /login.do directly, then "junkbean" is there
with all it's data.

How can I get my action behind /index.do (or any similar action that
gets data, then RequestDispatches a JSP back to the user) to execute so
that I can have my updated beans present?  If this is not the ideal way
to do it, what would be a better design for doing this sort of thing?
Essentially I want to hide all my JSPs behind WEB-INF, but I would
still like to have them updated after I submit forms and return action
paths, which load those JSPs.

Thanks so much for your help, and I look forward to receiving your
advice.


Andy


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


Re: Returning fully-stocked Actions/JSPs from other Actions

Posted by Andy Engle <st...@andyengle.com>.
Michael McGrady wrote:

> I am having a hard time seeing what you want to do, but I know that
> your issues with the "junkbean" are unrelated to the "hiding" of the
> JSPs behind/beneath/be-whatever WEB-INF.  If you want to access data,
> including an object, then the data must be saved somewhere and then
> accessed where it is saved during the time it is saved.  That is the
> simple truth that is required for this situation.

Sure -- that's the only way it will work.  I'll try to put everything
in order here, as I am doing it:

1. IndexAction (mapped to /home.do) puts data into the bean:

        List users = service.viewAllPeople(birForm);
        request.setAttribute("junkbean", users);

    ...and then returns index.jsp:

        <forward name="continue" path="/WEB-INF/pages/index.jsp"/>

2. Within this index.jsp is a form, which is submitted to LoginAction.

3. When I submit the form to LoginAction and LoginAction is finished,
then I want to return the /home.do mapping, or display the index.jsp
screen again:

        <action
            path="/login"
            type="com.andyengle.actions.LogonAction"
            name="logonForm"
            scope="request"
            input="/WEB-INF/pages/index.jsp">
          <forward name="continue" path="/home.do"/>
        </action>

4. When I do this, I get the following error:

    Cannot find bean junkbean in any scope


> If you go to access it and it is not there, then you must be
> accessing in session scope and saving in request scope or something
> like that.

Ok, in IndexAction, I did put it in request scope, but that should work
because I only want it for this request, not necessarily for the entire
session.  But in this case, does IndexAction even have access to the
request scope, or does LoginAction only have access to that (i.e.
IndexAction can't put junkbean in request scope)?


> You need to ask: (1) did I save "junk bean"?

Yes.


> (2) If not, do so.  If so, then is the scope of the respository
> adequate for your purposes.

It seems that request scope should be adaquate in this case, since I
only need it for the current request.


> (3) Etc. Okay dokay?

Okay dokay -- thanks!  Let me know if that is a decent-enough
clarification of my earlier question.


Andy


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


Re: Returning fully-stocked Actions/JSPs from other Actions

Posted by Michael McGrady <mi...@michaelmcgrady.com>.
I am having a hard time seeing what you want to do, but I know that your 
issues with the "junkbean" are unrelated to the "hiding" of the JSPs 
behind/beneath/be-whatever WEB-INF.  If you want to access data, including 
an object, then the data must be saved somewhere and then accessed where it 
is saved during the time it is saved.  That is the simple truth that is 
required for this situation.  If you go to access it and it is not there, 
then you must be accessing in session scope and saving in request scope or 
something like that.  You need to ask: (1) did I save "junk bean"?  (2) if 
not, do so.  If so, then is the scope of the respository adequate for your 
purposes.  (3) Etc. Okay dokay?

Michael

At 02:44 PM 3/4/2004, you wrote:
>Hi all,
>
>I'm working on a web app where I have my JSPs hidden beneath WEB-INF.
>In doing so, I of course have actions which RequestDispatch those pages
>to the user.  In doing this I am running into a problem where beans in
>those returned JSPs are not getting updated when they are returned from
>other actions.  For example, on my login screen lets say I have a bean
>"junkbean" that hold some data, which is loaded in LoginAction.  That
>bean has data in it when I call /login.do directly. When I complete a
>form on that screen and submit it to /update.do, I would like to return
>the user to the /login.do screen.  But when I do that, "junkbean" is
>nowhere to be found, as if the action behind /login.do is not doing
>anything.  But, if I call /login.do directly, then "junkbean" is there
>with all it's data.
>
>How can I get my action behind /index.do (or any similar action that
>gets data, then RequestDispatches a JSP back to the user) to execute so
>that I can have my updated beans present?  If this is not the ideal way
>to do it, what would be a better design for doing this sort of thing?
>Essentially I want to hide all my JSPs behind WEB-INF, but I would
>still like to have them updated after I submit forms and return action
>paths, which load those JSPs.
>
>Thanks so much for your help, and I look forward to receiving your
>advice.
>
>
>Andy
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org



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


Re: Returning fully-stocked Actions/JSPs from other Actions

Posted by Michael McGrady <mi...@michaelmcgrady.com>.
If you save it in request scope, then it will be gone afterward.  That is 
your problem.

At 03:22 PM 3/4/2004, you wrote:
>Michael McGrady wrote:
>
> > There are no beans in returned JSPs.  In fact, there are no returned
> > JSPs.  I assume you mean to talk about the response object.  That
> > includes only HTML in your case, I am betting.
>
>Yes -- that's what I meant.
>
>
> > The client requests /login.do.  What it means to say that "bean has
> > data in it" when a client requests "/login.do" is unclear to me.
>
>Ok, when the client requests /login.do, then junkbean gets data, which
>the JSP has access to when "returned" (or displayed) to the user.
>Hence, the JSP is able to display the data present in the bean.
>
>
> > You can return the user to any "screen" you like.  That is merely to
> > say that you can choose the response object's content.
>
>Right, but when doing so, I would like the response object to be able
>to have access to the bean that has my data.
>
>
> > >But when I do that, "junkbean" is nowhere to be found,
> >
> > I don't know what this means.  Either "junk bean" is saved or not.
> > If not, and you want it, save it, although I would not.
>
>No, this bean is only saved in the request object and nothing more.
>
>
>Andy
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org



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


Re: Returning fully-stocked Actions/JSPs from other Actions

Posted by Andy Engle <st...@andyengle.com>.
Michael McGrady wrote:

> There are no beans in returned JSPs.  In fact, there are no returned 
> JSPs.  I assume you mean to talk about the response object.  That
> includes only HTML in your case, I am betting.

Yes -- that's what I meant.


> The client requests /login.do.  What it means to say that "bean has
> data in it" when a client requests "/login.do" is unclear to me.

Ok, when the client requests /login.do, then junkbean gets data, which
the JSP has access to when "returned" (or displayed) to the user. 
Hence, the JSP is able to display the data present in the bean.


> You can return the user to any "screen" you like.  That is merely to
> say that you can choose the response object's content.

Right, but when doing so, I would like the response object to be able
to have access to the bean that has my data.


> >But when I do that, "junkbean" is nowhere to be found,
> 
> I don't know what this means.  Either "junk bean" is saved or not. 
> If not, and you want it, save it, although I would not.

No, this bean is only saved in the request object and nothing more.


Andy

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


Re: Returning fully-stocked Actions/JSPs from other Actions

Posted by Michael McGrady <mi...@michaelmcgrady.com>.
In addition to my previous nonsense, let me spout the following too:

At 02:44 PM 3/4/2004, you wrote:
>Hi all,
>
>I'm working on a web app where I have my JSPs hidden beneath WEB-INF.
>In doing so, I of course have actions which RequestDispatch those pages
>to the user.  In doing this I am running into a problem where beans in
>those returned JSPs

There are no beans in returned JSPs.  In fact, there are no returned 
JSPs.  I assume you mean to talk about the response object.  That includes 
only HTML in your case, I am betting.

>are not getting updated when they are returned from
>other actions.

Beans also are not returned from actions either, unless you are streaming 
objects, classes, etc., which is highly unlikely.

>For example, on my login screen lets say I have a bean
>"junkbean" that hold some data, which is loaded in LoginAction.

Loading a class in an action does not persist the class.

>That
>bean has data in it when I call /login.do directly.

The client requests /login.do.  What it means to say that "bean has data in 
it" when a client requests "/login.do" is unclear to me.

>When I complete a
>form on that screen and submit it to /update.do, I would like to return
>the user to the /login.do screen.

You can return the user to any "screen" you like.  That is merely to say 
that you can choose the response object's content.

>But when I do that, "junkbean" is
>nowhere to be found,

I don't know what this means.  Either "junk bean" is saved or not.  If not, 
and you want it, save it, although I would not.

>as if the action behind /login.do is not doing
>anything.  But, if I call /login.do directly, then "junkbean" is there
>with all it's data.
>
>How can I get my action behind /index.do (or any similar action that
>gets data, then RequestDispatches a JSP back to the user) to execute so
>that I can have my updated beans present?

Have your action persist whatever data you want persisted in whatever 
fashion you want it persisted, e.g. save to session or application or, 
better still, use a database.

>If this is not the ideal way
>to do it, what would be a better design for doing this sort of thing?

If you want to persist data, that is what you must do.

>Essentially I want to hide all my JSPs behind WEB-INF, but I would
>still like to have them updated after I submit forms and return action
>paths, which load those JSPs.

I am trying to see what you want.  You want there to be default or chosen 
values for the form fields when you return to the html?  Remember that JSPs 
are just GUI easy Servlets.  The JSPs are not real: they are PHANTOMs!


>Thanks so much for your help, and I look forward to receiving your
>advice.

Hope this helped.  If you just said what you wanted to do without the 
technical jargon, it would probably be easier to see what you are doing.



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



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