• 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

persist a value in drop down menu

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all,
is there any solution to persist a value in the drop down menu only by using strtus tags.
please do reply.
thanks in advance.
navdeep
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not entirely sure what you mean by "persist". If you mean persist to a java class, the answer is yes, there is a solution. By simply using the <html:select> and <html:options> tags, Struts automatically persists the values entered into the ActionForm bean when the form is submitted.

If you mean persist to a database, the answer is no, there is no solution using tags only. Struts is an MVC framwork, and putting logic to access a database in a JSP breaks the MVC model. The Struts way to persist data to a database is to include that logic in the "model" portion of your application and then have your Action class send messages to your model classes to persist data.
[ November 19, 2006: Message edited by: Merrill Higginson ]
 
Navdeep Singh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Merrill for replying ..
persist in my case means, when we select a value from a drop down box the selected value must remain selected in drop down box after submitting the form.
 
Merrill Higginson
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 that case, just use the Struts tags. If the page is submitted and then refreshed, the value will remain.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As said you can use struts tags to get persisted.

if in case you are using normal html tags you can use javascript also to achieve this.

<html>
<body>
<form name="form1">
<select name=persistMenu onchange="call1()">
<option value="vijayawada">Vijayawada
<option value="governorpet">Governorpet
</select>

</form>
</body>
</html>

<script language="javascript">
var selectedIndex=0;

function call1() {
selectedIndex=document.forms[0].persistMenu.selectedIndex;
document.forms[0].persistMenu.selectedIndex=selectedIndex;
}


</script>

you can use that onchane event in appropriate place.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic