在 JSP 中设置 DynaActionForm / DynaValidatorForm 的值
我想在 DynaForm 上设置一个值,这在 Action 类中很容易做到,但我想在 JSP 本身中这样做,通过将会话中的值复制到表单中。
<form-bean name="inputCIDs" type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="containerIDFormat" type="java.lang.String"/>
</form-bean>
以下 Java 代码可以在 JSP 中运行,但是是否有 Struts 1.x 或 JSTL 标记可以执行等效操作?
<%
DynaActionForm form = (DynaActionForm) request.getAttribute("inputCIDs");
form.set("containerIDFormat", session.getAttribute("varInSession"));
%>
用户将使用选择框
<html:select property="containerIDFormat">
<html:options collection="containerIDFormats" property="value" labelProperty="description"/>
</html:select>
环境来使用和更改该属性:
Struts 1.2.4
标签库 1.1.2
JBoss 4.0.2
I would like to set a value on a DynaForm, which is easy to do in the Action class, but I would like to do so in the JSP itself, by copying a value from the session into the form.
<form-bean name="inputCIDs" type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="containerIDFormat" type="java.lang.String"/>
</form-bean>
The following Java code works in the JSP, but is there a Struts 1.x or JSTL tag that would do the equivalent action?
<%
DynaActionForm form = (DynaActionForm) request.getAttribute("inputCIDs");
form.set("containerIDFormat", session.getAttribute("varInSession"));
%>
The property will be used and changed by the user using a select box
<html:select property="containerIDFormat">
<html:options collection="containerIDFormats" property="value" labelProperty="description"/>
</html:select>
Environment:
Struts 1.2.4
taglibs 1.1.2
JBoss 4.0.2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么? JSP 不适合进行此类工作。
如果您只是设置表单值,它无论如何都不会在提交后继续存在,因为将创建一个新的请求范围表单。如果它是会话范围的表单,则更没有理由在 JSP 中完成这项工作。
Why? The JSP isn't the appropriate place for this type of work.
If you just set the form value it won't survive the submission anyway, because a new request-scoped form will be created. And if it's a session-scoped form there's even less reason to do this work in JSP.