commandButton actionListener isn"t called when an other component is required - primefaces

I tried <p:commandButton> as shown above, it works correctly.
<p:spinner id="spinnerQte" min="1" value="#{newOpProgramme.quantite}"/>
<p:commandButton id="AjoutEquip" value="Ajouter" actionListener="#{newOpProgramme.addEquipement()}" update="spinnerQte"/>
But, when I tried ti nest this in my global page inside layout, panel, panel-Grid and field-Set, addEquipement() method is not called !
also, thee some fields which have required attribute set to true, I think this is why addEquipement() method isn't called.
Have you an Idea how to fix the problem.
thank you

I fixed the problem by adding process attribute to <p:commandButton> set to #this.

Related

Primefaces "reset fail" example

The documentation on the Primefaces showcase page gives a number of examples for ajax and non-ajax reset buttons. One is called "reset fail" and it can be found here. It simply involves calling an actionListener which sets all relevant backing bean fields to null.
I tried "reset fail" and it seems to do the job. So why is it a "fail" example and why do the docs say it "won't work"?
Thanks!
OK try this...
On that Showcase demo page enter "a" in the first field and "bbb" in the second field and press "Submit". You will get a validation error.
Now press "Reset Fail". See how the first field is still highlighted RED as validation has failed?
Now press "Reset Tag" and you will see the RED highlighted field go away.
So the difference is the Reset Fail doesn't reset the validation failures and Reset Tag does.
In the end, a combination of actionListener= and resetValues="true" worked for me, i.e:
<p:commandButton value="Reset" actionListener="#{otb.resetFail}" process="#this" update="#form" resetValues="true" style="margin-left:20px;"/>
Without the actionListener my fields don't clear properly. But the resetValues attribute is needed to get around the validation issue. I got this idea from the StanL answer in this post.
One more thing - in contrast to the example in the PF demo, my bean's "resetFail" method just nulls out the fields. It does not call PrimeFaces.current().resetInputs("form:panel"); (I don't have that library). Still, it works fine.

How to show/hide a p:button based on a checkbox selection inside a p:datatable?

I have a simple button,
<h:panelGroup>
<p:commandButton rendered="#{myBean.checkboxSelected}" value="Action" />
</h:panelGroup>
which is set to false and has getters and setters in the bean, that I want to toggle its rendered attribute (or hide/show it) based on whether ANY checkbox inside my p:dataTable is selected. Conversely, if I check one box and uncheck it, I want to be able to hide button as no checkboxes are selected.
My p:dataTable is set up like this.
<p:dataTable id="someID"
selection="#{myBean.mySelectList}"
rowKey="#{myBean.id}">
<p:column selectionMode="multiple" style="text-align:center"/>
....
</p:dataTable>
Any help is appreciated
Short answer: update it when there is more than one item selected.
Longer answer: On each selection, update the number of items server side (or just count the list) and use that value in a 'rendered' attribute of the button (check if > 0, or do that server side and use a boolean) and update the panelgroup on each ajax call or do that from the server as well.
All plain 'logic' when using JSF, nothing special, nothing fancy

outer p:selectCheckBoxMenu visible from composite p:dialog

I have the following scenario :
Page.xhtml (p:selectCheckBoxMenu id=sb1)
From page.xhtml I call genericDialog.xhtml
genericDialog.xhtml (Composite implementation with p:dialog,etc...)
From genericDialog.xhtml how can I process and update via p:ajax the sb1 component.
Error : javax.faces.FacesException: Cannot find component with identifier "formPessoa:tipoMercado" referenced from "j_idt440:myForm:confirm"
From the left side of image in green color I have my composite p:dialog (genericDialog.xhtml)
From the right side of image I have in red the selectCheckBoxMenu id=sb1 which I need to reload after saving new data from dialog.
thanks a lot stack members.
After a lot of time to me.... I figured out the issue:
<p:commandButton id="confirm" value="#{cc.attrs.labelbotao1}"
oncomplete="#{cc.attrs.oncompletebotao1}" update="myForm:divmessage"
actionListener="#{cc.attrs.actionbeanbotao1}" **ajax="true"**>
<p:ajax update="#{cc.attrs.ajaxupdate1}" process="#{cc.attrs.ajaxprocess1}"
listener="#{cc.attrs.listener1}" />
</p:commandButton>
Two problems:
First I need to reference in the composition genericDialog.xhtml the full path to update the component e.g. myform: sb1
Second the AJAX on p: commandButton has to be false. This way it does not cancel the p: AJAX update and process.
I'd like to hear some other opinions or fixes, etc.

PrimeFaces DataTable - Row Selection inquiry

How does this code in the PrimeFaces DataTable row selection work?
<p:commandButton update=":form:display" oncomplete="confirmation.show()" image="ui-icon ui-icon-close" title="Delete">
<f:setPropertyActionListener value="#{car}" target="#{tableBean.selectedCar}" />
</p:commandButton>
I am confused by the following: update=":form:display", and image="ui-icon ui-icon-close".
Is this inbuilt into Primefaces? or do I need to create an additional form, or have an external image mapped to it?
update=":form:display" refers to a specific element on the page. The first ':' goes to the root of the page, so there needs to be a component with the id "form" (probably a form) and inside that a component with the id "display". This means after the button actions has completed :form:display will be updated. Note that it's generally not a great idea to use absolute paths as they can be hard to keep up to date when you change the page structure. If the button is on the same level as the "display" component you could just do update="display", or you can do things like update="#form" to update the entire current form.
image="ui-icon ui-icon-close" refers to style classes in your css. These two comes predefined with primeface, but if you want to use custom graphics you can also define your own style classes for them.

conditionally show Primefaces dialog box

In reference to the query that I have posted
Primefaces Dialog box - show it conditionally. javascript code not working
The problem is that when
<p:outputPanel id="dialogPanel"
rendered="#{not reqSearchHandler.accStatusFlag}">
is not rendered as rendered turns out to be FALSE , then when I click on the commandbutton , its keep on clocking and I am not able to go the next page , it seems that ajax request is never getting completed as oncomplete="dlg3.show()" needs dialog box in the page.As rendered turns out to be false , it never finds dlg3.
<p:commandLink id="addRequest" immediate="true" value="addreq"
oncomplete="dlg3.show()" update="dialogPanel">
<f:setPropertyActionListener
value="#{searchHandler.selectedAccIns}"
target="#{reqSearchHandler.checkAccStatus}" />
</p:commandLink>
Can somebody please help me how to avoid opening dialog box when a particular condition is false. Any Idea?
Is the dlg3 inside of dialogPanel? Why don't you post the complete code?
If so, then just before calling dlg3.show)(), change the rendered condition to true (e.g. by adding action listener) or just move the dialog outside the panel.