1
我有一個在selectOneMenu中列出的Album實體的轉換器,如果有selectManyMenu,需要進行哪些修改才能使用它?selectManyMenu轉換器vs selectOneMenu轉換器
與selectManyMenu一起使用的轉換器的工作示例非常感謝。
轉換爲selectOneMenu用於
package converter;
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 javax.faces.convert.FacesConverter;
import javax.persistence.EntityManager;
import entities.Album;
import util.EntityUtil;
@FacesConverter("albumconverter")
public class AlbumConverter implements Converter {
EntityManager em = EntityUtil.getEntityManager();
public Object getAsObject(FacesContext context, UIComponent component, String value) {
if (value == null || value.length() == 0) {
return null;
}
Album album = em.find(
Album.class,
Long.parseLong(value));
return album;
}
public String getAsString(FacesContext context, UIComponent component, Object value) {
return value instanceof Album ?
((Album) value).getAlbumId().toString() : "";
}
}