On 10/04/07, Marko Asplund wrote:
... My current approach is based on doing most of the work on the server side. When a user clicks a select item picker icon next to a text field the whole input form gets submitted. There's a special request parameter that is included in the request to signal that "required" validation should be skipped (similar to how the Optional Validation Framework works). The response view includes a Javascript onload ...
After losing some sleep over maintainability issues i came up with an approach that i think is a bit closer to the "jsf mainstream". One reason i originally wanted to try and abuse the "required" attribute was that i have a custom HtmlOutputLabel that is attached to input components. The label outputs a '*' character next to required fields to indicate mandatory fields to the user. It also outputs the label text in red when validation fails for a component. The "required" attribute provided an easy way to attach metadata to a component and make it available also outside the component, without having to extend each component class, something i wanted to avoid. I realized that in my case the standard JSF UIParameter component can be used to carry metadata for a component. So now i add a UIParameter to a component to indicate that it is required like this: UIParameter param = (UIParameter)app.createComponent(UIParameter.COMPONENT_TYPE); param.setName(REQUIRED_COMPONENT_PARAMETER_NAME); param.setValue(Boolean.TRUE); comp.getChildren().add(param); The custom label component is then able to check all the direct descendents of its "for" component to see if the "for" component is required. Actual validation is done in the application-level. All the input components are programmatically bound to a map. There's another map that contains the model value objects that back the inputs. The application code calls the validation method which iterates through the model objects. The model objects have the key with which the corresponding components are looked up from the component map. If a required component is missing a value, the corresponding component is looked up and set as invalid. If one or more mandatory fields have missing missing values, application level processing is terminated. marko

