开发者

Struts Table fields

I would just like to ask how to pass values from JSP to Action in struts,

I have a table with data cells with the same property names, i.e., the table rows have the same property. does struts automatically pass them as ArrayList to the Action class?

My table has 3 columns:

userListFullName
userListUserName
softwareProduct -> values from multiple selection in combo box

This table can have maximum rows of 15 (there are buttons to add/delete rows)

Code snippet:

<tr class="dataRow" align="center">
<td class="dataCell" align="center">
    <html:text styleId="newSoftwareApplicationList" property="userListFullName"/>
</td>
<td class="dataCell" align="center">
    <html:text styleId="newSoftwareApplicationList" property="userListUserName"/>
</td>
<td class="dataCell" align="center">
    <select id="newSoftwareApplicationList" class="dropdown round_sb" style="width:90%" name="softwareProduct" multiple="true">
        <option value="1">Microsoft Access</option>
        <option value="2">Microsoft Visio Standard</option>
        <option value="3">Microsoft Visio Proffesional</option>
        <option value="4">Microsoft Project Standard</option>
     </select>
</td&开发者_如何学Gogt;


Yes, Struts does automatically pass them to the Action class. But you must understand that <html:text> will not be able to handle multiple values. You must use <html:select> for that, for example. A regular <select> will not be able to do that, I am afraid. Struts will not be responsible of anything done outside, I mean in regular HTML tags. As the other poster suggested, you must group all your struts-html-controls in a <html:form> tag.


You should have form tag, which should contain that table. If you submit that form, struts will send that property values to the action, which is specified in the action field of the form tag.

Also your action should have public setter methods for your properties, otherwise you can't get values. For example, if you have property which name is userListUserName, you should have method like this:

public void setUserListUserName(String userListUserName) {
    ...
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜