How to use square bracket in EL JSF

被刻印的时光 ゝ 提交于 2019-12-04 12:36:28
BalusC

I think I use #{bean.x[0]}, but I got exception.

It's unfortunate that you didn't share the exception details. But this should just work, provided that there's a getX() method which returns a non-null array of which the given index really exists.


The second scenario is from BalusC code Pass Argument to a composite-component action attribute

In this particular case, the brace notation [] enables you to use a dynamic property name or action method name. The following of course don't work

#{cc.attrs.bean.cc.attrs.action}

It would only try to invoke bean.getCc().getAttrs().action().

The brace notation is also used on Map<K, V>. It allows you to specify keys which contain dots (which in turn shouldn't be EL-evaluated as properties)

#{bean.map['key.with.dots']}

It of course also allows you to specify a dynamic map key:

#{bean.map[otherBean.mapKey]}

See also:

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!