File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes How to Write jQuery into RichFaces? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "How to Write jQuery into RichFaces?" Watch "How to Write jQuery into RichFaces?" New topic

How to Write jQuery into RichFaces?

Muhammad Ramahy

Joined: Jun 14, 2011
Posts: 11


I need to add jQuery into my richfaces page, basically I want to make a rich:panel sortable using the jQuery ui sortable()
the page goes like this:

I've also used the but it didn't work too
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17417

Welcome to the JavaRanch, Muhammad!

RichFaces has quite a few extensions to make displays more sortable using just JSF. RichFaces itself uses jQuery internally in some cases. You might want to check the list of tags and see if any of them help. I use sortable extendedDataTables all the time.

However, sometimes raw jQuery is what you need. You can usually get things to work right by enclosing the <script> elements inside <f:verbatim> elements. Like so:

The rather odd construction here has its reasons.

1. Following the <script> element, we start a JavaScript comment. That keeps the javaScript interpreter from attempting to interpret the "CDATA" as a JavaScript command.

2. The "CDATA" is the XML escape for all text down to its closing "]]>" sequence. Which is also hidden in a JavaScript comment.

The reason for using "CDATA" is that if you're using XHTML, the entire View definition must be valid XML. And while "&", "<" and ">" are all perfectly good JavaScript operators - and likewise the single and double quotes, all of the above have special meanings to XML and therefore must be escaped or the XML may not parse properly. If you didn't use CDATA, you'd have to deal with horrors like this:

Which could have been even worse, but in this particular case, the quotes were all unambiguous. Otherwise you'd have to do stuff like "&quot;are you sure?&quot;". In fact, even the ampersands are OK here, but if there'd been a "if ( a > b )", that would have been certain trouble.

An IDE is no substitute for an Intelligent Developer.
Muhammad Ramahy

Joined: Jun 14, 2011
Posts: 11

Thanks Tim
I agree. Here's the link:
subject: How to Write jQuery into RichFaces?
It's not a secret anymore!