Hi Heath,
this is the decleration of the managed bean and the converter in the faces-config.xml


<managed-bean>
<managed-bean-name>categoryConverter</managed-bean-name>
<managed-bean-class>essex.cc403.jsf.CategoryConverter</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<converter>
<converter-for-class>essex.cc403.hbeans.Category</converter-for-class>
<converter-class>essex.cc403.jsf.CategoryConverter</converter-class>
</converter>



Heath Borders wrote:

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;
  }










Reply via email to