Is your category converter a session bean?

On Fri, 18 Mar 2005 14:17:16 +0000, Kostas Karadamoglou
<[EMAIL PROTECTED]> wrote:
> Hi again!!!
> 
> I have another problem now, Very strange Can you suggest me a solution?
> 
> I created a converter for objects of type Category in order to display
> some Category beans in a selectOneMenu tag.
> 
> I have debuged the application and I noticed a strange behaviour of JSF
> which I cannot understand.
> Below I have the sequence explanation of the problem and the content of
> each method and jsp fragment.
> 
> 1)The getAsString method works perfectly and returns the following
> strings "0","1","2","3","4","5","6","7"
> 
> 2)The page is displayed properly, and I choose from the drop down menu a
> category.
> 
> 2)Afterwords JSF invokes getAsObject (I think for the chosen option)
> with the str parameter null !!!!!!!
> In this situation I return a null object (which is wrong).
> 
> 4)After that  when the page is redisplayed the getAsString throw an
> Exception because of the null value
> 
> JSP-------------------------------------------------------
>    <h:selectOneMenu id="selectCategory"
> converter="#{categoryConverter}" value="#{eventHandler.selectedCategory}">
>        <f:selectItems id="allCategories"
> value="#{eventHandler.allCategories}"/>
>    </h:selectOneMenu>
> 
> getAsString------------------------------------------------
> 
>    public String getAsString(FacesContext facesContext, UIComponent
> uIComponent, Object obj) throws ConverterException {
>        String retValue=null;
>        if(obj==null)
>            throw new ConverterException("not null object of type
> Category expected");
>        else if(obj instanceof Category){
>            Category category=(Category)obj;
>            map.put(new Integer(category.getId()), category);
>            retValue=String.valueOf(category.getId());
>        }else{
>            throw new ConverterException("object of type Category
> expected received: "+obj.getClass().getName()+"="+obj.toString());
>        }
>        return retValue;
>    }
> 
> getAsObject------------------------------------------------
> 
>     public Object getAsObject(FacesContext facesContext, UIComponent
> uIComponent, String str) throws ConverterException {
>        Category retValue=null;
>        if(str!=null){
>            try{
>                System.out.println(str);
>                Integer id=Integer.valueOf(str);
>                retValue=(Category)map.get(id);
>            }catch(Exception ex){
>                throw new ConverterException("a number formatted string
> expected");
>            }
> 
>        }else{
>            //throw new ConverterException("a not null string expected");
>            return null;
>        }
>        return retValue;
>    }
> 


-- 
-Heath Borders-Wing
[EMAIL PROTECTED]

Reply via email to