I have a problem showing a dialog when I try to do a test in the oncomplete
attribute.
But when I refresh the page it worked fine, and I have to refresh on each change of the variable in the backing bean.
Even if I show the dialog without test it worked to.
The problem is in debug mode. JSF doesn't call get
when I test after the action was invoked.
<p:commandButton value="#{msg.LABEL_ADD}"
action="#{axeBean.calculer}"
style="width:100px;"
update="msgs"
oncomplete="if(#{axeBean.formvalide}) PF('dialog').show()" />
formvalide
is a boolean
.
How can I solve this issue?
I still believe the core of the question should be solved by the applying the answer on the question I've marked as duplicate. As you are running into several issues, I'll give you some pointers here.
PrimeFaces
oncomplete
doesn't refresh the variable on test ... But when I refresh the page it worked fine.
Your button is obviously rendered before you can click on it. So the oncomplete
attribute was also rendered. It is not dynamic. So it will not be reevaluated when the action is invoked.
If you need to access #{axeBean.formvalide}
in some JavaScript call, use it as the value of a hidden input, and update the input after you invoke the action. Now you can get it using document.getElementById('hiddenInputsClientId').value
.
See also:
I have a problem showing a dialog when I try to do a test in the
oncomplete
attribute.
You don't need to expose your own validationFailed
. PrimeFaces will give you an args
object in the oncomplete
function, which contains a validationFailed
property if the validation failed. So just use:
oncomplete="if (args && !args.validationFailed) PF('dialog').show()"
See also:
validationFailed
worked just with required and client side validation, but I want to validate something in backing...
Just do the checks you need to do in your action. If your custom validation failed, you can set a flag in the Faces context:
FacesContext.getCurrentInstance().validationFailed();
If you need to set an error message, use:
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "message", null);
FacesContext.getCurrentInstance().addMessage("clientId", message);
Here you can use null
as clientId
to set a global message.
If you are using OmniFaces, you can simply use:
Faces.validationFailed();
Messages.addError("clientId", "message");
See also:
I'm not sure what the check is you are doing... It might be that you are better of by creating a custom validator. See: