• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with a select tag

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 93
Mac Objective C Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 93
Mac Objective C Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 <html:options> tag. For example:

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

<html:options name="myActionForm" property="myOptions" />
[ December 17, 2006: Message edited by: Merrill Higginson ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic