wood burning stoves 2.0*
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 Android Security Essentials Live Lessons this week in the Android 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: 15964

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.

Customer surveys are for companies who didn't pay proper attention to begin with.
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
jQuery in Action, 2nd edition
subject: Can we access a variable in <h:outputText> tag?
Similar Threads
HTML & Javascript
Assigning jsp expression value to javascript variable
Superclass Reference
creating a common jsp for many JSPs
JS variable In JSP