File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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
Author

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

Nagendra Shastry
Greenhorn

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: 16061
    
  21

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
Greenhorn

Joined: Sep 22, 2013
Posts: 13
Could think of two other approches
1. Implementing the javascript logic inside ManagedBeans
2. Writing Custom Converters
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Can we access a variable in <h:outputText> tag?