Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

struts problem

Options
  • 13-05-2004 4:21pm
    #1
    Moderators, Category Moderators, Technology & Internet Moderators Posts: 6,265 CMod ✭✭✭✭


    hi all,
    i've got a question from a friend - any thoughts apprecieated.

    I have an Struts ActionForm called, say, "MyForm". My jsp page contains the following code:

    <!
    MyPage.jsp
    >
    ....
    <bean:define id="myForm" name="myForm" type="MyForm"/>
    <%
    //This Collection contains "Status" objects that implement "KeyValuePair" interface
    Collection statusList = myForm.getStatusList();
    long currentStatus = myForm.getCurrentStatus();
    pageContext.setAttribute( "statusList", statusList );
    %>

    <html:select property="statusId" styleClass="dropDown" value="???????">
    <html:options collection="statusList" property="statusId" labelProperty="status"/>
    </html:select>
    ....
    <!
    End MyPage.jsp
    >

    I want the select list to display whatever the current status is as the default value, using the "selected" attribute of the option tag. I know that you can set this with a literal string value, using the value="" attribute of the <html:select> tag (see above).
    This isn't any use to me though, as I must read the status from the database using the myForm.getCurrentStatus() method and assign it dynamically.

    Do you any way to do this?


Comments

  • Registered Users Posts: 27 Harry Lime


    From what I remeber I think that is works like this...

    <html:select property="status">
    <html: options property="statuses"/>
    </html:select>

    where your ActionForm has a method getStatus() which returns the current status, and a method getStatuses() which returns an array of possible values.

    Sorry that I can't be more precise, but I think that's it.


Advertisement