[jboss-user] [JBoss Seam] - Re: Custom Converter

terryb do-not-reply at jboss.com
Tue Nov 6 07:23:22 EST 2007


please let me know if need further info. my xhtml file is pretty big so I have only pasted relevent sections.

Converts class
package au.edu.tisc.session;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;

import org.jboss.seam.InterceptionType;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Create;
import org.jboss.seam.annotations.Intercept;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.core.FacesMessages;

@Name("onlineConverters")
@Scope(ScopeType.APPLICATION)
public class Converters {
	
private Converter memberSource;
	
  @Create
	public void init() {
		this.memberSource = new MemberSource();
	}
	
	
	public Converter getMemberSource() {
		return this.memberSource;
	}
	
	
	public void setMemberSource(Converter memberSource) {
		this.memberSource = memberSource;
	}
	

	@org.jboss.seam.annotations.jsf.Converter
	@Intercept(InterceptionType.NEVER)	
	public class MemberSource implements Converter {
		
		@Override
		public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String value) throws ConverterException {
			return value;
		}
		
		@Override
		public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object value) throws ConverterException {

			String convertedValue = "";
			
			if (Constant.Member.Source.ONLINE.equalsIgnoreCase((String)value)) {
				convertedValue = "Online";
			} else if (Constant.Member.Source.QTISC.equalsIgnoreCase((String)value)) {
				convertedValue = "QTISC";
			} else if (Constant.Member.Source.CURRICULUM_COUNCIL_RESULT.equalsIgnoreCase((String)value)) {
				convertedValue = "CC Year11";
			} else {
								
				FacesMessage facesMsg = new FacesMessage("Converstion error.", String.format("Invalid member status %s.", ((String) value)));
				facesMsg.setSeverity(FacesMessage.SEVERITY_ERROR);
				FacesMessages.instance().add(facesMsg);				
				throw new ConverterException(facesMsg); <-- exception thrown here...
			}
			return convertedValue;
		}
	}
}

XHTML bits
...

<h:messages id="globalMessages" globalOnly="true" layout="table" errorClass="message-error" infoClass="message-info"/>

...
<h:panelGroup>Source</h:panelGroup>
<s:span id="source"> 
    <h:outputText value="#{clientHome.instance.source}" converter="#{onlineConverters.memberSource}"></h:outputText>
</s:span>
...

Exception
21:02:36,578 ERROR [STDERR] 6/11/2007 21:02:36 com.sun.facelets.FaceletViewHandler handleRenderException
SEVERE: Error Rendering View[/client.xhtml]
javax.faces.convert.ConverterException: Converstion error.
        at au.edu.tisc.session.Converters$MemberSource.getAsString(Converters.java:64)
        at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getFormattedValue(HtmlBasicRenderer.java:469)
        at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:322)
        at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:200)
        at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:836)
        at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:279)
        at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:276)
        at com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:242)
        at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:812)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:886)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:892)
        at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:571)
        at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108)
        at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:216)
        at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
        at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
        at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:63)
        at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:57)
        at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
        at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:60)
        at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
        at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
        at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
        at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:79)
        at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
        at org.jboss.seam.web.SeamFilter.doFilter(SeamFilter.java:84)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)
        at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
        at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
        at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
        at java.lang.Thread.run(Thread.java:619)

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

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



More information about the jboss-user mailing list