1

I have a <p:dataTable var="object"> with a <p:commandLink> inside. In my bean I have a Map whose value I want to display in <p:commandLink value> . I need to pass a key to this map which is a concatenation of "someString" and #{object.firstName}. I would something like this to work:

value="#{bean.map['someString'+object.firstName]}"

How can I achieve this?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
AC_1985
  • 183
  • 9
  • 22

2 Answers2

2

You can concatenate strings in EL by creating a new EL variable with the string and EL expression just inlined. You can use <c:set> for that.

<c:set var="key" value="someString#{object.firstName}" />
<p:commandLink value="#{bean.map[key]}" ... />

Alternatively, if you're on EL 2.2 already which supports invoking direct methods, then you can just directly make use of String#concat() method.

<p:commandLink value="#{bean.map['someString'.concat(object.firstName)]}" ... />

If you're not on EL 2.2 yet, but are using EL 2.1, then you can always install JBoss EL to have the same feature.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
0

Mr AC_1985 didn't respond but for information I have some working code along these lines.

                            <h:panelGrid columns="1" cellpadding="5" style="width:100%">
                                <p:inputTextarea id="factsText" style="width:100%; height:100%;" rows="18" cols="100" 
                                value="#{property.model.property.facts[property.model.factsLanguage.code]}"
                                counter="display" maxlength="2000" counterTemplate="{0} characters remaining." autoResize="false" />
                                <h:outputText id="display" />
                            </h:panelGrid>

Here I have a combo box where I can select a language. Then the text is retrieved from the Map for the language selected.

Thanks My BalusC for your invaluable help, as always.

Allan

Allan D
  • 51
  • 3