[jboss-user] [JBoss Seam] - Re: selectItems - Is it possible?
IGx89
do-not-reply at jboss.com
Fri Oct 26 17:07:04 EDT 2007
How's this look?
@Name("org.jboss.seam.ui.ObjectConverter")
| @Scope(PAGE)
| @Install
| @Converter(forClass=Object.class)
| @BypassInterceptors
| public class ObjectConverter implements javax.faces.convert.Converter, Serializable {
|
| private Map<String, Object> objects;
|
| @Create
| public void create() {
| objects = new HashMap<String, Object>();
| }
|
| public String getAsString(FacesContext facesContext, UIComponent cmp, Object value) throws ConverterException {
| if(value == null)
| return null;
|
| for(Map.Entry<String,Object> entry: objects.entrySet())
| if(entry.getValue() == value)
| return entry.getKey();
|
| if(facesContext.getApplication().getStateManager().isSavingStateInClient(facesContext)
| && Seam.isEntityClass(value.getClass()))
| throw new ConverterException("ObjectConverter is unable to handle entity classes when client-side " +
| "state saving is enabled. Please use EntityConverter instead, or enable server-side state saving");
|
| String key = new UID().toString();
| objects.put(key, value);
|
| return key;
| }
|
| public Object getAsObject(FacesContext facesContext, UIComponent cmp, String key) throws ConverterException {
| if (key == null)
| return null;
|
| return objects.get(key);
| }
|
| }
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4099497#4099497
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4099497
More information about the jboss-user
mailing list