Friday, May 24, 2013

How to set the default value of Selectonemenu Jsf Primefaces

This is an example to set the default value of Selectonemenu in Jsf Primefaces :

we have a user that we need change his group from a list of groups.


User.group : Administrateur

Application.groups : {Administrator,Moderator,guest}


<p:selectOneMenu value="#{User.group}">  
<f:selectItems value="#{Application.groups}" />  
</p:selectOneMenu>


The Result :

How to include any Customed jQuery script in Primefaces Jsf pages

As you know primefaces include by default jquery libs but I noticed that many primefaces developers need to add Customed jQuery in there Primefaces Jsf pages but they don't know how  .

to use jQuery script with Primefaces Jsf you need to import it like that in the <h:head></h:head> :


<script type="text/javascript" src="./js/ui3.js"/>

and in your jQuery script you need to start it with //<![CDATA[ and to end it with //]]>

Example :

//<![CDATA[ 
 $( init ); 
    function init() {
       (function($){
          var sortOpts = {
             connectWith: ["#sortablesA", "#sortablesB"]
          };
          $("#sortablesA, #sortablesB").sortable(sortOpts);
       })(jQuery);
    }
//]]>