2

I am using primefaces inplace editor. (tried primefaces 3.2, 3.3, 3.4RC1, and 3.4 snapshot)

When form is submitted through non-ajax request, and some other required field in the form was not filled, then the page should reload and show the required message. But what actually happens is: Along with page-reload and requiredMessage, the inplace editor is already being shown. How to solve this problem?

Sample Code to reproduce the problem

<h:form prependId="false"> <p:inplace editor="true" widgetVar="X"> <p:inputTextarea value="#{smsAlertBean.alertText}" /> </p:inplace> </h:form> <h:form prependId="false"> <p:selectOneMenu required="true" requiredMessage="Please select"> <!-- your values --> </p:selectOneMenu> <p:commandButton value="Submit" action="#{smsAlertBean.dummyAction}" ajax="false" /> </h:form> 
5
  • I guess you can't place them all in one form ? Commented Aug 29, 2012 at 11:05
  • No I can't place them in one form. But placing them in one form still does not help. Commented Aug 29, 2012 at 11:34
  • I'm not sure if I understand "already being shown". What exactly do you mean with "already" here? Was it already shown before you submit the form? Commented Aug 29, 2012 at 11:34
  • I mean : 1 form and instead of ajax="false" do process="@form" update="@form" Commented Aug 29, 2012 at 11:38
  • Oh, it shows without user interaction when you submit the form. Commented Aug 29, 2012 at 11:40

1 Answer 1

3

I'd bet that this is a bug in <p:inplace>. From InplaceRenderer#encodeMarkup() method:

boolean validationFailed = context.isValidationFailed(); String displayStyle = validationFailed ? "none" : "inline"; String contentStyle = validationFailed ? "inline" : "none"; 

It doesn't check if the validation failure concerns "own" form and would thus always display on a validation failure, regardless of the submitted form. There's not really much you can do against this other than editing the PrimeFaces source code, creatnig a custom renderer and/or posting a bug report.

You could workaround this by manually closing the inplace editor with help of JavaScript on the widgetVar. It has a cancel() function which closes the editor.

<p:commandButton binding="#{foo}" value="Submit" action="#{smsAlertBean.dummyAction}" ajax="false" /> <h:outputScript rendered="#{param.containsKey(foo.clientId)}">X.cancel();</h:outputScript> 

(this script thus get rendered when the command button is actually pressed)

This has however only an ugly effect on slow machines/browsers. The inplace editor flashes. Consider reporting it as a bug to the PrimeFaces guys, that the InplaceRenderer should first check if the validation failure concerns own form or not.

Sign up to request clarification or add additional context in comments.

4 Comments

Already reported as bug(Please vote): code.google.com/p/primefaces/issues/…
Instead of using the cancel() function (which causes an ajax update) you can call hide().
@siebz0r: Hmm, I haven't noticed the ajax request in first place, but I observed that cancel() immediately hides, while hide() fades out very visibly. This can perhaps be tuned by providing a different and better effect and effectSpeed attribute.
cancel() calls an update to be sure to reset any input element. hide() however 'just hides'.