Primefaces confirm dialog disappearing almost instantly - jsf

I'm developing an application in JSF 2.0. I'm also using the Primefaces component library. I'm having a problem with the p:confirmDialog of Primefaces. As soon as I want to show a p:confirmDialog, it disappears again almost instantly. The weirdest thing is that this problem only occurs with the application that is deployed on the GlassFish Server at work. When I upload the very same .war file to the GlassFish server on my computer at home or when I run the application in Netbeans this problem does not occur. I really can't find out what the cause of this problem is. Also I couldn't find any information about this on Google. Any help would be greatly appreciated! This is my code:
<h:commandButton value="Verwijderen" onclick="bezoekConfirmation.show()" styleClass="verwijderKnopBig" rendered="#{pageRenderController.canWriteBezoekenMobiele}" />
<p:confirmDialog message="Bent u zeker dat u dit bezoek wilt verwijderen?" closable="false"
header="Bezoek verwijderen" severity="alert" widgetVar="bezoekConfirmation">
<p:commandButton value="Ja" oncomplete="bezoekConfirmation.hide()" action="#{bezoekenMobieleController.deleteBezoek}" ajax="false" />
<p:commandButton value="Nee" onclick="bezoekConfirmation.hide()" type="button" />
</p:confirmDialog>

Clicking on the button will cause a submit. The dialog appears, and the page is reloaded immediately.
Change this:
bezoekConfirmation.show()
to this:
bezoekConfirmation.show(); return false;
It's really strange that your version works on your computer at home.

The solution with return false; will only work if you do not intend to call a method or set a variable.
In this case, just use oncomplete="dialog.show();" instead of onclick="dialog.show();"
This will pass through the method call.
Example:
Given that the following code is in some kind of data table then you can have
<p:commandButton value="edit" update=":dialog" oncomplete="dialog.show();">
<f:setPropertyActionListener target="#{bean.field}" value="#{_item}" />
</p:commandButton>
or call the setter directly
<p:commandButton value="edit" update=":dialog" oncomplete="dialog.show();" action="bean.setField(_item)">
</p:commandButton>

<h:commandButton value="Verwijderen" onclick="bezoekConfirmation.show()" styleClass="verwijderKnopBig" rendered="#{pageRenderController.canWriteBezoekenMobiele}" />
<p:confirmDialog message="Bent u zeker dat u dit bezoek wilt verwijderen?" closable="false"
header="Bezoek verwijderen" severity="alert" widgetVar="bezoekConfirmation" appendToBody="true">
<p:commandButton value="Ja" oncomplete="bezoekConfirmation.hide()" action="#{bezoekenMobieleController.deleteBezoek}" ajax="false" />
<p:commandButton value="Nee" onclick="bezoekConfirmation.hide()" type="button" />
</p:confirmDialog>
appendToBody="true" will overcome your problem

Related

enable save button when there is an update

I have to enable the 'save button' only when there is an update in my form page, otherwise it should be disabled. Here after the code I am using for :
<a4j:commandButton styleClass="boutonAction buttonSave"
value="#{messages['btn.save.label']}"
update="editForm"
action="#{Action.save()}"
ajaxSingle="false" immediate="false" limitToList="true"
reRender="msg" />
I think in this case I need to include a JS ?
You can use disabled attribute
<a4j:commandButton value="Update"
disabled="#{!bean.save}"/>
<a4j:commandButton value="Save"
disabled="#{bean.save}"/>
Now how you will disable/enable button,Put this inside a panel grid if you have logic to hide/show in your bean method then on action you can update the save variable.
<h:panelGrid id="panelGrid">
<a4j:commandButton value="Update"
disabled="#{!bean.save}" render="panelGrid"/>
<a4j:commandButton value="Save" action=""
disabled="#{bean.save}" render="panelGrid"/>
</h:panelGrid>
There could be other way also possible but you have to clearly right your problem in detail.
I resolved the issue by using this :
disabled="#{editForm.editAccess == 'false'}"
I tried with IE it works. Apparently firefox do not make darken the button.

Primefaces confirm dialog retains its background opacity after it is dismissed

Someone who have used Primefaces 4.0-SNAPSHOT may have noticed the following warning.
The appendToBody attribute of the ConfirmDialog will be deprecated in
future versions. Please use appendTo="#(body)" now
Along with Primefaces 4.0 RC1, I have this piece of code.
<h:body>
<h:form prependId="true" id="form">
<p:confirmDialog id="confirmDialog"
widgetVar="confirmDeleteMultiple"
message="Message"
showEffect="true"
hideEffect="true"
header="Header"
severity="alert"
closeOnEscape="true"
appendTo="#(body)" <-----------------
closable="true">
<p:commandButton id="btnYes"
value="Yes"
process="#this"
oncomplete="confirmDeleteMultiple.hide()"/>
<p:commandButton id="btnNo"
value="No"
onclick="confirmDeleteMultiple.hide()"
type="button" />
</p:confirmDialog>
<p:commandButton oncomplete="confirmDeleteMultiple.show()"
update=":form:confirmDialog"
actionListener="#{testManagedBean.insert}"
ajax="true" type="submit" value="Submit"/>
</h:form>
</h:body>
When the only command button on the page is clicked, the dialog appears with the two buttons given.
On pressing any of these buttons, the dialog disappears but leaving the background opacity. The background opacity loses only when the page is reloaded.
Why does this happen with this new version? Any suggestion? In earlier versions, this was just fine.
It is associated with showEffet and hideEffect attributes of confirm dialog - from PrimeFaces Forum.
There is a misuse of effect attributes, "true" is not a valid value,
should be bounce, fade ... 4.x is more strict about wrong attribute
values

RichFaces a4j:commandButton. first click does not work the action, it works in the secon click

I have a problem that a I couldn't solve. When I click first time on a a4j:commandButton there is not action. The second and following time it works perfectly. I have read about this problem however I have not clear the solucion.
I am new, and I have find this solucion: (h:commandButton/h:commandLink does not work on first click, works only on second click) however I do not know where should I introduce the script code.
I have found this: however I think is an old jsf version:
(https://community.jboss.org/thread/165031)
And I have tried to repare it with: https://community.jboss.org/wiki/ProgrammaticControlOfPartialProcessingInRichFaces4. However, I have not been success
If someone could explain me the #BalusC solution step by step, it could be really hepful
Thanks very much:
My code is: (everything in the same file)
<ui:define name="table">
<h:form id= "formListCompanies">
<a4j:outputPanel id="tablePaneRegion">
<rich:extendedDataTable ....
<rich:column sortable="false" width="100%">
...
<a4j:commandLink id="editCmd" styleClass="no-decor" render="editGrid, editPane"
execute="#this" oncomplete="#{rich:component('editPane')}.show()">
<a4j:param value="#{it.index}" assignTo="#{myBean.currentIndex}" />
<f:setPropertyActionListener target="#{myBean.selected}" value="#{mypojo}" />
</a4j:commandLink>
....</rich:column>
....
<rich:popupPanel id="editPane" header="#{...}" domElementAttachment="body"
moveable="true" modal="true" resizeable="false" autosized="true"
onshow="focus(#{rich:component('name')});">
....
<!-- h:Inputtext ..-->
<h:panelGrid columns="2">
<a4j:commandButton value="#{'save'}" action="#{myBean.edit}"
render="dataTable" execute="editPaneRegion" />
<a4j:commandButton value="#{...}"
onclick="#{rich:component('editPane')}.hide(); return false;" />
</h:panelGrid>
</h:form>
</a4j:outputPanel>
</rich:popupPanel>
What I have already tried is to take out the h:form id= formListCompanies, and put there a h:panelgrid and a h:panelgroup
Is the problem related to the doble clicking issue? Am i in the right way?
rerender panel and form (form state lost error in jsf spec)... render="richPanelMantenimientoTipoVisualAjaxWebPart,frmMantenimientoTipoVisual"

<p:dialog appendToBody="true" doesn't call Converter class

I am using Primefaces 3.4.2 with JSF 2.0
I have the following in a dialog popup in JSF page.
<p:dialog header="Create New Request" style="font-weight:bold"
widgetVar="newDialog" resizable="false" id="newDlg"
showEffect="fade" hideEffect="fade" appendToBody="true"
modal="true" position="center top" width="850" height="450">
<p:panelGrid columns="2">
<h:outputLabel value="Employee" for="employee" />
<p:selectOneMenu id="employee" value="#{mymb.employee}"
converter="#{employeeConverter}">
<f:selectItems value="#{mymb.employeeItems}" var="emp"
itemLabel="#{emp.employeeName}" itemValue="#{emp.employeeNumber}"/>
<p:ajax listener="#{mymb.loadDepartments}" process="#this"/>
</p:selectOneMenu>
</p:panelGrid>
<p:separator />
</p:dialog>
If I use appendToBody="true", then selectOneMenu Converter class doesn't gets invoked, but if I make it appendToBody="false", then Converter class gets invoked.
What could be the reason for this? appendToBody="false" makes my popup dialog unusable, not able to navigate using mouse.
How can I resolve this issue?
Remove the appendToBody and put an <h:form/> inside your dialog(along with it's content).
The purpose of appendToBody="false" is to ensure your dialog is rendered within the body (and hence within the main <h:form/>) of the HTML output.
Without appendToBody="false" , the dialog might end up being appended to the end of the markup in <body/> and as a result, nothing inside it will get executed.
Adding <h:form/> to your dialog ensures that even if it winds up outside the <body/> it will still be able to submit to the server

Reset input fields without executing validation

I have a Facelets view as below:
<h:form id="f1">
<p:panelGrid id="p1" columns="2">
<p: inputText value="Distance Travelled::/><p:inputText value="#{airTransportUsage.distance}" immediate="true"
required="true" requiredMessage="Distance Travelled Field cannot be left blank.."
converterMessage="Distance Travelled must be a number"
validatorMessage="Distance Travelled must be a valid number.."
id="dis">
<f:validateLongRange minimum="1"/>
</p:inputText>
<p:commandButton value="Reset" action="#{airTransportUsage.reset}" update=":f1:p1" />
</p:panelGrid>
</h:form>
When the reset button is clicked, the corresponding method can never be executed due to validation. I can't use immediate="true" on my reset button as it creates some other problems.
The <p:commandButton> processes indeed by default the entire form (process="#form"), you can change this by specifying only the current component in the process attribute.
<p:commandButton value="Reset" ... process="#this" />
However, this will fail if the form is already been validated beforehand. The input fields which have been marked invalid won't be updated with the new model value (which you've resetted yourself). If you're using PrimeFaces 3.4, then embed <p:resetInput> in the button:
<p:commandButton value="Reset" ... process="#this">
<p:resetInput target="#form" />
</p:commandButton>
If you aren't on PrimeFaces 3.4 yet and can't upgrade to it, you can use OmniFaces ResetInputAjaxActionListener for this.
A completely different alternative is to just refresh the current page by a fresh new GET request.
<p:button value="Reset" />
This worked for me in PrimeFaces 5.3
<p:commandButton action="#{bean.reset()}" value="Reset" process="#this" update="#form" resetValues="true" />
You can probably replace the "#form" target of the update attribute to a specific component if you want.

Resources