3 Replies Latest reply on Feb 16, 2006 12:12 AM by hookomjj

    Use JSP script in xhtml

    ericmacau

      Hello,

      How can I add some code in XHTML (under faceletes)?


        • 1. Re: Use JSP script in xhtml
          shane.bryzak

          It needs to be placed in a CDATA:

           <script type="text/javascript">
           // <![CDATA[
          
           // Your code here
          
           // ]]>
           </script>


          • 2. Re: Use JSP script in xhtml
            gavin.king

            I think he means a JSP scriplet, not javascript.

            Scriptlets are highly frowned upon. Use a JSF component.

            • 3. Re: Use JSP script in xhtml

               

              "ericmacau" wrote:
              Hello,

              How can I add some code in XHTML (under faceletes)?



              There's the beanshell addition to Facelets, but it was developed a long while ago and may need some updating. But for the most part, you should avoid scripting logical behavior within the presentation layer and take a more declarative approach with your UIs.

              With that said, you can do some neat things with EL/JSTL:

              #{myfn:staticFunction(bean.property)}

              Loading Functions within your tag libraries for specialized behavior-- these can even result in booleans and used in JSTL core/control tags.

              #{(bean.boolProp) ? 'A' : (bean.boolProp2) ? 'B' : 'C'}

              To inline chains of choice statements instead of doing if/elseif/else clauses. Much faster too btw.