1

In my .xhtml pages in my JSF 2.0 application, I am trying to find out a way to have multiple EL values and strings to be used with a single HTML attribute. The following WRONG syntax will give you the idea:

<h:outputText value=" 'Welcome' + #{myBean.loggedInUser} + ' '  "/>

So I am wondering what is the correct way of doing it. I don't need a workaround (as h:outputText is just an example).

Also let me know if your suggestion works in JSP/JSF1.2 or not

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Saed Alavinia
  • 234
  • 3
  • 12
  • possible duplicate of [Concatenating strings within EL expression defined in an attribute of a facelets tag](http://stackoverflow.com/questions/7386133/concatenating-strings-within-el-expression-defined-in-an-attribute-of-a-facelets) – Luiggi Mendoza Jan 28 '13 at 23:34

2 Answers2

2

You don't need any special operators. You can just inline EL in text.

<h:outputText value="Welcome #{myBean.loggedInUser}" />

or

Welcome <h:outputText value="#{myBean.loggedInUser}" />

or even in template text

Welcome #{myBean.loggedInUser}
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • I am looking to have something like the first one, but mine doesn't work. Second and third option does work, but as I said outputText is an example. The actual code contains more complex tags. – Saed Alavinia Jan 29 '13 at 16:12
  • You're welcome. In the future, post an SSCCE instead of oversimplified code which doesn't accurately represent the actual code. – BalusC Jan 29 '13 at 16:17
-1

The <h:outputFormat> component?

http://www.jsftoolbox.com/documentation/help/12-TagReference/html/h_outputFormat.html

I believe that is either JSF 1.2 or 2

Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
EdH
  • 4,918
  • 4
  • 24
  • 34
  • Alternatively, you could have a request-scoped bean that handles the concatenation / construction of the attribute's value as method output. Then call the method within the xhtml. – EdH Jan 28 '13 at 23:37
  • Do not try to mix view logic with business logic or server side logic. If you do that, you're breaking the MVC pattern. – Luiggi Mendoza Jan 28 '13 at 23:57