1

I'm currently developing a dynamic form system and have to implement a feature, where users (who set which form fields should be displayed from some predefined fields) must have the ability to define which input fields are required and which not. There also has to be the possibility to set the following: "Field A and B should be displayed. You need to fill out at least one of them (A or B, or if you want A and B) to submit the form."

I have stored following data:

0: not displayed
1: displayed
2: displayed and required (w/o any dependency to another field)
greater than 1: Custom identifier

Example:

name: 1
birthday: 2
city: 2
x: 3
y: 3
postal code: 0

With that setting the user has to fill out the name, either birthday or city and either x or y.

Does JSF support that kind of a "required" field?

Regards

Thomas Schmidt
  • 1,248
  • 2
  • 12
  • 37
  • 1
    possible duplicate of [JSF2.0 doesn't support cross-field validation, is there a workaround?](http://stackoverflow.com/questions/6282466/jsf2-0-doesnt-support-cross-field-validation-is-there-a-workaround) – kolossus Nov 05 '14 at 14:34

2 Answers2

2

From the documentation of primefaces 4.0 (http://www.primefaces.org/docs/vdl/4.0/primefaces-p/inputText.html), the attribute required accepts a javax.el.ValueExpression which must evaluate to java.lang.Boolean.

My understanding would lead to create a backbean function which would return a Boolean, and use your own logic to determine whether it's true or false (taking in account the user setting and the current element).

Thrax
  • 1,926
  • 1
  • 17
  • 32
  • I can't determine if a field is required or not. Example: "Field A and B should be displayed. You need to fill out at least one of them (A or B, or if you want A and B) to submit the form." - You can choose your own if you fill out A *OR* B – Thomas Schmidt Nov 04 '14 at 15:37
0

No, this kind of cross field validation is not available out of the box. You need to achieve this by custom validation.

siva636
  • 16,109
  • 23
  • 97
  • 135