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

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?

Related

Orbeon Form - reCAPTCHA Field required error after submitting form

I'm struggling to make reCAPTCHA work in my Orbeon form.
I'm using ORBEON 2018.2.3.201905172253 PE within SAP Commerce (Hybris).
After submitting the form, I get the error "Please check your answer to the CAPTCHA challenge" even though the captcha is correct.
Created a common Form and added reCAPTCHA as per official Orbeon documentation: https://doc.orbeon.com/form-runner/component/captcha
Added my private and public keys to the properties file
Added the reCAPTCHA property to my form:
<property
as="xs:string"
name="oxf.fr.detail.captcha.yforms.myForm"
value="reCAPTCHA"/>
This is the process executed when clicking the SUBMIT button:
<property as="xs:string" name="oxf.fr.detail.process.save-final.yforms.myForm">
validate-all
then save
then send(
uri = "https://myurl",
method = "PUT"
)
then navigate(uri = "https://myurl")
</property>
I see the reCAPTCHA at the bottom of my form as expected
When I click SUBMIT after filling up the form and completing the captcha successfully, I see a popup saying "There are validation errors. Please retry once all fields have been properly filled-out."
And the form displays this error for the captcha field:
"Please check your answer to the CAPTCHA challenge."
So I'm clearly missing something. I know there are some configurations needed for the fr-verify-done and fr-verify-error to be added, but the Orbeon documentation does not specify how to configure those through PROPERTIES. They only say how to add those event listeners while adding the captcha component by hand (editing the source code of the form through Form Builder).
Things that I tried and didn't work:
Dispatching an fr-verify event when submitting:
xf:dispatch(name = "fr-verify", targetid = "captcha")
then validate-all
then save
then send(
uri = "https://myurl",
method = "PUT"
)
then navigate(uri = "https://myurl")
Adding the reCAPTCHA component to the form source code as per Orbeon documentation:
<fr:recaptcha id="my-captcha">
<xf:send ev:event="fr-verify-done" submission="save-submission"/>
<xf:action ev:event="fr-verify-error">
<xf:toggle case="failure-case"/>
<xf:dispatch target="my-captcha" name="fr-reload"/>
</xf:action>
</fr:recaptcha>
When I click SAVE after adding the excerpt above, the Form Builder crashes. Same happens if I try to add the same excerpt to a form through the online demo form builder provided by Orbeon : https://demo.orbeon.com/demo/fr/orbeon/builder/new
That is super weird since I'm adding code provided by them using the online last version of the form builder, and it still crashes when trying to save it. So that makes me think the problem I have is not related to my platform, but with Orbeon itself.
This is the error I get in the online demo for Form Builder after adding the recaptcha excerpt to the source code of the form: "Cannot read property 'call' of undefined'
There're no relevant LOGS that I can provide, I activated debug level logs for Orbeon and I'm not getting any useful info.
I would really appreciate if someone can guide me through with either:
- Configuring the fr-verify events without changing the source code of the form using Form Builder, OR
- Adding the reCAPTCHA component through Form Builder successfully without making it crash, OR
- Anything you can come up with to make my form with captcha work
Thanks in advance,
David
SAP Hybris 6.6 includes Orbeon Forms 2017.1.1, which uses Google's reCAPTCHA 1, which Google doesn't support anymore. Your options are either:
To upgrade to a version of SAP Hybris that includes Orbeon Forms 2018.1 or 2017.2.2 or newer (those version use Google's reCAPTCHA 2).
To use the SimpleCaptcha instead of reCAPTCHA.

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

Why a View is reinstancied, when we click a commandButton displayed in richfaces component displayed after an ajax call?

Initially my question was : Does richfaces 4.3.4 support JSF 2.2 and ViewScoped?
But now the question is in the title.Thanks :)
I'm trying to solve this problem. Why a View is reinstancied, when you click a command button displayed in richfaces component displayed after an ajax call ?
It seems i'm not alone : [anotherLink], anotherlink 2.
Resolve thanks to this.
Thanks BalusC.
EDIT : But it's no more working when you try to add an rich:fileupload neither with h:inputFile... It will displayed strange html code in a newly textarea ....It's weird...
<rich:fileUpload id="upload" fileUploadListener="#{analyse.test}" acceptedTypes="bam,pdf,png" ontyperejected="alert('Seulement les fichiers avec l'extension bam et pdf sont acceptés.');" maxFilesQuantity="3">
                 <a4j:ajax event="uploadcomplete" execute="#none" render="upload" />
</rich:fileUpload>

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