JSF中属性名称(EL)的串联 [英] Concatenation of property name (EL) in JSF
本文介绍了JSF中属性名称(EL)的串联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用EL连接属性名称?
How can I concatenate the name of a property using the EL?
这是我尝试过的方法:
<ui:repeat value="#{someBean.getParts()}" var="part">
<h:inputTextarea value="#{someOtherBean.result}#{part}" />
</ui:repeat>
但这没用。
bean具有四个属性resultA,resultB,resultC和resultD。 getParts()返回 A, B, C和 D。
The bean has the four property resultA, resultB, resultC and resultD. getParts() returns "A", "B", "C", and "D".
推荐答案
我认为不更改设计就无法使其正常工作。在Java中,设计要求您通过名称访问方法字段和属性通常是一个坏主意,如果名称是由字符串构建的,则更糟。
I don't think that can be made to work without changing the design. It's generally a bad idea in Java to have a design that requires you to access methods fields and properties through a name, and worse if the name is built from strings.
可能解决方案:
- 具有
getParts()
返回 resultA, resultB,等等,并访问它们#{someOtherBean [getParts()]}
- 将属性名称更改为
a
,b
,c
,d
并以#{someOtherBean [getParts()]}
- 的方式访问它们具有单个属性
result
包含Map
,其中以 A, B等作为键,并以#{someOtherBean .result [getParts()]}
- have
getParts()
return "resultA", "resultB", etc. and access them#{someOtherBean[getParts()]}
- change the property names to
a
,b
,c
,d
and access them as#{someOtherBean[getParts()]}
- have a single property
result
that contains aMap
with "A", "B", etc as keys and access the values as#{someOtherBean.result[getParts()]}
这篇关于JSF中属性名称(EL)的串联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文