Struts问题——s:hidden
我的 JSP 中有以下代码。我正在使用 Struts 表单,在其中传递要迭代的列表,并且列表中的每个项目都有其自己单独的表单。列表中的所有字段都是字符串,除了 id 之外,它是一个 int。我试图在 as:hidden 标记中呈现 int,但 Eclipse 告诉我“属性(值)无效”。 Struts 文档说该值采用字符串,但我将Bulletins.id 包装在${...} 内,这应该将其转换为字符串。我已经进行了多次谷歌搜索来尝试解决这个问题,但我一无所获。有人见过这个吗?
<%@ page import="java.io.*"%>
<%@ page import="java.util.List"%>
<%@ page language="java" import="model.Bulletin"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!-- Some more code here that's not relevant to this problem -->
<c:forEach var="bulletins" items="${bulletins}">
<c:if test="${bulletins.approved == false}">
<s:form action="ApproveBulletin" method="post">
<table>
<tr>
<td colspan="2"><b>From:</b> <c:out value="${bulletins.name}" /></td>
</tr>
<tr>
<td colspan="2"><b>Subject:</b> <c:out value="${bulletins.subject}" /></td>
</tr>
<tr>
<td colspan="2"><b>Date:</b> <c:out value="${bulletins.date}" /> <br>
</td>
</tr>
<tr>
<td colspan="2"><c:out value="${bulletins.note}" />
<!-- Error here --> <s:hidden name="id" value="${bulletins.id}" /></td>
</tr>
<tr>
<td><s:submit type="button" value="approve" label="Approve"
action="ApproveBuletin" /></td>
<td><s:submit type="button" value="deny" label="Deny"
action="DenyBulletin" /></td>
</tr>
</table>
<br />
</s:form>
</c:if>
</c:forEach>
<!-- Some more code here that's not relevant to this problem -->
I have the following code in my JSP. I'm using a Struts form where I'm passing in a List that I'm iterating over, and each item in the List has its own separate form. All fields in the list are Strings except for id, which is an int. I'm trying to render the int in a s:hidden tag, but Eclipse is telling me, "Invalid attribute (value)." The Struts documentation says that value takes a String, but I'm wrapping bulletins.id inside ${...}, which should convert it into a String. I've done multiple Google searches to try to resolve this issue, but I've come up with nothing. Has anyone seen this before?
<%@ page import="java.io.*"%>
<%@ page import="java.util.List"%>
<%@ page language="java" import="model.Bulletin"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!-- Some more code here that's not relevant to this problem -->
<c:forEach var="bulletins" items="${bulletins}">
<c:if test="${bulletins.approved == false}">
<s:form action="ApproveBulletin" method="post">
<table>
<tr>
<td colspan="2"><b>From:</b> <c:out value="${bulletins.name}" /></td>
</tr>
<tr>
<td colspan="2"><b>Subject:</b> <c:out value="${bulletins.subject}" /></td>
</tr>
<tr>
<td colspan="2"><b>Date:</b> <c:out value="${bulletins.date}" /> <br>
</td>
</tr>
<tr>
<td colspan="2"><c:out value="${bulletins.note}" />
<!-- Error here --> <s:hidden name="id" value="${bulletins.id}" /></td>
</tr>
<tr>
<td><s:submit type="button" value="approve" label="Approve"
action="ApproveBuletin" /></td>
<td><s:submit type="button" value="deny" label="Deny"
action="DenyBulletin" /></td>
</tr>
</table>
<br />
</s:form>
</c:if>
</c:forEach>
<!-- Some more code here that's not relevant to this problem -->
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Struts2 标签更喜欢 OGNL,因此将 ${} 替换为 %{} 甚至更好,只需写“
这是个人偏好”,但我会只使用 S2 标签来编写该页面,如下所示:
几乎没有什么区别。请注意,迭代器堆栈将当前正在迭代的对象推送到堆栈上,因此您不需要迭代器元素内的点符号(对于更深层嵌套的对象,您将...)。
Struts2 tags prefer OGNL so replace ${} with %{} or even better just write
This is personal preference but I'd write that page with only S2 tags as such:
There is very little difference. Note that the iterator stack pushes the current object being iterated onto the stack so you don't need dot notation inside the iterator element (well for more deeply nested objects you would...).
我对 Struts2 部分不太了解,但以下内容肯定是错误的:
您正在用当前迭代的项目覆盖列表。用普通的 Java 术语来说,你基本上是在做:
这没有意义,也不会编译(重复的局部变量或类似的东西)。
给它一个不同且独特的名称。
bulletin
是最有意义的。循环内只有一个公告,对吗?然后将循环内的任何
${bulletins.property}
替换为${bulletin.property}
。I have no utter idea about the Struts2 part, but the following is definitely wrong:
You're overwriting the list with the currently iterated item. In normal Java terms, you're basically doing:
This makes no sense and also wouldn't compile (duplicate local variable or something like that).
Give it a different and unique name.
bulletin
would make the most sense. There's means of only one bulletin inside the loop, right?and then replace any
${bulletins.property}
inside the loop by${bulletin.property}
.