I liked your solution because it would allow me to use the manage-properties as managed properties of converters .  However dug a little deeper into the UIComponent that is passed to getAsObject and get what I needed HtmlSelectOneMenu -> UISelectItems -> SelectItem -> the object -> the object's name .  Attached is the code.

Dennis Byrne
        public static String getClassNameByUISelectItems(UISelectItems 
uISelectItems){
                List selectedItemsList ;
                SelectItem selectItem ;
                String className = null;
                
                selectedItemsList = (List)uISelectItems.getValue();
                for(int i = 0 ; i < selectedItemsList.size(); i++){
                        selectItem = (SelectItem)selectedItemsList.get(i);
                        if(className == null){
                                className = 
selectItem.getValue().getClass().getName();
                        }else{
                                if(! 
className.equals(selectItem.getValue().getClass().getName())){
                                        // this means there are SelectItems 
wrapping more than one type
                                        // of object ... the dynamic converter 
cannot perform magic!!
                                        throw new ConverterException();
                                }
                        }
                }
                return className;
        }
        
        public static String getClassNameByUIComponent(UIComponent uIComponent){
                Iterator iterator ;
                Object child ;
                UISelectItems uISelectItems ;
                
                if(uIComponent instanceof HtmlSelectOneMenu){
                        for(iterator = uIComponent.getChildren().iterator(); 
iterator.hasNext();){
                                child = iterator.next();
                                if(child instanceof UISelectItems){
                                        uISelectItems = (UISelectItems)child;
                                        return 
getClassNameByUISelectItems(uISelectItems);
                                }
                        }
                }
                return null;
        }
          
        public Object getAsObject(FacesContext arg0, UIComponent uIComponent, 
String id)
                        throws ConverterException {
                String shortName ; 
                String identifier;
                MappingUtilImpl mappingUtil;
                String hql ;
                Object object;
                String className;
                
                className = getClassNameByUIComponent(uIComponent);
                mappingUtil = (MappingUtilImpl)BackingUtil.getMappingUtil();
                shortName = MappingUtilImpl.getClassNameByClassType(className); 
                identifier = mappingUtil.getPkPropertyByClassType(className);
                hql = "FROM " + shortName + " AS a WHERE a." + identifier + " = 
'" + id + "'";
                try {
                        object = HibernateTool.get(hql);
                        return object;
                } catch (PersistenceException e) {
                        e.printStackTrace();
                        throw new ConverterException();
                }
        }=

Reply via email to