Strange behavior when updating form inside a dialog

UI Components for JSF
Post Reply
robert.m
Posts: 226
Joined: 07 Dec 2010, 22:52
Location: Salzburg/Austria

28 Apr 2011, 16:32

Hello everybody,

I just came across a very strange problem. If anybody has a suggestion please let me know, I'm rather desperate as i already spent some hours figuring out why this is happening! Thanks in advance!
Best regards,
Robert

Situation:
I have a dialog to create a new object - let's say a Person.
So the dialog has a form in it and some <h:inputText> (or <p:inputText>, leads to the same problem). Some of the textfields are required, therefore when no value is entered into one of them, the validation fails, the dialog stays open and the usual validation-errormessages are displayed.

The dialog is opened using a <p:commandButton> which has update="newPersonForm" and oncomplete="newPersonDialog.show();".

The value of the Person comes from a Backing-Bean "newPersonBean" which has scope session or request (has the same behavior... I even tried the conversation scopes of myfaces orchestra). An empty person object is created either inside the constructor (when using the request scope) or inside the getPerson-Method if the person-object is null. The person object is set to null every time the dialog is closed.

Expected Behavior:
Now what should happen is that every time the dialog is closed, the person-object inside the newPersonBean is et to null. When the dialog is opened, all textfields should be empty and should have no error-formatting (which they have when using 3.0.M1 as far as I noticed).

Problem:
Then i open the dialog for the first time, everything is fine, the inputfields are empty and if I enter valid data and submit the form, everything works as expected.
However, if i open the dialog, then enter some data into one inputfield and submitting the data, the validation kicks in and displays the messages. Now when i close the dialog, the person-object in the backing bean is set to null (I checked using the debugger). When I open the dialog again, there is still the value i entered before inside the inputfield.

This seems to happen only to inputfields, because when a <h:outputText> is located inside the dialog with the same value as the inputField (eg. #{newPersonBean.person.firstName}) the outputText is empty while the inoutText still has the value. I even debugged inside the getFirstName method of the Person-Class to see which value it has right when the dialog opens and it is null(!). But afterwards a value is shown.

Code:
NewPersonBean: http://pastebin.com/BimY8RRL
CommandButton and Dialog: http://pastebin.com/tsdZmuRf

Environment:
PrimeFaces 2.2.1 or 3.0.M1
Mojarra 2.0.4
Spring 3.0.x
Tomcat 7.0.x or 6.0.x

Jenks
Posts: 4
Joined: 26 Jul 2011, 14:05

14 Sep 2011, 15:34

Hi Robert. I´m having the same issue here.
Have you come to a solution for it?

Does anyone know how to solve this?

borkert
Posts: 21
Joined: 12 Sep 2011, 12:27

14 Sep 2011, 19:29

I guess the update="newPersonForm" of the "New person" button fails, because the button is outside the form. Try update=":newPersonForm" instead to reference it absolutely.

And the button needs to be inside a form too. Not the one of the dialog, just put it into its own form.
jetty-6.1.9 / Mojarra 2.1.3 / PrimeFaces 3.3.1

Jenks
Posts: 4
Joined: 26 Jul 2011, 14:05

14 Sep 2011, 19:58

Well, at least in my case i have the commandbutton that does the update inside a form and I am updating the form.

What is weird is that when i bring a new object into the form (like when I click in a row in a datatable and want to edit the attributes from the object in that row), the inputText fields that have required="true" come filled right, but the required="false" fields come wrong (and when I say wrong, I mean that it comes with the values from the last object).

rasman
Posts: 12
Joined: 12 Jun 2011, 00:36

15 Sep 2011, 00:23

Hi

I too have been having this same problem and have been trying to figure it out for the past two days.

Yesterday I came across viewtopic.php?f=3&t=11389&hilit=dialog+open&start=20, from earlier this year, which appears to be the same issue. There is no solution documented in that post either, but in the first post on this link Alex mentions ends with "ill post into the enterprise board to ask cagatay for support in this". I posted a reply today wondering if there was any solution from the enterprise board.

In my own testing I actually noticed that required fields were being overwritten by previous values when loading an existing instance of an object from say a list or a table, where the previous instance of the dialog had validation errors with data partially supplied in fields regardless of whether they were required or not.
Rasman
Primefaces 3.3.1.M3, Mojarra 2.1.3, SEAM Faces 3.0.2.Final, JBoss AS 7.0.Final

rasman
Posts: 12
Joined: 12 Jun 2011, 00:36

15 Sep 2011, 12:05

Hi

I think I have found the solution, with thanks to the author of the topic at http://www.coderanch.com/t/491486/JSF/j ... nException. In the third post of the topic there is a link to https://cwiki.apache.org/confluence/dis ... Components which explains what is going on and provides possible solutions.

I have implemented the solution under the heading of Delete Components Holding Unwanted State in this discussion and so far my testing has shown it to work. If anyone can think of a reason why we should not do this I would be grateful.

Example solution for the Dialog as I have implemented it:

Code: Select all

@Named
@ViewScoped
public class TestBean implements Serializable {
	....

	public void close(CloseEvent event) {
		event.getComponent().getChildren().clear();
	}

	....
}
on page

Code: Select all

<p:dialog widgetVar="testWidget" ... >
	<h:form>
		......
		<p:commandButton value="Cancel" update="frmGrowl" onclick="testWidget.hide();" type="button"/>
	</h:form>
	<p:ajax event="close" listener="#{testBean.close}" update="individualsDTbl" process="@this"/>
</p:dialog>
Hope that helps.
Rasman
Primefaces 3.3.1.M3, Mojarra 2.1.3, SEAM Faces 3.0.2.Final, JBoss AS 7.0.Final

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 27 guests