facebook

Struts usage question

  1. MyEclipse IDE
  2.  > 
  3. Java EE Development (EJB, JSP, Struts, XDoclet, etc.)
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #221967 Reply

    dsarris
    Member

    Hi,

    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?

    #221975 Reply

    Greg
    Member

    Our 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.

    #221987 Reply

    dsarris
    Member

    I 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.

    #225408 Reply

    Haggi
    Member

    @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.

    #225409 Reply

    Haggi
    Member

    sorry 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.

Viewing 5 posts - 1 through 5 (of 5 total)
Reply To: Struts usage question

You must be logged in to post in the forum log in