• 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

html:options - having difficulty preselecting item

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a registration form. If a user makes a mistake he or she gets sent back to the registration page by RegisterForm.java.
Struts is automatically filling in the free text fields so that the user doesn't have to fill in the whole form again, but is not preselecting the drop down fields. I'm not sure why this is happening. My jsp code is:
<%
DropDownFactory factory = DropDownFactory.getInstance();
request.setAttribute("personTitle", factory.getDropDownBean("Title"));
%>
<html:select property="title">
<html ptions name="personTitle" property="idList" labelName="personTitle" labelProperty="categoriesList"/>
</html:select>
The personTitle DropDownBean has a method called getIdList(), which as the name suggests returns a List with the Strings "1","2","3" etc. that match the Title table in my database.
Does Struts have the capability to select these choices again, or am I going to have to use something other than the <html:select> and <html ptions> tags?
 
Sheriff
Posts: 17644
300
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
"Xmas Pudding Tree"
As much as we are all eager to get into the holiday spirit, we really need you to change your publicly displayed name to comply with the JavaRanch Naming Policy.
Thanks for your cooperation.
 
Junilu Lacar
Sheriff
Posts: 17644
300
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
The associated ActionForm needs to have a title property and corresponding getters and setters. If the value of the title property matches any of the option values, it will automatically be selected. If your IDE allows you to debug JSPs, step through the JSP and make sure that the form's title property is not null or blank or has a value that is not listed in the options.
 
Ray Beaumont
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for that - name duly changed...
Just to clarify what you said, it seems that my problems are because of my naming:
<option value="-1">Please select</option>
<option value="1">Mr</option>
<option value="2">Mrs</option>
<option value="3">Mr & Mrs</option>
<option value="4">Miss</option>
<option value="5">Ms</option>
and I need to change it to:
<option value="Please select">Please select</option>
<option value="Mr">Mr</option>
<option value="Mrs">Mrs</option>
<option value="Mr & Mrs">Mr & Mrs</option>
<option value="Miss">Miss</option>
<option value="Ms">Ms</option>
I think that these forums are wonderful. Previously I could have spent days experimenting working out a problem like this.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm still having difficulties getting struts to select the appropriate option. My log goes something like this:
New RegisterForm created.
title is set to: Mr
setTitle will now call getTitle()
title is got as: Mr
firstname is set to: hello
RegisterForm.validate()
email has errors
password has errors
firstname is got as: hello
title is got as: null
A new Form is created, all the values are set using the setXXX methods.
However when it comes to displaying register.jsp again, the title field has been set to null, while all the other (text) fields remain as they are. This happens for all my <select> fields. It looks like the struts framework may be using reflection to set these fields to null. (Just my guess).
Can anybody explain this strange behaviour and put me on the right track?
My jsp fields are:
<html:text name="RegisterForm" property="firstName" maxlength="50" size="26"/>

and:

<%
houserent.domain.DropDownFactory factory = houserent.domain.DropDownFactory.getInstance();
request.setAttribute("personTitle", factory.getDropDown("Title"));
%>
<html:select property="title">
<html ptions name="personTitle" property="categoriesList" labelName="personTitle" labelProperty="categoriesList"/>
</html:select>
 
Ray Beaumont
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(sorry about name - it seems to have reverted itself, I have updated it again.)
 
Ray Beaumont
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorted - instead of
<html:select name="RegisterForm" property="title">
I used
<html:select property="title">
which presumably accessed a different instance of the form bean.
reply
    Bookmark Topic Watch Topic
  • New Topic