【问题标题】:struts generating form elements from beanstruts 从 bean 生成表单元素
【发布时间】:2013-05-14 12:43:06
【问题描述】:

我在 JSP 页面中有一个 Struts 1.2 Bean 和一个 Bean 代码,如下所示

checkBox.jsp

<logic:iterate property="userList" id="userDet" name="userDetails">
  <html:checkbox property="checked" name="userDet" indexed="true">
   <bean:write property="userName" name="userDet"></bean:write>
  </html:checkbox>
</logic:iterate>

上面的代码输出如下

现在,当我提交表单时,我想使用复选框的 ID 执行 Javascript 验证。

如何为 JSP 页面中通过 Bean 生成的复选框生成 id?是否可以动态生成 id 属性?

【问题讨论】:

  • 通过将属性放到标签中。
  • 最佳解决方案取决于您希望如何实际验证。如果您只想确保至少选中一个复选框,我会使用一个类。这还取决于您是否使用 jQuery/etc 等 JS 库。

标签: java jsp struts struts-1


【解决方案1】:

尝试使用“indexId”属性(页面范围 JSP bean 的名称,它将包含每次迭代时集合的当前索引。 ) 的

<logic:iterate>

并在

的 'styleId' 属性中使用它
<html:checkbox>

像这样:

<logic:iterate property="userList" id="userDet" name="userDetails" indexId="checkBoxIndex">
  <html:checkbox property="checked" name="userDet" indexed="true" styleId="checkBox<%= checkBoxIndex %>">
   <bean:write property="userName" name="userDet"></bean:write>
  </html:checkbox>
</logic:iterate>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-15
    • 1970-01-01
    • 1970-01-01
    • 2015-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多