【发布时间】:2023-03-22 19:50:01
【问题描述】:
我见过有人在 JSF 中使用方括号,但我不确定我是否正确理解了它的用法。所以也许JSF大师可以帮助我理解它
1.所以说我有这个
#{bean.x}
而x是一个二维数组(x[][]),如何使用EL显示x[0]?我想在这种情况下我需要使用方括号。我想我使用#{bean.x[0]},但我遇到了异常。
2.第二种情况来自BalusC代码Pass Argument to a composite-component action attribute
<composite:interface>
<composite:attribute name="bean" type="java.lang.Object" />
<composite:attribute name="action" type="java.lang.String" />
<composite:attribute name="property" type="java.lang.String" />
</composite:interface>
<composite:implementation>
<h:commandButton value="Remove" action="#{cc.attrs.bean[cc.attrs.action]}">
<f:setPropertyActionListener target="#{cc.attrs.bean[cc.attrs.property]}" value="Somestring" />
</h:commandButton>
</composite:implementation>
我了解代码在做什么,并且运行良好,但如果有人能解释在这种情况下方括号的用途,我将不胜感激。非常感谢
【问题讨论】:
-
第二部分,
cc.attrs是页面传递给组合的参数映射。如果bean的值为myBean且action的值为myAction,则#{cc.attrs.bean[cc.attrs.action]}将等价于#{myBean.myAction}(当然,但作为属性传递给组合。