You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Rob Parker <rp...@bstonetech.com> on 2001/12/07 04:45:07 UTC

Problem using toScope parameter

I am having trouble with the <bean:define> tag, specifically the toScope
parameter.

Here is the situation:

I set up some collections in an action class to use as <select> options in a
form and set them as attributes on the request object. These collections
contain information pulled from a database, customized for different sets of
users. Everything works perfectly unless there is a problem with validation
in the associated user form. In that case, the collection "beans" go out of
scope and and the jsp call results in an exception saying that the
collection bean cannot be found in the request scope. Here is some example
code to hopefully make everything a bit clearer.

In the action class:

...
Collection industrySectorList =
optionGenerator.getIndustrySectorList(connection, userID);
request.setAttribute("industrySectortList", industrySectorList);
...

In the jsp:
...
<bean:define id="industrySectorList" name="industrySectorList"
scope="request" toScope="request" type="java.util.Collection"/>
...
<html:select value="applicantForm" property="industrySectorID" >
	<html:options collection="industrySectorList" property="value"
labelProperty="label"/>
</html:select>
...

If I understand correctly, when user form validation fails, the associated
action is bypassed and the request is forwarded back to the originating jsp
page. How can I make sure that the collection beans necessary to display
option lists stay in scope so that I don't get an exception? Why doesn't the
toScope parameter in the <bean:define> tag work in this case? Thanks,

Rob

By the way, the exact exception that I get is:
javax.servlet.jsp.JspException: Cannot find bean industrySectorList in scope
request


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Problem using toScope parameter

Posted by Keith Bacon <ke...@yahoo.com>.
I hope I have this right! 
What that <bean:define says is:-
Get the bean industrySectortList(name=) from the
request(scope=) & add it to the request(toScope=) as
industrySectortList(id=).

You don't need that whole <bean:define.

The <html:select looks for your bean in the request by
default (as you haven't mentioned scope in the
html:select)

You have to remember to re-add your bean to the
request after validation that fails - so the
re-display of the original form has access to it.
I hope this makes sense & helps.
Keith.

--- Rob Parker <rp...@bstonetech.com> wrote:
> I am having trouble with the <bean:define> tag,
> specifically the toScope
> parameter.
> 
> Here is the situation:
> 
> I set up some collections in an action class to use
> as <select> options in a
> form and set them as attributes on the request
> object. These collections
> contain information pulled from a database,
> customized for different sets of
> users. Everything works perfectly unless there is a
> problem with validation
> in the associated user form. In that case, the
> collection "beans" go out of
> scope and and the jsp call results in an exception
> saying that the
> collection bean cannot be found in the request
> scope. Here is some example
> code to hopefully make everything a bit clearer.
> 
> In the action class:
> 
> ...
> Collection industrySectorList =
> optionGenerator.getIndustrySectorList(connection,
> userID);
> request.setAttribute("industrySectortList",
> industrySectorList);
> ...
> 
> In the jsp:
> ...
> <bean:define id="industrySectorList"
> name="industrySectorList"
> scope="request" toScope="request"
> type="java.util.Collection"/>
> ...
> <html:select value="applicantForm"
> property="industrySectorID" >
> 	<html:options collection="industrySectorList"
> property="value"
> labelProperty="label"/>
> </html:select>
> ...
> 
> If I understand correctly, when user form validation
> fails, the associated
> action is bypassed and the request is forwarded back
> to the originating jsp
> page. How can I make sure that the collection beans
> necessary to display
> option lists stay in scope so that I don't get an
> exception? Why doesn't the
> toScope parameter in the <bean:define> tag work in
> this case? Thanks,
> 
> Rob
> 
> By the way, the exact exception that I get is:
> javax.servlet.jsp.JspException: Cannot find bean
> industrySectorList in scope
> request
> 
> 
> --
> To unsubscribe, e-mail:  
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 


__________________________________________________
Do You Yahoo!?
Send your FREE holiday greetings online!
http://greetings.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>