Use value from backing bean in javascript

What I want is to use a boolean value from applicationContext.properties (Jboss configuration file) in my javascript.

Currently I use Spring to inject a value configured in applicationContext.properties into my backingbean. Then I put an output text in my jsp like this

<h:outputText id="idValue" styleClass="foo" value="" rendered="#{bean.isRendered}"/>

In my JavaScript I try following

  jQuery(function(){
     bRedirect = jQuery(".foo").value != undefined;
     ...

All this looks so terrible to me, even though it works fine. There must be a smarter way than doing what I do.

Note that I am running JSF1.2 and therefore must use jQuery instead of $ and also select by unique class (foo) and not by id, which may be bad practice as well.

Thank you in advance. alfons

Answers


Assuming the function is to be called whenever part is rendered you can embed just your function call in the template:

<script type="text/javascript">
  myFunction("#{springExpressionForBooleanValue}")
</script>

and myFunction definition resides in .js file not processed by JSF. I can't see why you are unable to use $ to address jQuery object in such scenario.

If the function is to be called as a result of some interaction you can make it part of onclick/oblur etc attribute of your JSF component.

You can also embed entire function in the script tag but I think it's better to separate JavaScript logic from your templates.


Need Your Help

how to get hash code of a string in c++

c++ string hash hashcode

Following java code returns hash code of a string.

Error: gdal-config not found

linux r installation gdal

Please point out the point that I am missing:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.