File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes Can we access a variable in <h:outputText> tag? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Can we access a variable in <h:outputText> tag? " Watch "Can we access a variable in <h:outputText> tag? " New topic

Can we access a variable in <h:outputText> tag?

Nagendra Shastry

Joined: Oct 26, 2010
Posts: 19
Hi all,

Can we access a variable inside a rich model panel's <h: output Text > tag's value attribute? I need to display something like <h:output Text value ="This will affect '+VARIABLE+' records"> . I have to calculate the value of variable from a java script code. Please help me out.!
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17423

No you cannot do that. Because the outputText text is rendered BEFORE the page is sent to the client, and therefore before the JavaScript runs.

What you can do is have JavaScript alter the text of that control AFTER the page is rendered as a standard DOM modification process. You can even use jQuery to do the job, since jQuery is automatically included as part of RichFaces.

Don't forget, however, that when using jQuery in JSF that the "$()" expression form should be avoided (use the "jQuery()" form) and that the ID of the outputText control that the will be the element's low-level ID, and not the simple "id=" value in the JSF control.

An IDE is no substitute for an Intelligent Developer.
Balaji Manoharan Bm

Joined: Sep 22, 2013
Posts: 13
Could think of two other approches
1. Implementing the javascript logic inside ManagedBeans
2. Writing Custom Converters
I agree. Here's the link:
subject: Can we access a variable in <h:outputText> tag?
jQuery in Action, 3rd edition