I have a highly dynamic single page interface where various user events trigger new fields to display on the screen. I am using jsf 1.1 and basic ajax without the ability to use partial submit. Because of these limitations I have marked all of my fields required false and immediate false. The idea is to validate ONLY when the user attempts to transition to the next page in an action method NOT when they tab off and execute an ajax event. I set immediate false because I need input to make it to the modal so I can conditionally render certain fields based on business logic.
PROBLEM: I know ahead of time a list of "possible" UIInput ids which may or may not be displayed on the screen at any given time. My goal is to iterate through all these UIInputs, check to see if they are rendered, not null, and not empty otherwise mark the UIInput in error.
This works except for fields which are not displayed on the screen. For example, I have a field "amountInput" which has an XHTML rendered property set to false so it does not show up on the screen. From a display perspective, this works, but upon invoking my action, this field is still showing its rendered property as true so I have no way to know whether I should validate it or not.
What are my options here?
public boolean validate() {
boolean hasValidMinimumData = true;
final List<UIInput> componentList = getComponentList();
if (CollectionUtils.isNotEmpty(componentList)) {
for (UIInput curComponent : componentList) {
final Object curComponentValue = curComponent.getValue();
if (curComponent.isRendered() && (curComponentValue == null || isNoValue(curComponent))) {
setError(curComponent); // applies the error
hasValidMinimumData = false;
}
}
}
return hasValidMinimumData;
}