使用 JSP 的动态输入字段
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的操作表单中有一个名为“dropDown”的 setter
,那么 Struts 将使用一个数组来调用它,该数组包含所有名为“dropDown”的选择框中的所有选定值。
如果您的操作表单中有一个名为“dropDown[i]”的设置器
,那么 Struts 将为每个名为“dropDown[i]”的选择框调用一次它,其中 i 是标识每一行的整数(每行一个索引)。
如果您的操作表单中有一个名为“dropDown(key)”的设置器
,那么 Struts 将为每个名为“dropDown(key)”的选择框调用一次它,其中 key 是标识每一行的键(每行一个键)。
请参阅 http://struts.apache.org/1.x/struts- taglib/indexedprops.html 了解更多详细信息
If you have a setter in your action form named
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
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
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