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?
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.
Practice only makes habit, only perfect practice makes perfect.—every music teacher ever
Practice mindfully by doing the right things and doing things right.— Junilu
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.
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"/>