I have seen people using square bracket in JSF, and I am not sure if I understand its use correctly. So maybe an JSF guru can help me understand it
1.So let say I have this
#{bean.x}
and x is a two dimensional array (x[][]), how do I display x[0]
using EL? I would imagine that I need to use square bracket in this case. I think I use #{bean.x[0]}
, but I got exception.
2.The second scenario is from BalusC code 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>
I understand what the code is doing and it works beautifully, but I would appreciate if someone can explain what is the use of the square bracket in this case. Thank you very much
cc.attrs
is the map of parameters passed to the composition by the page. Ifbean
has valuemyBean
andaction
has valuemyAction
, then#{cc.attrs.bean[cc.attrs.action]}
would be the equivalent to#{myBean.myAction}
(but passed as attributes to a composite, of course. – Breastwork