【问题标题】:Using <c:out> tag to set var in jsp by using the <c:set> tag使用 <c:out> 标签在 jsp 中使用 <c:set> 标签设置 var
【发布时间】:2013-04-19 20:01:51
【问题描述】:

在我的 Struts 1 应用程序的 jsp 中,我尝试使用 c:set 标记从显示表的列表中设置变量。

表中的每一行都有一个值(100 或 200),用于区分哪个用户添加了该条目。我只想为某个用户(100)显示编辑/删除。

我正在尝试设置该值并将其与 100 进行比较以确定哪些行应该进行编辑/删除。

我遇到的问题是 rowUser 没有从我的列表中获得值。

我知道列表有值,因为表格正在显示,但它们显示的所有行好像不等于 100。

到目前为止我所拥有的是:

<c:set var="rUser"><c:out value="${myList.rowUser}" /></c:set>
<c:choose>
<c:when test="${rUser == 100}">
<display:column  property="startDate" title="Start Date" width="18%" decorator="com.mhngs.util.DisplayTagDateWrapper" sortable="true" headerClass="sortable"/>
<display:column  property="endDate" title="End Date" width="18%" decorator="com.mhngs.util.DisplayTagDateWrapper" sortable="true" headerClass="sortable" />
<display:column  property="reason" title="Comments" width="17%" sortable="true" headerClass="sortable" />
<display:column media="html" width="17%"><a href="#" onClick="javascript:editEntry('<c:out value="${myList.Id}"/>')">Edit</a></display:column>  
<display:column media="html" width="15%"><a href="#" onClick="javascript:deleteEntry('<c:out value="${myList.Id}"/>')">Delete</a></display:column>
</c:when>

<c:otherwise>
<display:column  property="startDate" title="Start Date" width="18%" decorator="com.mhngs.util.DisplayTagDateWrapper" sortable="true" headerClass="sortable"/>
<display:column  property="endDate" title="End Date" width="18%" decorator="com.mhngs.util.DisplayTagDateWrapper" sortable="true" headerClass="sortable" />
<display:column property="reason" title="Comments" sortable="true"/>
</c:otherwise>
</c:choose>

任何帮助将不胜感激。

【问题讨论】:

    标签: html jsp struts displaytag


    【解决方案1】:

    如果您想将myList.rowUser 分配给属性rUser,只需使用

    <c:set var="rUser" value="${myList.rowUser}"/>
    

    也就是说,为什么要为此使用附加属性,而不是直接使用myList.rowUser

    <c:when test="${myList.rowUser == 100}">
    

    最后,问题在于显示标签在第一次迭代时计算要显示的列。在接下来的迭代中,它只是更改每列中显示的值。当属性为 200 时,不应显示最后两列,而应显示它们但将它们留空。简而言之,测试应该在 display:column 标签内,而不是在外:

    <display:column ...> if row = 100, display button </display:column>
    

    【讨论】:

    • 感谢您帮助我,但我试过了,但我遇到了同样的问题,所以我尝试使用 c:out 设置变量
    • 我在答案完成之前发布了,对不起。请阅读我编辑的答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多