gpt4 book ai didi

java - struts2,转换s :select list to display Tag column

转载 作者:搜寻专家 更新时间:2023-11-01 02:39:42 24 4
gpt4 key购买 nike

我在 jsp 中有以下选择列表:

<td>
<s:select list = "models"
listValue = "modelName"
listKey = "modelId"
multiple = "true"
name = "models" />
</td>

我选择使用 display Tag 库实现分页,所以我想在显示列中转换它并显示列表中的一个或多个模型。我怎样才能做到这一点?下面是我的显示表和其他列:

<display:table name = "cars" 
requestURI = "/listCar.action"
pagesize = "10">

<display:column property = "name" title = "name" />

<display:column titleKey = "models" >
<!--------------model list?-------------->
</display:column>

<display:column property = "year" title = "year" />

</display:table>

最佳答案

首先,您需要让 DisplayTag 在您可以访问的上下文中推送值:

Implicit objects created by table


If you add and id attribute the table tag makes the object corresponding to the given row available in the page context so you could use it inside scriptlet code or some other tag. Another implicit object exposed by the table tag is the row number, named id_rowNum .

These objects are saved as attributes in the page scope (you can access it using pageContext.getAttribute("id") ). They are also defined as nested variables (accessible using <%=id%> ), but only if the value of the id atribute is not a runtime expression. The preferred way for fetching the value is to always use pageContext.getAttribute().

If you do not specify the id attribute no object is added to the pageContext by the table tag


然后您需要访问该上下文。在 Struts2 中,pageContext可通过 #attr 获得:

Struts 2 Named Objects:


#attr['foo'] or #attr.foo

Access to PageContext if available, otherwise searches request/session/application respectively


所以代码是:

<display:table   id = "currentRowInPageContext"
name = "cars"
requestURI = "/listCar.action"
pagesize = "10">

<display:column property = "name" title = "name" />

<display:column titleKey = "models" >
<s:select list = "%{#attr.currentRowInPageContext.models}"
listValue = "modelName"
listKey = "modelId"
multiple = "true"
name = "models" />
</display:column>

<display:column property = "year" title = "year" />

</display:table>


然而,现在有比 DisplayTag 更好的替代品,例如 jQuery DataTablesjQuery jqGrid ;对于后者,还有一个插件 ( struts2-jquery-grid-plugin ) 可以帮助您在不知道其语法而只知道 struts2 标签的情况下使用网格。

关于java - struts2,转换s :select list to display Tag column,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36711299/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com