Jump to: navigation, search

Stardust/Knowledge Base/Customization/Portal/JSFValidation

Custom error messages in JSF pages

The completeion method is invoked when a user trie sto complete an activity. This is a good point in the activity lifecycle to run validations (in addition to the regular JSF input field validations). The completeion method can throw a ValidatorException which will cause the activity completion to halt. The error message of the exception will be displayed to teh user. After correcting the invalid inputs the user can complete the activity again.

import javax.faces.application.FacesMessage;
import javax.faces.validator.ValidatorException;

public void complete() {..
if ((firstname == null) || (firstname.length() == 0)) { 
throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "empty user name", null));
}}

Validating input depending on activity target state

User can initiate several state changes when leaving the activity panel: - complete the activity - suspend the activity - suspend and save the activity

In many case it can make sense to apply a different validation logic depending on the target sate. For instance a state "suspend and save" may run a less strict validation logic that does not require all fields to be filled in while a state change to complete requires all fields to be entered correctly. The following code snippet shows how to distinguish between activity target states in the backing bean's completion method.

ActivityInstanceState state = (ActivityInstanceState)RequestContext.getCurrentInstance().getPageFlowScope().get("activityTargetState");
if (!ActivityInstanceState.Suspended.equals(state)) {...}