Showing posts with label Primefaces. Show all posts
Showing posts with label Primefaces. Show all posts

March 02, 2016

How to partial reset form in primefaces


To reset input fields of a part or a component of a form programmatically , we need to use reset method similarly like we do update through managed bean.
for example I have below code snippet :

1:  <p:panel id="panel">  
2:       <p:inputText id="text1">   
3:       <p:inputText id="text2">   
4:       ...  
5:       <P:commandButton .. />  
6:  </p:panel>  

and need to reset the component ("panel") then using below code in managed bean I can reset all input fields/components under it:

 RequestContext.getCurrentInstance().reset("form:panel");  

It will reset only the component which is provided in rest method.

January 10, 2016

How to set multiple Default Command using Primefaces 5

Primefaces 5, gives a feature to allow multiple defaultcommand (ENTER) within a form.
Default Command can be use to define which commandbutton should be triggered when the enter key is pressed.

Following is the code for defining defaultCommand in primefaces.

 <p:defaultCommand target="buttonId" />  
target is the identifier of commandbutton that needs to be triggered.

Now, to allow mutiple command buttons triggering within the same form we need to use scope attribute in the same tag as below:

 <p:defaultCommand target="buttonId" scope="panelgrid_id" />  
 Example,  
 <h:panelGrid columns="2" cellpadding="5" id="panelgrid1">   
      <h:outputLabel for="btnSelect" value="Button 1:" />   
 ................  
 ................  
 <p:commandButton value="Button1" id="btn1" actionListener="#{defaultCommandView.btn1Submit}" />   
 <p:defaultCommand target="btn1" scope="panelgrid1" />  
 </h:panelGrid>   
 <p:separator />   
 <h:panelGrid columns="3" cellpadding="5" id="panelgrid2">   
 <h:outputLabel for="btnSelect" value="Button 1:" />   
 ................  
 ................  
 <p:commandButton value="Button2" id="btn2" actionListener="#{defaultCommandView.btn2Submit}" />   
 <p:defaultCommand target="btn2" scope="panelgrid2" />  
 </h:panelGrid>  
There are 2 default command tags been used in above code so, if user has any input text in focus under panel grid one then it on press on ENTER key then it will trigger command button one. Similarly for command button second.