使用 JSP 的动态输入字段

发布于 2024-12-20 12:24:48 字数 389 浏览 1 评论 0原文

我正在使用 jsp 和 struts 实现一个简单的门户,用户在表单中填写一些参数,然后我呈现一个表格,表格中的每个元素都是只读的,除了一个,这是一个输入字段,用户可以完全填充。该表是动态的,我永远不知道它会有多少行。那么使用 JSP 和 struts 如何处理动态数量的输入字段?

例如,表单有一个下拉列表,我使用 struts taglib 中的 html:select 标签实现,并且在 ActionForm 中我有一个数组,每个请求中都会由 struts 框架填充。如果包含下拉列表中可能值的数组名称是“dropdown”,则 POST 将类似于 "dropdown='value1'&dropdown='value2'" ,但我无法实现此解决方案适用于动态输入字段。我需要帮助。

I am implementing a simple portal using jsp and struts, the user full fill some parameters in a form and i present a table , every elements in the table are readOnly except one , that is a input field that the user could full fill.The table is dynamic and i never know how many rows it would have. So using JSP and struts how can i deal with a dynamic number of input fields ?

For example ,the form have one drop-down list that i implement using the html:select tag from struts taglib and in the ActionForm i have an Array that will be fullfill by the struts framework in every request. If the Array name that contains the possible values from the dropdown is "dropdown" the POST will be something like this "dropdown='value1'&dropdown='value2'" , but i can not implement this solution to the dynamic input fields. I need help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

待"谢繁草 2024-12-27 12:24:48

如果您的操作表单中有一个名为“dropDown”的 setter

public void setDropDown(String[] selectedValues)

,那么 Struts 将使用一个数组来调用它,该数组包含所有名为“dropDown”的选择框中的所有选定值。

如果您的操作表单中有一个名为“dropDown[i]”的设置器

public void setDropDown(int index, String value)

,那么 Struts 将为每个名为“dropDown[i]”的选择框调用一次它,其中 i 是标识每一行的整数(每行一个索引)。

如果您的操作表单中有一个名为“dropDown(key)”的设置器

public void setDropDown(String key, String value)

,那么 Struts 将为每个名为“dropDown(key)”的选择框调用一次它,其中 key 是标识每一行的键(每行一个键)。

请参阅 http://struts.apache.org/1.x/struts- taglib/indexedprops.html 了解更多详细信息

If you have a setter in your action form named

public void setDropDown(String[] selectedValues)

then Struts will call it with an array containing all the selected values in all the select boxes named "dropDown".

If you have a setter in your action form named

public void setDropDown(int index, String value)

then Struts will call it once for each select box named "dropDown[i]" where i is an integer identifying each of the rows (one index per row).

If you have a setter in your action form named

public void setDropDown(String key, String value)

then Struts will call it once for each select box named "dropDown(key)" where key is the a key identifying each of your rows (one key per row).

See http://struts.apache.org/1.x/struts-taglib/indexedprops.html for more details

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文