[jboss-user] [JBoss Seam] - Re: convertEntity not working with a4j:support

jrwsampson do-not-reply at jboss.com
Thu Jan 3 10:55:06 EST 2008


I ended up defining a custom converter for the object, which appears to be doing its job correctly. The problem it still does not bind the selected items to the list in the h:selectManyListbox's value attribute. This appears to happen when I use s:convertEntity (or a custom converter) in conjunction with a4j:support. If I remove the converter, I do get a list of Strings bound to the value attribute... but this doesn't really help me. What is going on here?

My xhtml:

  | 	   	<h:selectManyListbox value="#{campaignSelector.selectedAdvertisers}" converter="genericEntityConverter">
  | 			<s:selectItems value="#{campaignSelector.availableAdvertisers}" var="advertiser" label="#{advertiser.name}" />
  | 			<a4j:support event="onchange" reRender="campaignSelector" />
  | 		</h:selectManyListbox>
  | 

My converter:

  | //This converter can be used for entities extending ConvertibleEntity
  | @Name("genericEntityConverter")
  | @Scope(org.jboss.seam.ScopeType.APPLICATION)
  | @org.jboss.seam.annotations.faces.Converter(id="genericEntityConverter")
  | public class GenericEntityConverter implements Converter {
  | 
  | 	@In
  | 	private EntityManager entityManager;
  | 
  | 	public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String entityId) throws ConverterException {
  | 		String[] strings = entityId.split("@");
  | 		if(strings.length == 2) {
  | 			
  | 			String tableName = strings[0];
  | 			Integer id = Integer.valueOf(strings[1]);
  | 			String query = "from " + tableName + " where id=:id";
  | 			Object entity = (Object) entityManager.createQuery(query).setParameter("id", id).getSingleResult();
  | 			return entity;
  | 		} else {
  | 			throw new ConverterException("The converter could not get the object associated with the id: " + entityId);
  | 		}
  | 	}
  | 
  | 	public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object object) {
  | 		ConvertibleEntity entity = (ConvertibleEntity) object;
  | 		return entity.getEntityId();
  | 	}
  | 	
  | 
  | }
  | 
  | public abstract class ConvertibleEntity {
  | 	public abstract String getEntityId();
  | 	public abstract String getEntityName();
  | }
  | 
  | //example of ConvertibleEntity implementation
  | 	@Transient
  | 	public String getEntityId() {
  | 		return "Advertiser@" + this.getId().toString();
  | 	}
  | 
  | 	@Transient
  | 	public String getEntityName() {
  | 		return "Advertiser";
  | 	}
  | 
  | 


I have stepped through in the debugger, and the converter's getAsObject method is being called and getting the Object from the EM... but when I get into the getAvailableCampaigns method on the action bean, the selectedAdvertisers list is still empty... what is going on here?

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

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



More information about the jboss-user mailing list