2 Replies Latest reply on Mar 28, 2008 4:01 AM by Laurent Parcet

    Problem whith SelectOneMenu - selected

    Laurent Parcet Newbie

      Hi all.

      I have a problem with <f:selectOneMenu> when i have a selected value, it is never selected in my page.

      Here is my page code:

      <s:decorate id="typeMouvement" template="../../layout/edit.xhtml">
       <ui:define name="selectOneMenu">
       <h:selectOneMenu id="listTypeMouvement" value="#{ecr_cta_1.myNaturePiece}" converter="#{ecr_cta_1.natureConverter}" rendered="#{ecr_cta_1.editMode}" required="#{ecr_cta_1.editMode}">
       <f:selectItem itemLabel=""/>
       <f:selectItems value="#{ecr_cta_1.natureConverter.content}"/>
       </h:selectOneMenu>
       </ui:define>
       </s:decorate>
      


      Here is my converterFacory code:
      public MapConverter getConverter(IrCompagnie myCompagnie, final String theConvertedClassName)
       throws ConverterException
       {
       MapConverter theConverter = null;
       try
       {
       theConverter = converterFactory.getConverter(myCompagnie, theConvertedClassName);
       }


      here is the code of the MapConverter class
      public class MapConverter implements Converter
      {
      
       @Logger
       Log log = Logging.getLog(MapConverter.class);
      
       /** The content. */
       private final Map<String, DatabaseObject> content;
      
       /**
       * Gets the content.
       *
       * @return the content
       */
       public Map<String, DatabaseObject> getContent()
       {
       return content;
       }
      
       /**
       * Instantiate a new map converter.
       *
       * @param content
       * the content
       */
       public MapConverter(final Map<String, DatabaseObject> content)
       {
       super();
       this.content = content;
       }
      
       /**
       * return the objet's key.
       *
       * @param object
       * the object
       *
       * @return the key as string
       */
       private String getAsString(final DatabaseObject object)
       {
       String key = null;
       for (final Map.Entry<String, DatabaseObject> theEntry : content.entrySet())
       {
      
       log.debug("=====================>> theEntry.key #0", theEntry.getKey());
      
       if (theEntry.getValue().equals(object))
       {
       key = theEntry.getKey();
       break;
       }
       }
       return key;
       }
      
       /**
       * return the object
       *
       * @param key
       * the key
       *
       * @return the object
       */
       private DatabaseObject getAsObject(final String key)
       {
       return content.get(key);
       }
      
       /*
       * (non-Javadoc)
       *
       * @see javax.faces.convert.Converter#getAsObject(javax.faces.context.FacesContext, javax.faces.component.UIComponent,
       * java.lang.String)
       */
       public Object getAsObject(final FacesContext arg0, final UIComponent arg1, final String arg2)
       {
       return getAsObject(arg2);
       }
      
       /*
       * (non-Javadoc)
       *
       * @see javax.faces.convert.Converter#getAsString(javax.faces.context.FacesContext, javax.faces.component.UIComponent,
       * java.lang.Object)
       */
       public String getAsString(final FacesContext arg0, final UIComponent arg1, final Object arg2)
       {
       String retour = null;
       if (arg2 instanceof DatabaseObject)
       {
       retour = getAsString((DatabaseObject)arg2);
       }
       return retour;
       }
      
       public void setLog(final Log log)
       {
       this.log = log;
       }
      }


      My selectItems are all dispayed what ever i have in the vlaue field, it is never selected when i display my page.

      What's wrong with my code???

        • 1. Re: Problem whith SelectOneMenu - selected
          Laurent Parcet Newbie

          Hi all...

          In fact, my code has no problem, it's a JSF bug!!! ;P

          I use Jboss 4.2.2.GA with JSF 1.2_04 and i load all my parameters (ie converters content) at the server's startup.
          All my parameters are scope APPLICATION, except my EntityManager

          When i call my page, with a preselected value load by another EntityManager in my selectOneMenu, i have this exception:

          Cannot convert myPackage.ejb3.IrFractionnement@41 of type class myPackage.ejb3.IrFractionnement to class myPackage.ejb3.IrFractionnement_$$_javassist_102
          


          It's in the renderOption() method of MenuRenderer class when i call
          newValue = context.getApplication().getExpressionFactory().coerceToType(itemValue, type);
          

          which have a singular comment:


          // this should catch an ELException, but there is a bug
          // in ExpressionFactory.coerceToType() in GF


          I have an ugly solution to bypass the problem but we are trying to fix it by applying the 1.2_08 patch release of Mojarra.



          • 2. Re: Problem whith SelectOneMenu - selected
            Laurent Parcet Newbie

             

            I have an ugly solution to bypass the problem but we are trying to fix it by applying the 1.2_08 patch release of Mojarra.


            Does not work... :'(

            Waitting for JBoss 5 CR1...