Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing parameters to a method in h:outputtext tag

Tags:

jsf

el

I would like to display a text in jsf screen by passing an attribute to a method implemented in backing bean. I have to pass a dynamic value as an attribute. I tried the below but it seems to be an incorrect syntax -

<h:outputText value="#{getValue(#{item.product}).component.address}" />
like image 595
Punter Vicky Avatar asked Dec 07 '11 11:12

Punter Vicky


1 Answers

Apart from the syntax error (you can never nest EL expressions like as #{#{}}), the following is valid in EL 2.2 which is in turn part of Servlet 3.0 / Java EE 6:

<h:outputText value="#{bean.getValue(item.product).component.address}" />

So if you have a Servlet 3.0 compatible target runtime (Tomcat 7, Glassfish 3, JBoss 6, etc) with a Servlet 3.0 compatible web.xml, then you can invoke non-getter methods with arguments like this.

However, based on your question history you're using JSF 1.2 and the chance is big that you're also targeting an older container where the above wouldn't work. If it is a Servlet 2.5 container, then you could use JBoss EL to get this EL syntax to work.

See also:

  • Invoking methods with parameters by EL in JSF 1.2
like image 51
BalusC Avatar answered Oct 13 '22 20:10

BalusC