Values from UI not set in model in validation

UI Components for JSF
Post Reply
olpf
Posts: 84
Joined: 25 Feb 2013, 16:49
Location: GER

22 Jul 2014, 13:22

Hi,

I have a dialog in its own form which contains a dataList. With a link the user can add an item to the dataList model. This items has several fields and some required ones. When the user has created several items and clicks on button "save" of the dialog, the items have to be validated and saved. E. g. a name attribute must be unique for all created items. I tried 2 approaches:

1. assigned a validator method for the name input text (so the validation is done for each item which is not necessary but should work)
2. use inside the form <f:event listener="#{controller.validateItems}" type="postValidate" />

My problem is on both approaches that the ui values of the last element item in the list is not set in the model which is a list in the backing bean. So I cannot check uniqueness. I mentioned that the user can add an item with a link to the list, this link processes the dataList and updated the model on each click. When the user adds the last element, it seems like that the save button does not processes the dataList. I set process="@form" on the save button. Any idea?

Regards
Oliver
JBoss AS, Primefaces 5, Primefaces extensions 4.0.0

User avatar
andyba
Expert Member
Posts: 2473
Joined: 31 Mar 2011, 16:27
Location: Steinfeld, near Bremen/Osnabrück, DE
Contact:

22 Jul 2014, 14:52

You can only check for uniqueness when all values are in the model, trying to do so on the client side, while possible, is more complicated.
PF 4.x (Elite versions), PF 5, Pf 5.1, PF 6.0
Glassfish 4.1, Mojarra 2.x, Java 8, Payara 4.1.1.
If you haven't read the forum rules read them now

olpf
Posts: 84
Joined: 25 Feb 2013, 16:49
Location: GER

22 Jul 2014, 16:32

But I do not understand why it is not in the model. I process the form which contains the dataList. So I would expect that the button click updates the model. I also tried to get the values from the component tree by finding the dataList, but it is also not set. If I remember correctly, the values are only updated in the model if the validation was successful? So I have to pass all values explicitly as parameter? Do not know if this is possible?
JBoss AS, Primefaces 5, Primefaces extensions 4.0.0

olpf
Posts: 84
Joined: 25 Feb 2013, 16:49
Location: GER

22 Jul 2014, 17:15

Checked the JSF lifecycle...only successful validation updates the model values that explains the problem. In the past I sent an extra attribute to the validator if I want to validate another field additionally. I think this is too bis and dynamic in this case. Because each item has a name and a group. Names in a group must be unique for all dynamic created items. What shall I send?
JBoss AS, Primefaces 5, Primefaces extensions 4.0.0

rikup
Posts: 459
Joined: 29 Jan 2013, 14:27

23 Jul 2014, 00:03

If you want to skip validation, OmniFaces might help you: http://showcase.omnifaces.org/validators/validateBean
PrimeNG 2.0.0
Angular 2.4.5

olpf
Posts: 84
Joined: 25 Feb 2013, 16:49
Location: GER

28 Jul 2014, 09:38

I do not want to skip validation. I think the validateMultiple of omnifaces is close to a solution for my case. My problem is that the input components can be multiple. In the example of validateMultiple I have several foo, bar, baz fields and I have to check for instance all foos for uniquness. I do not know to add all component ids to the attribute "components" of validateMultiple.
JBoss AS, Primefaces 5, Primefaces extensions 4.0.0

olpf
Posts: 84
Joined: 25 Feb 2013, 16:49
Location: GER

28 Jul 2014, 09:54

Got it partly working. After the adding of a new item the existing items will validated and set to the backing bean. So I can check the uniquness for the n-1 items. The last item must be validated when the user clicks the save button. But the values are not set of the last item at this time.
JBoss AS, Primefaces 5, Primefaces extensions 4.0.0

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 33 guests