- This topic has 4 replies, 3 voices, and was last updated 19 years, 10 months ago by Haggi.
-
AuthorPosts
-
dsarrisMemberHi,
I am trying to use the <html:select> tag with the <html:optionscollection> tag. The documentation states that the optionscollection tag retrieves ithe collection from the bean that is specified using the name property.
My question is the following:Do I have to put the collection property inside the form bean of the form that contains the <html:select>?
For example:
myAction.do has the form bean myActionFormBean.
<html:form action="/myAction.do"> <table> <tr> <td>Name</td> <td><html:text property="name" /></td> </tr> <tr> <td>Surname</td> <td><html:text property="surname" /></td> </tr> <tr> <td>Marital Status</td> <td> <html:select property="maritalStatusId"> <html:optionsCollection name="myCustomBeanNotTheSameAsTheForm" property="maritalStatus" label="name" value="id"/> </html:select> </td> </tr> </html:form>
Is it going to work if the “myCustomBeanNotTheSameAsTheForm” is saved in the session?
GregMemberOur resident struts guru is on vacation this week. Please, any struts developers out there, feel free to jump in.
According to the struts documentation, as long as the name=”” attributes points to a collection of beans, where each bean has a label property and a value property you should be ok. I don’t think it has to be the same bean name as the form bean. Give it a shot and see.
dsarrisMemberI tried but with no success. I put the “myCustomBeanNotTheSameAsTheForm” is saved in the session but I had no success. Using the same form bean it had no problem.
HaggiMember@dsarris wrote:
Hi,
Do I have to put the collection property inside the form bean of the form that contains the <html:select>?
No, that is not required. If you save your collection property in the request (request.setAttribute(..)) you can access the collection with the attribute property of the <html:optionscollection> tag (without the name attribute). If another scope holds your collection you have to specified this scope with the name attribute.
HaggiMembersorry a little mistake, use the name attribute of the <html:optionscollection> tag if you want to access a collection holds by the request. If you want to access a collection in your form bean you only use the property attribute.
-
AuthorPosts