Re: How can I construct STRUTS select options tag according to aparameter ?

2003-08-30 Thread Ted Husted
The simplest thing would be to have the Action create a LabelValue bean 
collection from state and cities, and pass that collection instead.

http://jakarta.apache.org/struts/api/org/apache/struts/util/LabelValueBean.html

A good practice is to use Actions to front any page that uses dynamic 
data. So, instead of linking to examnple_1.jsp, you would always link to 
a example_1.do (or equivalent) that ensured whatever data you need exists.

The idea is that the Action does whatever is necessary to make the 
dynamic data easy to display. For a select control, the easiest format 
for the data is a collection of LabelValue beans, so that's the one the 
Action should prepare.

For something like States, you could also store the collection in 
application scope at start up, using a plug-in, so that the Action would 
not need to create it. See the MailReader sample application, bundled 
with Struts, for a working example of using a plugin to create a 
LabelValue collection.

-Ted.

Fumitada Hattori wrote:
Hi there.

How can I construct STRUTS select options tag according to a parameter ?

I got a jsp named "example_1.jsp".
One accesses the page with a parameter like example_1.jsp?id=2 .
Now what I wanna do is that the example_1.jsp get the value of id
parameter and construct select options tag dynamically.
Like below...
String id = request.getParameter("id");
USBean us = (USBean)request.getServletContext().getAttribute("USBean");
StateBean state = us.getState(id);
ArrayList cities = state.getCities();
All Beans above are set in the application scope when tomcat starts.

I dont' know how to make us.getState(id) with STRUTS select options tag,
since USBean's getState( ) method requires a id parameter.
What I'm doing now is 
Using 1 more page ( actionExample.do ) right before 
the example_1.jsp.

One accesses the actionExample.do with the id parameter like 
actionExample.do?id=2 and forward to example_1.jsp

In the actionExample.do, get a value of the id parameter and 
StateBean accroding to the value.
Set the StateBean in session scope like below.

String id = request.getParameter("id");
USBean us = (USBean)request.getServletContext().getAttribute("USBean");
StateBean state = us.getState(id);
request.getSession(true).setAttribute("state",state);
then in example_1.jsp



I don't wanna do this anymore...since eveytime users accesses the
actionExample.do , state bean is set in the session scope...
Isn't this too much work ???
Thanks in advance.





-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

--
Ted Husted,
  Junit in Action  - <http://www.manning.com/massol/>,
  Struts in Action - <http://husted.com/struts/book.html>,
  JSP Site Design  - <http://www.amazon.com/exec/obidos/ISBN=1861005512>.
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


How can I construct STRUTS select options tag according to a parameter ?

2003-08-30 Thread Fumitada Hattori
Hi there.

How can I construct STRUTS select options tag according to a parameter ?

I got a jsp named "example_1.jsp".
One accesses the page with a parameter like example_1.jsp?id=2 .
Now what I wanna do is that the example_1.jsp get the value of id
parameter and construct select options tag dynamically.

Like below...
String id = request.getParameter("id");
USBean us = (USBean)request.getServletContext().getAttribute("USBean");
StateBean state = us.getState(id);
ArrayList cities = state.getCities();

All Beans above are set in the application scope when tomcat starts.

I dont' know how to make us.getState(id) with STRUTS select options tag,
since USBean's getState( ) method requires a id parameter.

What I'm doing now is 
Using 1 more page ( actionExample.do ) right before 
the example_1.jsp.

One accesses the actionExample.do with the id parameter like 
actionExample.do?id=2 and forward to example_1.jsp

In the actionExample.do, get a value of the id parameter and 
StateBean accroding to the value.
Set the StateBean in session scope like below.

String id = request.getParameter("id");
USBean us = (USBean)request.getServletContext().getAttribute("USBean");
StateBean state = us.getState(id);
request.getSession(true).setAttribute("state",state);

then in example_1.jsp




I don't wanna do this anymore...since eveytime users accesses the
actionExample.do , state bean is set in the session scope...
Isn't this too much work ???

Thanks in advance.





-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Select/Options Tag

2001-02-23 Thread Chalmers, Douglas

Thanks for that. Got it passing a string array now. Managed to pass all
options by calling a script function to select them all before posting.


"Chalmers, Douglas" wrote:

> A tag reference can maintain a String from a SELECT statement within a
> form bean, but only the ONE actually selected..
>
> How can I maintain ALL the OPTIONS within a SELECT box within a form
> bean??
>

This bug was just fixed, so you will need the most current nightly
release.  You can now have a property that returns a String array, and
use
it to back a SELECT statement that allows multiple options:


... Use  and/or  here ...


and Struts will correctly remember all of the selected values, based on
the contents of your array.

There is a test page (html-select.jsp) in the Struts test application
(struts-test.war) that illustrates how this works.


>
> Doug Chalmers
> Software Development
> Petrotechnics Ltd
> Exploration House
> Exploration Drive
> Aberdeen
> 707303 (Ext 14)

Craig





Re: Select/Options Tag

2001-02-22 Thread Craig R. McClanahan

"Chalmers, Douglas" wrote:

> A tag reference can maintain a String from a SELECT statement within a
> form bean, but only the ONE actually selected..
>
> How can I maintain ALL the OPTIONS within a SELECT box within a form
> bean??
>

This bug was just fixed, so you will need the most current nightly
release.  You can now have a property that returns a String array, and use
it to back a SELECT statement that allows multiple options:


... Use  and/or  here ...


and Struts will correctly remember all of the selected values, based on
the contents of your array.

There is a test page (html-select.jsp) in the Struts test application
(struts-test.war) that illustrates how this works.


>
> Doug Chalmers
> Software Development
> Petrotechnics Ltd
> Exploration House
> Exploration Drive
> Aberdeen
> 707303 (Ext 14)

Craig





Select/Options Tag

2001-02-22 Thread Chalmers, Douglas

A tag reference can maintain a String from a SELECT statement within a
form bean, but only the ONE actually selected..

How can I maintain ALL the OPTIONS within a SELECT box within a form
bean??

Doug Chalmers
Software Development
Petrotechnics Ltd
Exploration House
Exploration Drive
Aberdeen
707303 (Ext 14)