javascript - JSF components not parsed inside a <script> block -
i had change <script> ... </script>
in jsf page , tried evaluate jsf component inside of script. el evaluated tag untouched.
what reason behaviour?
example:
<script type="text/javascript"> //<![cdata[ function dosomething() { $('.usernode').droppable({ activeclass : 'ui-state-active', hoverclass : 'ui-state-highlight', tolerance : 'intersect', drop : function(event, ui) { <h:panelgroup rendered="#{mybean.usethis}"> alert("code a"); </h:panelgroup> <h:panelgroup rendered="#{!mybean.usethis}"> alert("code b"); </h:panelgroup> } }); }; //]]> </script>
the el #{!mybean.usethis}
evaluated true/false <h:panelgroup>
in result of rendering.
why?
it's because placed inside cdata block. inside cdata block considered character data, not xml data.
better don't @ all. poor practice. put js function in own .js
file. use jsf/el prepare javascript variables js functions ask (as method argument) or access (in window scope), not fill parts of js functions.
e.g.
<h:outputscript>var usethis = #{mybean.usethis};</h:outputscript> <h:outputscript name="script.js" />
function dosomething() { $('.usernode').droppable({ activeclass : 'ui-state-active', hoverclass : 'ui-state-highlight', tolerance : 'intersect', drop : function(event, ui) { if (usethis) { alert("code a"); } else { alert("code b"); } } }); }
to prevent pollution of global scope, consider creating namespace.
<h:outputscript>var = my||{}; my.usethis = #{mybean.usethis};</h:outputscript>
if (my.usethis) { alert("code a"); } else { alert("code b"); }
Comments
Post a Comment