File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Problem with a select tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Problem with a select tag" Watch "Problem with a select tag" New topic
Author

Problem with a select tag

Mattia Merenda
Ranch Hand

Joined: Dec 14, 2006
Posts: 47
Hi everybody,
I have to use in a JSP page a form with 2 select tags.
The select tags should get their values from 2 different queries.These queries ask the same table of database but 2 different fields.The first query should work like:
"SELECT DISTINCT(field1) FROM table)".
The second query should work like:
"SELECT DISTINCT(field2) FROM table".
How can I make this?Should I use 2 different struts Action?Does anybody know some example?
Of course,I already wrote the getter and setter methods in the Action Form class.I also need to know if I have to write something special in struts-config.xml file.
I need some example before Tuesday if it is possible.
Thanks in advance,
Mattia
Rusty Smythe
Ranch Hand

Joined: Aug 09, 2006
Posts: 93
Easy:

a) Call model, method #1 from controller - store result in variable #1
b) Call model, method #2 from controller - store result in variable #2
c) Call form setter for field #1, set this to value of variable #1
d) Call form setter for field #2, set this to value of variable #2
e) Forward to JSP
f) Done.

Bonus points: instead of a) and b), call ONE method to get both results; put these results into a DTO, then pass the DTO back to the controller where you extract the values.
Rusty Smythe
Ranch Hand

Joined: Aug 09, 2006
Posts: 93
Ahh, I misunderstood you before.

To set up the select boxes in your view, check out
"How to use HTML OPTIONS."

You can use two methods or have one method return two arraylists (via a DTO).
[ December 15, 2006: Message edited by: Rusty Smythe ]
Mattia Merenda
Ranch Hand

Joined: Dec 14, 2006
Posts: 47
Hi Rusty,
I read your link page and thanks for it,
but if I have only one field to use in my query how can I put 2 String values in the LabelValueBean object?
Answer me soon.
Thanks,Mattia
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
In a case where the label of the options and its value are the same, don't use the LabelValue bean at all. Just send back a collection of Strings and use that in your <htmlptions> tag. For example:

Create a property myOptions in your ActionForm that is a collection of Strings. Then in your jsp:

<htmlptions name="myActionForm" property="myOptions" />
[ December 17, 2006: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
 
wood burning stoves
 
subject: Problem with a select tag