PrimeFaces p:commandButton - jsf-2

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" ..../>

Related

show confirmDialog before rowEditor updates the model

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!

Primefaces - Ajax - Select Components

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>

primefaces datatable is not getting refresh in tab

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 :)

How to hide and show p:panel on commandbutton click

i have the following problem:
I'm new to JSF2 and primefaces.
I have a table in a page that will be populated with information, after the user enters a string and clicks a CommandButton. After clicking the button, I want it to be disabled until processing is over.
To disable the CommandButton I'm doing the following;
<p:commandButton update=":outPanel" widgetVar="btnSend" id="btnsend"
value="Calcular" actionListener="#{calcBean.getTrfs}"
onclick="btnSend.disable()" oncomplete="btnSend.enable()" />
And then I have a panel where I want to show its contents:
<p:panel id="outPanel" widgetVar="outpanel">
#{calcBean.result}
</p:panel>
How can I hide this outpanel when the page loads the first time?
How can I hide it when I click the CommandButton, and only show it again if the processing in my bean is successful?
Thanks.
Solved,
i have to put
closable="true" toggleable="true"
attributes in p:panel... Thanks
I have checked following panel hide and show using p:commandButton in JSF,
please try following methods in JSF,
<p:panel id="button_panel" widgetVar="testPanel" closable="true" toggleable="true">
<h1>Testing</h1>
</p:panel>
<p:commandButton onclick="PF('testPanel').show()" value="Show Panel" type="button"/>
<p:commandButton onclick="PF('testPanel').hide();" value="Hide Panel" type="button"/>
to show the panel after the ajax request is finished try this:
<p:commandButton update=":outPanel" widgetVar="btnSend" id="btnsend"
value="Calcular" actionListener="#{calcBean.getTrfs}"
onclick="btnSend.disable()" oncomplete="btnSend.enable();outPanel.show();" />

Create new data objects with a popup panel fails

Here I am again with a JSF problem, this time it is more about richfaces (4.2.1 final, JSF 2). I have an eytended DataTable and want to add new items. There ist the List of Journey-objects, every attribute have getter and setter. The table is created well (there are already some items in the list). And now I click the "add new item" button:
<a4j:commandButton ajax="true" value="Neue Fahrt hinzufügen"
actionListener="'{editorBean.prepareCreateJourney}" render="createJourneyPopupForm"
oncomplete="#{rich:component('createJourneyPopup')}.show()" />
The editorBean is SessionScoped, the method is properply called and create a new object of Journey called currentJourney. A popup comes up and should allow me to insert some input:
<rich:popupPanel id="createJourneyPopup" modal="true">
<h:panelGrid id="createJourneyPopupForm" columns="3">
<h:outputLabel for="currentId" value="ID" />
<h:inputText id="currentId"
value="#{editorBean.currentJourney.journeyNumber}" />
<rich:message for="currentId" />
[...and more...]
</h:panelGrid>
<a4j:commandButton value="Save"
execute="currentId currentTrainType operator">
<f:ajax event="click" listener="#{editorBean.doCreateJourney}"
render=":vmsEditorForm:resultTable" />
<rich:componentControl target="createJourneyPopup" operation="hide" />
</a4j:commandButton>
<a4j:commandButton value="Abbrechen"
onclick="#{rich:component('createJourneyPopup')}.hide();" />
</rich:popupPanel>
When i clicked the button, the method doCreateJourney is called, but the currentJourney is empty. It is the default Journey object after creating it. No setter was called, do a hint on the inputfields.
I checked the names twice, there are getters and setters for alle needed objects. I tried to change the scope, but no effect. Objects are the same, in the prepare method i created Journey(id=151) and in the save method it is still Journey(id=151).
What is going on here? I can't be this difficult to make some dialogs to create and edit data objects. Thank you for listening and for your help!
You need to wrap both your inputs and your commandButtons in a form in order to correctly submit the data.
<rich:popupPanel id="createJourneyPopup" modal="true">
<h:form>
... the content of your popupPanel
</h:form>
</rich:popupPanel>
Regards,

Resources