[jboss-user] [JBoss Seam] - Re: Boolean to integer customconverter!!

archana_mannepalli do-not-reply at jboss.com
Mon Feb 4 00:24:00 EST 2008


hi This is my class

package org.domain.Portal.entity;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.ConverterException;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.faces.Converter;
import org.jboss.seam.annotations.intercept.BypassInterceptors;
import org.jboss.seam.log.Log;


@Name("tst")
@Scope(ScopeType.SESSION)
@BypassInterceptors
@Converter

public  class Tst extends com.sun.faces.renderkit.html_basic.CheckboxRenderer implements javax.faces.convert.Converter {

	 @Logger private Log log;
		
	 public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) throws ConverterException  {
		 try {
		log.warn("MyConverter.getAsObject action called");
		return (arg2 == null || arg2.equals("") || arg2.equals("0") ||  arg2.equals("false") ? new Integer(0) : new Integer(1));
		 } catch (Exception e) {
				throw new ConverterException(e);
			}
	}

	public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) throws ConverterException {
		 try {
			
		log.warn("MyConverter.getAsString action called: "+arg2);
		
		if (arg2 instanceof Boolean)
		
		{
			log.warn("if getAsString action called"+arg2);
			return (arg2 == null || ((Boolean)arg2).equals(false) ? "0" :"1");
		
		}
		else{
			log.warn("else getAsString action called"+arg2);
			return (arg2 == null || ((Integer)arg2).intValue() == 0 ? "0" : "1");
			
		}
	} catch (Exception e) {
		throw new ConverterException(e);
	}
	

	}

  


}	

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4125991#4125991

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4125991



More information about the jboss-user mailing list