• 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

JSP + struts html:select

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI,

I am using struts 1.2 in my web application. I have to display one <html:select>.... <html:options> list

list will be build dynamically. User can select any option. base on the user's selection page will be refreshed (need to hit the database and display information in other fields on same page.) I need to know two things:

1) there is one submit button on that page and one action is associated with that submit button. i can call the associated action class once the user finish the form and click the submit button. When user select from list i need to call another action class.

I want to know how to call another action class, (when user select something from list), as list control is inside the same html:form tag.

2) When user selects some value from list i need to refresh the page and populate the other fields.

I would like to know, Lets say there are ten values and user has selected third option, how to keep selected that third option as page is already refreshed?

I am beginner in struts.. any sample code would be a great help for me

Thank you for time and help.

Ajay
 
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To your first problem: you can associate N number of actions with a given JSP as long as you know how to handle the data in the corresponding Action classes. In your case, I would associate a JS function with the "onchange" event of the <select> element. Therein, I will simply overwrite the form's action using something like:

As for your second problem: you can always send back the value selected through a request attribute or form bean variable from the server and have it saved in a hidden textbox. At the end of the <form> section, write a small script like:


That should solve your problem to a good extent, I believe.
[ March 17, 2008: Message edited by: Anirvan Majumdar ]
 
Ranch Hand
Posts: 341
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

1) there is one submit button on that page and one action is associated with that submit button. i can call the associated action class once the user finish the form and click the submit button. When user select from list i need to call another action class.




For you particular case you'll require to do a lot of JavaScript-ing.
Basically, you'll require to have some variable which will be set to true if it is list-action and false if it is normal submit. Now, on the click of submit button you'll require to check for that variable and appropriately set your action.



But, this is not a good way and not robust and may crash in some situations. I suggest to use one action class to handle multiple action requests.

What I mean is that an action class is capable of responding to multiple action events. In the execute method you can handle multiple action requests with the help of if-else, switch or some condition block.

2) When user selects some value from list i need to refresh the page and populate the other fields.

I would like to know, Lets say there are ten values and user has selected third option, how to keep selected that third option as page is already refreshed?



For this when you are re-rendering the response, you'll require to set the property pertaining to the select box to the one that was originally selected.

e.g when you try to get what property was selected you say something like

So, while re-rendering you'll need to say-


This will work perfectly fine. But, I suggest you use AJAX for this for better user interface.

Good Luck..!!
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"ajay tickle", please check your private messages for an important administrative matter.
 
Opportunity is missed by most people because it is dressed in overalls and looks like work - Edison. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic