All pastes #72391 Raw Edit

Unnamed

public text v1 · immutable
#72391 ·published 2006-06-26 20:22 UTC
rendered paste body
package com.loomis.jsf.component.keystrokevalidatedinput;

import java.io.IOException;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.el.MethodBinding;

import org.apache.myfaces.custom.ajax.api.AjaxRenderer;
import org.apache.myfaces.renderkit.html.ext.HtmlTextRenderer;
import org.apache.myfaces.renderkit.html.util.AddResource;
import org.apache.myfaces.renderkit.html.util.AddResourceFactory;
import org.apache.myfaces.shared_tomahawk.renderkit.JSFAttr;

public class KeyStrokeValidatedInputRenderer extends HtmlTextRenderer implements AjaxRenderer {
	
	
	public String getErrorMessageHTML(FacesContext context, UIComponent component) {
		KeyStrokeValidatedInput ksv = (KeyStrokeValidatedInput) component;
		Boolean ajaxEnabled = ksv.getAjaxEnabled();
		MethodBinding mb = ksv.getValidatorMethod();
		
		if (mb == null || !ajaxEnabled) return "";
		
		
		return "";
	}
	
	private void encodeJavascript(FacesContext context, UIComponent component) {
		KeyStrokeValidatedInput ksvi = (KeyStrokeValidatedInput) component;
		Boolean ajaxEnabled = ksvi.getAjaxEnabled();
		MethodBinding mb = ksvi.getValidatorMethod();
        String javascriptLocation = (String)component.getAttributes().get(JSFAttr.JAVASCRIPT_LOCATION);

		if (ajaxEnabled) {
			//DojoUtils.addMainInclude(context, component, javascriptLocation, new DojoConfig());
		} else {
			AddResource addResource = AddResourceFactory.getInstance(context);
			
			addResource.addJavaScriptToBodyTag(context, 
					component.getId() + "_" + mb.getExpressionString(),
					mb.invoke(context, new Object[] {ksvi}).toString());
		}
	}

	public void encodeAjax(FacesContext context, UIComponent component) throws IOException {
		
	}
	
	public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
		super.encodeEnd(context, component);
	}
	
	public void decode(FacesContext context, UIComponent uiComponent) {
		super.decode(context, uiComponent);
	}
}