Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

persist a value in drop down menu

 
Navdeep Singh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • 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 <htmlptions> 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
  • 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
  • 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.
 
prasanth jalasutram
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic