访问嵌套 JSP 标记之间的变量
我想在两个嵌套的 JSP tagx 工件之间交换信息。举个例子:
list.jspx
<myNs:table data="${myTableData}">
<myNs:column property="firstName" label="First Name"/>
<myNs:column property="lastName" label="Last Name"/>
</myNs:table>
现在,table.tagx 应该显示嵌套列标签中定义的数据列。问题是如何从表标签访问嵌套列标签的 property 和 label 属性的值。我尝试了 jsp:directive.variable 但这似乎只能在 jsp 和标签之间交换信息,而不能在嵌套标签之间交换信息。
请注意,我想完全避免对表和列标记使用 java 支持对象。
我还想知道如何访问由父标记定义的属性(在本示例中,我想从 column.tagx 访问 table.tagx 中的数据属性的内容)。
所以它归结为如何访问嵌套 JSP 标签之间的变量,这些变量纯粹是通过标签定义本身实现的(不需要 Java TagHandler 实现)?
I would like to exchange information between two nested JSP tagx artifacts. To give an example:
list.jspx
<myNs:table data="${myTableData}">
<myNs:column property="firstName" label="First Name"/>
<myNs:column property="lastName" label="Last Name"/>
</myNs:table>
Now, the table.tagx is supposed to display the data columns as defined in the nested column tags. The question is how do I get access to the values of the property and label attributes of the nested column tags from the table tag. I tried jsp:directive.variable but that seems only to work to exchange information between a jsp and a tag, but not between nested tags.
Note, I would like to avoid using java backing objects for both the table and the column tags at all.
I would also like to know how I can access an attribute defined by a parent tag (in this example I would like to access the contents of the data attribute in table.tagx from column.tagx).
So it boils down to how can I access variables between nested JSP tags which are purely implemented through the tag definitions themselves (no Java TagHandler implementation desired)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个想法是在请求范围内共享数据:
在 myNs:table 中创建一个请求范围的占位符变量来保存数据(在您的情况下,您将需要其中两个:一个用于属性,另一个用于标签):
以便列可以填充占位符。在 myNs:column 中填充占位符,记住将它们保留在请求范围内:
<前><代码>;
>
现在,在 myNs 中调用
后:table 你已经填充了值,你所需要的就是使用逗号作为分隔符来分割字符串,然后做你想做的事情:<前><代码><表>;
<头>
PS: 功劳归于 Spring Roo 的人,看看他们的 表。 tagx 和 column.tagx。
The idea is to share the data in request scope:
In myNs:table create a request scoped placeholder variable to hold the data (in your case you will need two of them: one for properties and another for labels):
<jsp:doBody />
so that columns could populate the placeholders.In myNs:column populate the placeholders, remember to keep them in request scope:
Now, after you invoked
<jsp:doBody />
in your myNs:table you got the values populated, all you need is to split the string using comma as a separator and then do whatever you want:P.S.: The credits go to Spring Roo guys, take a look at their table.tagx and column.tagx.