[jboss-user] [JBoss Seam] - Re: Writing a custom converter which wraps EntityConverter

Newlukai do-not-reply at jboss.com
Fri Jun 15 10:16:23 EDT 2007


Thanks. I've it implemented this way:

public class SeverityConverter implements Converter {
  | 	public Object getAsObject(FacesContext context, UIComponent component, String value) throws ConverterException {
  | 		Converter entityConverter = (Converter) Component.getInstance("org.jboss.seam.ui.entityConverter");
  | 		
  | 		if(NoSelectionConverter.NO_SELECTION_VALUE.equals(value)) {
  | 			return entityConverter.getAsObject(context, component, value);
  | 		}
  | 
  | 		int severity = Integer.parseInt(value);
  | 		if(severity >= 0) {
  | 			return entityConverter.getAsObject(context, component, value);
  | 		}
  | 		
  | 		return AdditionalSeverities.getSeverityByID(severity);
  | 	}
  | 
  | 	public String getAsString(FacesContext context, UIComponent component, Object value) throws ConverterException {
  | 		Converter entityConverter = (Converter) Component.getInstance("org.jboss.seam.ui.entityConverter");
  | 		Severityclass severity = (Severityclass) value;
  | 		
  | 		if(severity == null || severity.getID() >= 0) {
  | 			return entityConverter.getAsString(context, component, value);
  | 		}
  | 		
  | 		return String.valueOf(severity.getID());
  | 	}
  | }

I'm wondering if the way I get the EntityConverter is OK or if there's a more elegant way.

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

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



More information about the jboss-user mailing list