You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by ge...@convergys.com on 2003/07/02 11:38:39 UTC

Re: view objects

Hi Adam,

Thanks for your reply.. but I think perhaps the point may be missed...
probably by me, but here goes...

Suppose you have on your jsp a drop down menu... a list of options, perhaps
a list of colors.  This list is generated from a database query.

What I do not want to do:

I do not want to make a database query directly from the jsp.  The reason
is that the jsp may partially display (non-buffered) and THEN I run into an
error.  I cannot recover gracefully at that point to redirect to an error
page.

Also what I do not want to do:

I do not want to make a database query INDIRECTLY from the jsp.  E.g., I do
not want to provide some sort of service object to the jsp and let IT do
the query.. mainly because it doesn't solve the problem any better.  I
still will end up with an error part way down the view.

What I DO want to do:

I want to pass to the jsp a databean that contains all the information PRE
LOADED for the jsp to query.  I want to know, in advance, which jsp is
going to be displayed next, create this databean (really a dto in this
case), load it up with the necessary information (in this case the list of
colors), stick the dto into the request and THEN fire the jsp.  The jsp
would then reference this databean for all necessary information and I'm
assured that I'm not going to run into any network problems while running
the jsp.

If I run into network problems, I run into them while constructing the dto
for the jsp.  I can then handle the error gracefully by forwarding to a
nice error page.

Now, you've mentioned the ActionForm bean as the key to the answer.  I
wasn't sure that was correct because I wasn't sure the form bean was
created until AFTER the form was submitted to the server by the browser.
I.e, your 'flow example' here talks about feeding the action form to the
action.. but that's too late.  The JSP has rendered we're actually doing a
SUBMIT from the form that the jsp generated.

In other words, the Action gets the ActionForm of the PREVIOUS jsp.. not
the one that is about to be rendered.  If this previous jsp happens to be
redisplayed (due to some error condition) we ok, I suppose.  But that's not
generally the case...

>Hi George,
>perhaps you should take a look at the flow-of-control diagrams or UML
>graphics that can be found on the struts website.
>
>Basically the form bean is created if you configure one, when the struts
>action servlet is given the request. It calls the reset() method and
>then the validate() method and if that's OK, calls your Action and
>passes it the form. It's in the Action that you can get all your
>resources and put them in the form (or the request attributes
>collection) so that your JSP doesn't crash. If you can't get any of your
>resources, you don't go to the JSP at all or you make sure you clean up
>first.
>
>Adam
>
>george.baxter@convergys.com wrote:
>> Hey all,
>>
>> Forgive a newbie his questions!
>>
>> I'm trying to understand a bit of struts and I'm having one key problem.
>>
>> When a with a form jsp runs, there may be dynamic data there that is not
>> related to user input directly.  Examples might include the 'step
number'
>> in a wizard or perhaps some values for a drop down menu for the user to
>> choose from.
>>
>>>From experience, it's important to have a data transfer object type of
>> class to provide to the jsp with the necessary data enclosed.  The key
here
>> is that you don't want the jsp hitting any back end pieces that might
>> require a network or db hit while the jsp is displaying.  Otherwise, you
>> may get a peculiar error (network down?  database crash?) when the jsp
is
>> half way done rendering.  Since the output of the jsp can be streamed
out,
>> you may get a partial HTML page and then some wacky attempt at a clean
>> error page.  It doesn't look nice.
>>
>> So I've been trying to figure out how Struts might handle this concept.
>> The closest I've come to an answer is the ActionForm, but.. it has
>> problems:
>>
>> 1) Are ActionForms only supplied (in the request) to the jsp after the
>> first request (i.e., only if the validation routines found an error).
>> 2) How can I 'prepare' my ActionForm with data the jsp requires (such as
>> the page number or the values for a drop down menu)?
>>
>> Thanks!
>>
>> George Baxter
>>
>> e-mail George.Baxter@convergys.com
>> www.convergys.com

--
"NOTICE:  The information contained in this electronic mail transmission is
intended by Convergys Corporation for the use of the named individual or
entity to which it is directed and may contain information that is
privileged or otherwise confidential.  If you have received this electronic
mail transmission in error, please delete it from your system without
copying or forwarding it, and notify the sender of the error by reply email
or by telephone (collect), so that the sender's address records can be
corrected."



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


RE: view objects

Posted by Andrew Hill <an...@gridnode.com>.
Its recomended that you also pass through an Action before going to a JSP -
this being a setup action as opposed to the one you hit after submitting
from that JSP (though they are often different executes in the same dispatch
action).

Load your stuff into beans there and save it as a request attribute before
forwarding to the view.



-----Original Message-----
From: george.baxter@convergys.com [mailto:george.baxter@convergys.com]
Sent: Wednesday, 2 July 2003 17:39
To: struts-user@jakarta.apache.org
Subject: Re: view objects


Hi Adam,

Thanks for your reply.. but I think perhaps the point may be missed...
probably by me, but here goes...

Suppose you have on your jsp a drop down menu... a list of options, perhaps
a list of colors.  This list is generated from a database query.

What I do not want to do:

I do not want to make a database query directly from the jsp.  The reason
is that the jsp may partially display (non-buffered) and THEN I run into an
error.  I cannot recover gracefully at that point to redirect to an error
page.

Also what I do not want to do:

I do not want to make a database query INDIRECTLY from the jsp.  E.g., I do
not want to provide some sort of service object to the jsp and let IT do
the query.. mainly because it doesn't solve the problem any better.  I
still will end up with an error part way down the view.

What I DO want to do:

I want to pass to the jsp a databean that contains all the information PRE
LOADED for the jsp to query.  I want to know, in advance, which jsp is
going to be displayed next, create this databean (really a dto in this
case), load it up with the necessary information (in this case the list of
colors), stick the dto into the request and THEN fire the jsp.  The jsp
would then reference this databean for all necessary information and I'm
assured that I'm not going to run into any network problems while running
the jsp.

If I run into network problems, I run into them while constructing the dto
for the jsp.  I can then handle the error gracefully by forwarding to a
nice error page.

Now, you've mentioned the ActionForm bean as the key to the answer.  I
wasn't sure that was correct because I wasn't sure the form bean was
created until AFTER the form was submitted to the server by the browser.
I.e, your 'flow example' here talks about feeding the action form to the
action.. but that's too late.  The JSP has rendered we're actually doing a
SUBMIT from the form that the jsp generated.

In other words, the Action gets the ActionForm of the PREVIOUS jsp.. not
the one that is about to be rendered.  If this previous jsp happens to be
redisplayed (due to some error condition) we ok, I suppose.  But that's not
generally the case...

>Hi George,
>perhaps you should take a look at the flow-of-control diagrams or UML
>graphics that can be found on the struts website.
>
>Basically the form bean is created if you configure one, when the struts
>action servlet is given the request. It calls the reset() method and
>then the validate() method and if that's OK, calls your Action and
>passes it the form. It's in the Action that you can get all your
>resources and put them in the form (or the request attributes
>collection) so that your JSP doesn't crash. If you can't get any of your
>resources, you don't go to the JSP at all or you make sure you clean up
>first.
>
>Adam
>
>george.baxter@convergys.com wrote:
>> Hey all,
>>
>> Forgive a newbie his questions!
>>
>> I'm trying to understand a bit of struts and I'm having one key problem.
>>
>> When a with a form jsp runs, there may be dynamic data there that is not
>> related to user input directly.  Examples might include the 'step
number'
>> in a wizard or perhaps some values for a drop down menu for the user to
>> choose from.
>>
>>>From experience, it's important to have a data transfer object type of
>> class to provide to the jsp with the necessary data enclosed.  The key
here
>> is that you don't want the jsp hitting any back end pieces that might
>> require a network or db hit while the jsp is displaying.  Otherwise, you
>> may get a peculiar error (network down?  database crash?) when the jsp
is
>> half way done rendering.  Since the output of the jsp can be streamed
out,
>> you may get a partial HTML page and then some wacky attempt at a clean
>> error page.  It doesn't look nice.
>>
>> So I've been trying to figure out how Struts might handle this concept.
>> The closest I've come to an answer is the ActionForm, but.. it has
>> problems:
>>
>> 1) Are ActionForms only supplied (in the request) to the jsp after the
>> first request (i.e., only if the validation routines found an error).
>> 2) How can I 'prepare' my ActionForm with data the jsp requires (such as
>> the page number or the values for a drop down menu)?
>>
>> Thanks!
>>
>> George Baxter
>>
>> e-mail George.Baxter@convergys.com
>> www.convergys.com

--
"NOTICE:  The information contained in this electronic mail transmission is
intended by Convergys Corporation for the use of the named individual or
entity to which it is directed and may contain information that is
privileged or otherwise confidential.  If you have received this electronic
mail transmission in error, please delete it from your system without
copying or forwarding it, and notify the sender of the error by reply email
or by telephone (collect), so that the sender's address records can be
corrected."



---------------------------------------------------------------------
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