• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

default value in select tag - - optionsCollection

 
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 11606
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
work out this problem with the answer I gave to your other post.
 
Sheriff
Posts: 17734
302
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 11606
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 17734
302
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic