Intermediate Custom Input Validation: Failover during PROCESS_VALIDATIONS phase


Code 1 - FooBean.java

package com.ibm.xsp.beans;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.ValidatorException;

/*
 * @author Tony McGuckin, IBM
 */
public class FooBean { 
	
	public FooBean(){}
	
	//------------------------------------------------------------------------
	
	public void validate(FacesContext context, UIComponent component, Object submittedValue)
		throws ValidatorException {
		String sv = (String)submittedValue;
		if(null != sv && sv.length() > 3){
			String msgStr = "way too long!";
			FacesMessage msgObj = new FacesMessage(FacesMessage.SEVERITY_ERROR, msgStr, msgStr);
			throw new ValidatorException(msgObj);
		}
	}
	
	//------------------------------------------------------------------------
	
} // end FooBean


Code 2 - faces-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<faces-config>
	<managed-bean>
		<managed-bean-name>fooBean</managed-bean-name>
		<managed-bean-class>com.ibm.xsp.beans.FooBean</managed-bean-class>
		<managed-bean-scope>request</managed-bean-scope>
	</managed-bean>
</faces-config>


Code 3 - XSP Markup

<xp:inputText id="inputText3" validator="#{fooBean.validate}"></xp:inputText>
<xp:message id="message3" for="inputText3"></xp:message>

All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.
No comments yetLogin first to comment...