Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Embedding Javascript in a facelet Page

 
Ranch Hand
Posts: 495
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have defined a Javascript function in the middle of my facelet page


But whenever the page is generated and i look into the HTML all i can see is




which means the Javascript code is getting lost, Please how do i resolve this
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Facelets uses XHTML as markup language which on its turn is based on XML.

The above is not only invalid XML syntax, but also a bad practice. You shouldn't tight couple scripting with presentation. Place Javascript code in its own .js file which you load in the head. If you want to include scripting in presentation at any way, then in case of XHTML you need to wrap it with XML CDATA tags.
 
Abiodun Adisa
Ranch Hand
Posts: 495
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bauke Scholtz wrote:Facelets uses XHTML as markup language which on its turn is based on XML.

The above is not only invalid XML syntax, but also a bad practice. You shouldn't tight couple scripting with presentation. Place Javascript code in its own .js file which you load in the head. If you want to include scripting in presentation at any way, then in case of XHTML you need to wrap it with XML CDATA tags.



I embedded it using CDATA but it still does not show
 
Saloon Keeper
Posts: 24580
168
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wrap it in a "f:verbatim" tag. Also be careful where you place it - A good place in a facelets composition is right up top after the ui:define's but before the content. DON'T put it outside the ui:composition, since that stuff all gets discarded by definition.

CDATA is highly recommended, but not essential. In your case, it wouldn't have mattered. CDATA is what keeps you from getting into trouble when you have relational operators (<, >) and other XML tokens in your javascript code. You could also use the XML entities and avoid CDATA, but that's kind of pointless. And ugly.
reply
    Bookmark Topic Watch Topic
  • New Topic