Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

default value in select tag - - optionsCollection

 
AnilPrakash Raju
Ranch Hand
Posts: 137
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I was wondering how to make a value in a <select> in dafault when i enter in a jsp page.

eg.<html:select property="periodEnd">
<html ptionsCollection name="statSearch" property="misReportPeriodVec" value="periodEnd" label="periodEnd"/>
</html:select>

How can i make a particular value of periodEnd to be default?

thanks

Anil
 
Roel De Nijs
Sheriff
Posts: 9145
75
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this:

in your formbean you have a data-member periodEnd where the value will be put in that is selected in the combobox when user submit form.

private [datatype] periodEnd = value_from_optionCollection; (use the value not the label)

and then it should work.
Good luck!
 
AnilPrakash Raju
Ranch Hand
Posts: 137
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Roel,

Thanks for you suggestion, but i was more interested when the user came to the jsp, i want the a certain value of periodEnd to be selected(or defaulted) and then the user can select other values.

Thanks.

Anil
 
Shankar Narayana
Ranch Hand
Posts: 134
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Anil,

You have a property in the ActionForm corressponding to the dropdown name, before coming to the jsp , you set this property value to whatever has to be selected.
 
AnilPrakash Raju
Ranch Hand
Posts: 137
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Shankar,
I tried it but it does not seem to work.

Do you think i need to change the order of the values of the vector so that the default value is at the top of the list?

Thanks

Anil
 
Shankar Narayana
Ranch Hand
Posts: 134
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
work out this problem with the answer I gave to your other post.
 
Junilu Lacar
Bartender
Pie
Posts: 6529
21
Java Linux Mac Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by AnilPrakash Raju:
I tried it but it does not seem to work.


Post the code that you tried and think should work. The suggested solutions by the two posters above are correct.
 
AnilPrakash Raju
Ranch Hand
Posts: 137
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

in the action just before going to the jsp, i set the field in the actionForm.

code:

statSearchForm.setPeriodEndingString(statSearch.getPeriodEndingString());

the bean statSearch also contains a vector having the values of the <select> tag.


in the jsp :
<html:select property="periodEndingString">
<html ptions name="statSearch" property="periodEndVec"/>
</html:select>

thanks
Anil
 
Roel De Nijs
Sheriff
Posts: 9145
75
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess that you make the change to statSearchForm, but that another instance is created when the jsp-page is called.

change into your struts-config.xml the action that corresponds with your statSearchForm the attribute scope (default: request) into session. so you've got something like this:



another possibility is initialising your periodEndingString into your StatSearchForm, something like this


So in each instance made of this form your data member periodEndingString will be initialized with "blahblahblah"
[ August 09, 2004: Message edited by: Roel De Nijs ]
 
Junilu Lacar
Bartender
Pie
Posts: 6529
21
Java Linux Mac Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by AnilPrakash Raju:

statSearchForm.setPeriodEndingString(statSearch.getPeriodEndingString());


Check these:

1. Is statSearch.getPeriodEndingString() returning a valid option value?

2. Are the options successfully populated in the response?
 
AnilPrakash Raju
Ranch Hand
Posts: 137
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

To your ques1- statSearch.getPeriodEndingString() is returning a valid option value.

And to your ques2- The options are successfully populated in the response.

I am able to maintain the selected option once it is selected.

I am no longer using optionsCollection, just options(that should not make a difference i think ??)

Anil
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic