File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes Calling method in the outputText value attribute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Calling method in the outputText value attribute" Watch "Calling method in the outputText value attribute" New topic

Calling method in the outputText value attribute

Rahul Juneja
Ranch Hand

Joined: Aug 03, 2002
Posts: 425

I want to do something like the following in my code. Is it possible to use method calls in value parameter of outputText.

Any pointers are appreciated.


Rahul Juneja
ThoughtClicks -
Arun Sudharsanam

Joined: May 29, 2008
Posts: 21
Why do you want to call a method from an outputText.
If you want to assign the return value of the method to the outputText you can just do it as:
<iceutputText value="#{}"/>

and code in the bean as follows:

String Name;

//Getters and setters for the Variable

Himanshu Gupta
Ranch Hand

Joined: Aug 18, 2008
Posts: 598

You can call a method in Value just do one thing for that.

Name the method in backing Bean like getXXX() and in the Page bind it like value="#{beanName.XXX}".

Point to remember: The return type of the Method should be String.

My Blog SCJP 5 SCWCD 5
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17410

You shouldn't call action code in an attribute (property) accessor. Technically, that's known as a side-effect. In JSF it's especially important, since the accessor may get invoked more than once and at unpredictable times.

If you desire a placid life, always make your getter functions read-only and your setters should update only data and not fire off actions of their own. Leave the heavy-duty logic to action processor methods.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: Calling method in the outputText value attribute
It's not a secret anymore!