[英]Struts2, convert s:select list to display Tag column
I have the following selection list in jsp: 我在jsp中有以下选择列表:
<td>
<s:select list = "models"
listValue = "modelName"
listKey = "modelId"
multiple = "true"
name = "models" />
</td>
I chose to implement pagination with display Tag
library, so I want to convert it in display column and show one ore more models from the list. 我选择使用
display Tag
库来实现分页,因此我想在显示列中转换它并从列表中显示一个或多个模型。 How can I do this? 我怎样才能做到这一点? Below is my display table with the other columns:
下面是我的显示表和其他列:
<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>
First of all, you need to make DisplayTag pushing the value in a context you can access: 首先,您需要使DisplayTag在您可以访问的上下文中推送值:
Implicit objects created by table
由表创建的隐式对象
If you add andid
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.如果添加了
id
属性,则表标记会使页面上下文中对应于给定行的对象可用,因此您可以在scriptlet代码或其他标记中使用它。 Another implicit object exposed by the table tag is the row number, namedid_rowNum
.表标记公开的另一个隐式对象是行号,名为
id_rowNum
。These objects are saved as attributes in the page scope (you can access it using
pageContext.getAttribute("id")
).这些对象在页面范围中保存为属性(您可以使用
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.它们也被定义为嵌套变量(可使用
<%=id%>
),但前提是id atribute的值不是运行时表达式。 The preferred way for fetching the value is to always usepageContext.getAttribute()
.获取值的首选方法是始终使用
pageContext.getAttribute()
。If you do not specify the id attribute no object is added to the pageContext by the table tag
如果未指定id属性,则表标记不会将任何对象添加到pageContext
Then you need to access that context. 然后,您需要访问该上下文。 In Struts2, the
pageContext
is available through #attr
: 在Struts2中,
pageContext
可以通过#attr
:
Struts 2 Named Objects :
Struts 2命名对象 :
#attr['foo']
or#attr.foo
#attr['foo']
或#attr.foo
Access to
PageContext
if available, otherwise searchesrequest
/session
/application
respectively访问
PageContext
如果可用),否则分别搜索request
/session
/application
So the code would be: 所以代码是:
<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>
Nowadays, however, there are better alternatives than DisplayTag, for example jQuery DataTables and jQuery jqGrid ; 然而,现在有比DisplayTag更好的选择,例如jQuery DataTables和jQuery jqGrid ; for the latter there is also a plugin ( struts2-jquery-grid-plugin ) that helps you use the grid without knowing its syntax, just knowing struts2 tags.
对于后者,还有一个插件( struts2-jquery-grid-plugin ),它可以帮助您在不知道语法的情况下使用网格,只需要知道struts2标签。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.