Document form validator: get mode

I have a field validator method which needs to be able to distinguish between layout modes of “create” and “edit”, and do slightly different validation in those cases.

The best solution I have managed to find looks like this:

public void validateMyField(FacesContext context, UIComponent component, Object value) {
  boolean isCreateMode = 
    (context.getExternalContext().getRequestParameterMap().get("document_create") != null);

  if (isCreateMode)
    //...validation A...
  else
    //...validation B...

}

This lookup seems somewhat fragile; is there a better approach? I thought about creating two different validator methods for create and edit, but when the layout is in “create” or “edit” mode, the widget is always in “edit” mode, so I can only define the one validator.

0 votes

0 answers

1408 views

ANSWER