i am new to JSF and primefaces.. i wrote a small code... i am getting what i want to do with "h:commandbutton" but samething is not working with "p:commandbutton". is there any difference between the functionality of these two things.
<h:commandButton value= "enter" actionListener= "#{newJSFManagedBean.show()}"/><br/>
<p:commandButton value= "enter" actionListener= "#{newJSFManagedBean.show()}"/><br/>
i have tried alot of things, but newjsfmanagedbean.show() havenot been called from p:commandbutton but h:commandbutton is working fine. what is the reason :-( ?
*hey it worked :-) *
thanxmates
<p:commandButton process="#this" value= "enter" ajax="false" actionListener= "#{newJSFManagedBean.show}" /><br/>
You didn't share your show() function but I can guess that it looks like below :
public void show(ActionEvent event) {
// some stuff here
}
Well, just delete your brackets in your EL language if you want to use it with primefaces :
<p:commandButton value= "enter" actionListener= "#{newJSFManagedBean.show}"/>
Otherwise it looks for a show method which does not have any parameters.
You should add process="#this" to p:commandButton to get its action invoked. If you want to process any other components add process="#this,id1,id2" like this.
Hope this helps
Related
I'm using PrimeFaces dataTable and rowEditor in pretty default way:
<p:dataTable id="payments-table" var="apayment" value="#{payment.payments}" editable="true">
<p:ajax event="rowEdit" listener="#{payment.update}"/>
...
</p:dataTable>
I'd like a confirmation dialog to show itself on clicking to the 'check' button of rowEditor.
I know it's possible using JS confirm function (thanks to Show a confirm message before <p:rowEditor> updates the model on click of "OK" button):
<p:ajax event="rowEdit" listener="#{payment.update}" onstart="return confirm('Save changes?')"/>
But I would like the dialog to conform to the UI theme, confirmDialog component being the best candidate. Alas, I don't know how to use it here. I tried the following and it won't work (simply no confirmation occurres):
<p:ajax event="rowEdit" listener="#{payment.update}">
<p:confirm header="Remove payment" message="Remove payment?" icon="ui-icon-trash"/>
</p:ajax>
....
<p:confirmDialog global="true">
<h:form id="form-payment-confirm">
<p:commandButton value="Yes" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check"/>
<p:commandButton value="No" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close"/>
</h:form>
</p:confirmDialog>
Any ideas?
I think you can use in this case simple widgetVar and call show() or hide() functions. Here is your modified code:
<p:ajax event="rowEdit" listener="#{tableBean.onRowEdit}" oncomplete="myDialog.show()"/>
I use PF 3.5 and can't find global parameter in p:confirmDialog. May be it is new feature. So I simple deleted it of my code. Here is modified confirmDialog:
<p:confirmDialog widgetVar="myDialog" closeOnEscape="true" appendToBody="true" closable="true">
<h:form id="form-payment-confirm">
<p:commandButton value="Yes" type="button" update="#form" styleClass="ui-confirmdialog-yes" icon="ui-icon-check"/>
<p:commandButton value="No" type="button" onclick="myDialog.hide()" styleClass="ui-confirmdialog-no" icon="ui-icon-close"/>
</h:form>
</p:confirmDialog>
Please try and adjust this confirm dialog code! May be unnecessary code for update form or hide()...
EDIT:
If you want to dynamically adjust text message of confirmDialog, you can adjust from server-side. Perhaps it is not best solution. I think the second way is it adjust from client-side by JQuery.
Server-side:
The ajax event is same. It call onRowEdit listener which adjust simple String attribute. For example the bean containt:
String myDialogMessage = "Default message";
//getter and setter
public void onRowEdit(RowEditEvent event) {
myDialogMessage="Are you sure?";
}
and the dialog containt message property:
<p:confirmDialog widgetVar="myDialog" closeOnEscape="true" appendToBody="true" closable="true" message="{tableBean.myDialogMessage}">
Client-side:
You can use repleaceWith function of JQuery:
<script>
jQuery("myDialog.p").replaceWith(....
</script>
Of course need to develop more business logic to client-side, more functions. Maybe the server-side solution is faster.
Please try it!
Based on your comment, I edited:
I find this in 4.0 user' guide:
When pencil icon is clicked, row is displayed in editable mode meaning
input facets are displayed and output facets are hidden. Clicking
tick icon only saves that particular row and cancel icon reverts the
changes, both options are implemented with ajax interaction. Another
option for incell editing is cell editing, in this mode a cell
switches to edit mode when it is clicked, losing focus triggers an
ajax event to save the change value.
So ajax event works when row is change. Here is dataTable events which can you catch:
I hope this answer help to you find solution!
I'm using this primafaces example http://www.primefaces.org/showcase/ui/pprSelect.jsf,
but I'm having problem when I put the first p:selectOneMenu as required true, it isn't clean the second p:selectOneMenu when I choose the first option again.
Regards
What happens here is that when you try to "unselect" the first p:selectOneMenu, you end up triggering a validation rule.
You can do what you want by using two remoteCommand tags and JavaScript.
<p:remoteCommand name="makeSelection" process="select" update="suburbs" />
<p:remoteCommand name="clearSelection" process="#this" update="suburbs" >
<f:setPropertyActionListener value="#{null}" target="#{pprBean.city}" />
</p:remoteCommand>
Now you can decide which one to call using a javascript funcion
<p:selectOneMenu id="city" required="true" value="#{pprBean.city}" onchange="selectFunction(this)">
...
function selectFunction(el){
//if el.value is empty you call clearSelection();
//else you call makeSelection();
}
Another common solution is using a commandButton that clears the selection calling something like:
<p:commandButton update="suburbs" (...)>
<f:setPropertyActionListener target="#{pprBean.city}" value="#{null}" />
</p:commandButton>
I have one problem, data is not getting refresh in datatable.I am opening a dialoge box in which I have accordian panel in acordian panel I have tab in tab I have datatable.
<p:dialog id="dlgAddEditFundsCustFinAcct"
widgetVar="dlgAddEditFundsCustFinAcctWidget" modal="true"
'
.
<p:accordionPanel id="accAEFCFA" widgetVar="accWidget">
<p:tab id="tabDocuments" widgetVar="tabDocumentsWidget">
<p:panel id="pnlDocuments" widgetVar="pnlDocumentsWidget" >
<p:panelGrid id="pgDocumentTable" columns="5">
<p:dataTable id="dtDocumentTable" var="documentRecord" value="#addEditFundsCustFinAcctManagedBean.documentDetails}" widgetVar="documentTable">
And I have properly close all the tab.
And I am trying to call this dialogue box using
<p:commandButton value="Yes" styleClass="button-green"
id="btnAddSellerAccountSsr" oncomplete="confirmAccountDialog.hide(),dlgAddEditFundsCustFinAcctWidget.show()" update=":parentForm:dlgAddEditFundsCustFinAcct" />
"parentForm" is my form name.
The one thing is that if I call update inside the on some event like filtering on column or on rowclick then data is getting refresh in datatable.
<p:commandButton value="Yes" styleClass="button-green" id="btnAddSellerAccountSsr"
oncomplete="confirmAccountDialog.hide(),dlgAddEditFundsCustFinAcctWidget.show()"
update="dtDocumentTable" >
<f:ajax render="dtDocumentTable"/>
</p:commandButton>
use two forms. one for dialog box and other for parentform, and then update dialogbox datatable using its id
Thank You Saurabh and Zaido.
Unfortunatly both solution has not worked for me.
But I have solved the issue by calling clearfilter methode of datatable (this is client side methode).
<p:commandButton value="Yes" styleClass="button-green" id="btnAddSellerAccountSsr"
oncomplete="confirmAccountDialog.hide(),**documentTable.clearFilters();"**
update="dtDocumentTable" >
<f:ajax render="dtDocumentTable"/>
</p:commandButton>
where documentTable is widgetVar of datatable.
Hope this solution will help any one who has same issue :)
I'm working with primefaces mobile(0.9.2 - jsf2), and I have a strange problem.
I have a view with 2 buttons, one to add and another to save the order.
the add button works fine, but when I click on the save button, instead of call the save method, it goes first to the method add and after it goes to save method.
Anyone have a tip?
thank you..
...<div class="field-input" >
<p:commandButton action="#{pedidoMobileBean.adicionaProduto()}" id="pcbAdd" value="Adicionar" update="hpgItens hpgTotais hpgTipoBonificacao" icon="plus" iconPos="left" ></p:commandButton>
</div>
<div class="label-input"></div>
<div class="field-input">
<p:commandButton action="#{pedidoMobileBean.salvar()}" ajax="true" id="pcbSave" value="Salvar" update="hpgPedidoV3 :Form:hpgPedidoV1" ></p:commandButton>
</div>...
Try adding the process-attribute to your save-button:
<p:commandButton ajax="true" process="#this" ..../>
I seem to be having a problem where I have an a4j:commandLink on a rich:popupPanel but the action is not firing. The xhtml looks as follows:
<rich:popupPanel id="rate-panel" modal="true" height="444" width="780" top="60" show="false" onmaskclick="#{rich:component('rate-panel')}.hide()" styleClass="cs-modal">
/**Some html here**/
<a4j:commandLink immediate="false" action="#{venueScore.up}" render="rate-panel" styleClass="rate love">
<span>Love it</span>
</a4j:commandLink>
/**Some more html here**/
</rich:popupPanel>
And the managed bean looks as follows:
#Named("venueScore")
#ViewScoped
public class VenueScoreManager extends BaseManager implements Serializable {
public void up() {
System.out.println("TEST");
//Do something
}
}
I have made the managed bean #ViewScoped.
I have also tried adding an <h:form> around the commandLink however, this does even less than without it. I actually think that is because the commandLink is inside the <h:form> in which the link that opened the popupPanel sits.
Anyway, can someone please point me in the direction of why the action not fire?
Ok, so I fixed it myself. After screwing around I worked out that I just need to add an <a4j:region> around the content in the <rich:popupPanel>. So now the xhtml looks something like this:
<rich:popupPanel id="rate-panel" modal="true" height="444" width="780" top="60" show="false" onmaskclick="#{rich:component('rate-panel')}.hide()" styleClass="cs-modal">
<a4j:region id="panel-region">
/**Some html here**/
<a4j:commandLink immediate="false" action="#{venueScore.up}" render="panel-region" styleClass="rate love">
<span>Love it</span>
</a4j:commandLink>
/**Some more html here**/
</a4j:region>
</rich:popupPanel>
I had the same problem, a4j:commandLink only worked after first click.... put the poppanel inside a form and add domElementAttachment...
<h:form id="myform">
<rich:popupPanel id="pop" domElementAttachment="form">
...
<a4j:commandLink />
...
</rich:popupPanel>
</h:form>
I know that it's an old question but as I had exactly the same problem, I spent a lot of time before fixing it, maybe it will help someone else.
First, I tried the solution proposed above but it did not worked.
Finally, I found this thread:
Issues closing rich:popupPanel via show condition, RF 4.0
And I added the domElement attribute to my popup:
<rich:popupPanel
id="newMailPopup"
**domElementAttachment="form"**
...>
And now, my a4j:commandLink works perfectly :-)