Primefaces 5.1: #this ajax update not working anymore - ajax

I'm having a little application with a selectOneMenu which needs to update the selected value in the backing bean. Easy thing. I used Primefaces 4 and the code looks like this:
<p:selectOneMenu id="customersMenu"
value="#{customerController.selectedCustomer}" style="float:right"
converter="#{customerConverter}">
<p:ajax event="change" update="#this, :tabview" />
<f:selectItem itemLabel=" Kunde auswählen" itemValue="" />
<f:selectItems value="#{customerController.customers}"
var="customer" itemLabel="#{customer.name}" itemValue="#{customer}" />
</p:selectOneMenu>
With the ajax update on change the backing bean is updated correctly and a tabview is updated correctly too.
Now I replaced the primefaces4.jar with the primefaces5.jar and this is not working anymore. When checking with FireBug in Bugzilla I can see a ominous error saying: 'TypeError: PrimeFaces.Expressions is undefined'. Anyone got that too?
I played with the settings and found that the '#this' in ajax update seems to cause the error. I checked the migration guide, should be working - shouldn't it?
Anyway, I suceeded with removing '#this' and adding a ' onchange="submit();"' to my selectonemenu. The bean is now updated. I don't understand why, can anyone tell me?

Related

Updating p:dialog clears p:message which inside same dialog

Am Upgrading application from PrimeFaces 6.1 to PrimeFaces 6.2. I have <p:dialog appendTo="#(body)" id="dialog" widgetVar="widgetVar" modal="true"> with <p:message id="validation"> element inside it.
Am opening dialog using PF('widgetVar').show(). When I click p:commandButton inside dialog, doing some validation and showing message using below code,
FacesContext.getCurrentInstance().addMessage("validation", new
FacesMessage(FacesMessage.SEVERITY_ERROR, "validation error", null))
With in the same method am reopening dialog and update it with below code,
RequestContext context = RequestContext.getCurrentInstance();
context.update("dialog");
context.execute("PF('widgetVar').show();")
In PrimeFaces 6.1 its working fine and validation message getting displayed. But in PrimeFaces 6.2 validation Message not displaying in dialog. I know RequestContext is deprecated in PF 6.2. Am also tried with below code,
PrimeFaces primefaces = PrimeFaces.current();
primefaces.ajax().update("dialog");
primefaces.executeScript("PF('widgetVar').show();");
Facing same issue. I saw that message displaying and immediately its getting cleared.
But, when I remove the ajax update primefaces.ajax().update("dialog"); It's working fine.
What is the reason for this issue?

p:fileDownload not working from modal dialog (due to ajax="false")

I need to use PrimeFaces p:fileDownload from within a data-table inside a modal dialog, but due to the use of ajax="false" (else the file download won't be triggered) inside command button the dialog disappears. Do you have any clue?
<p:commandLink value="#{row.name}" ajax="false"
actionListener="#{documentsBean.fileDownloadController(row)}">
<p:fileDownload value="#{documentsBean.fileStream}" />
</p:commandLink>
Above is the command link triggering the file download and it is included inside a data-table, the data-table itself is inserted in a modal dialog. Any help appreciated.
I Tested this method and it's worked fine for me, but to make a complete answer add some code to understand if there is a problem
public void downloaddoc(FileUploadEvent file) throws FileNotFoundException, TransformerConfigurationException, TransformerException {
InputStream input = file.getFile().getInputstream();
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
setDownload(new DefaultStreamedContent(input, externalContext.getMimeType(file.getFile().getName(), file.getFile().getName()));
}
you can read more in Primefaces Web Site
Hope that helped you.

Ajax close listener for p:confirmDialog

I have a confirmDialog and I need to do some action when the dialog is canceled. I've attached that action to 'close' button, but I need to do that also when user click 'x' icon in the top corner. How to do that?
I've tried ajax listener:
<p:confirmDialog appendToBody="true">
<p:ajax event="close" onstart="myAction()"/>
</p:confirmDialog>
but I've got an error:
Unable to attach to non-ClientBehaviorHolder parent
What you want cannot be done, as in, it's not supported by JSF (not just primefaces).
The <p:confirmDialog/>is not a ClientBehaviourHolder(components that support listening for actions on the client side). You should just disable the X close button, forcing the user to click on either the Yes or No buttons. To disable the X:
<p:confirmDialog id="theDialog" closable="false"/>
Or you could spring for the <p:dialog/>, which provides support for listeners
Further reading:
<f:ajax> Unable to attach <f:ajax> to non-ClientBehaviorHolder parent

f:ajax not working on tomcat7/eclipse

I have this very simple code which works fine until I add a f:ajax tag.
Code that works:
<h:commandButton disabled="#{!feature.available}" class="featureButton"
value="#{feature.selected ? 'selected': feature.available? 'available':'unavailable'} "
style="vertical-align: top;" action="#{Bean.toggleFeature(feature)}">
</h:commandButton>
Code that doesn't work:
<h:commandButton disabled="#{!feature.available}" class="featureButton"
value="#{feature.selected ? 'selected': feature.available? 'available':'unavailable'} "
style="vertical-align: top;" action="#{Bean.toggleFeature(feature)}">
<f:ajax event="click" />
</h:commandButton>
As far as I can tell the jsf.js file is loaded fine, this is automatically added by the facelet servlet to the head of my rendered document
<script type="text/javascript" src="/www/javax.faces.resource/jsf.js.xhtml?ln=javax.faces"></script> and I was even able to do a jsf.ajax.request directly from javascript and got the page to rerender something.
I am using mojarra 2.1.13, tomcat 7, eclipse juno, java 7.
Any thoughts on what I might be doing wrong or how I might be able to troubleshoot this issue? debugging it in javascript didn't help at all.
Thanks.
I failed to mention above that I had nested ui:repeats and it turns out there is a bug with mojarra regarding that. As far as I can tell the fix has just been committed but it isn't out as a jar yet however I tried myfaces and it worked fine, so I'll do that for now. Here are the bug details:
http://java.net/jira/browse/JAVASERVERFACES-1817

java.lang.IllegalArgumentException: "" when carriage return present in ajax render attribute

I have this line of code in my application:
<f:ajax event="click"
render="#{ULInvestmentPatternUI.premiumForm}
fundstable btnModify btnSave"
The section of code is in a h:commandButton in an .xhtml file.
When I run the code locally and click on the button I get this error message showing up in my console in Eclipse :
SEVERE: java.lang.IllegalArgumentException: ""
and the buttons which are supposed to update (become enabled) don't.
I've narrowed down the problem to the line wrapping in the render attribute:
render="#{ULInvestmentPatternUI.premiumForm}
fundstable btnModify btnSave"
If this is all on one line (no carriage return between #{ULInvestmentPatternUI.premiumForm} and fundstable) then the SEVERE: java.lang.IllegalArgumentException: "" message is not displayed in the console. The relevent buttons on the page still do not update though.
I'm new to the development team that I am in. All the other developers in the team are using the same code and it is working fine for them. I've checked to make sure that my environment is set up the same as everyone else in the team, and everything seems exactly the same.
Can anyone suggest anything please ?
Thanks,
Trish.

Resources