Uploaded image for project: 'Application Server 7'
  1. Application Server 7
  2. AS7-6262

Dynamically added JSF converter ignored in some cases since Mojarra 2.1.16 upgrade

XMLWordPrintable

    • Hide

      1. deploy the attached AS7-6262.war
      2. go to http://127.0.0.1:8080/AS7-6262/index.jsf
      3. click the "Add" button twice
      4. Notice the string "[default] [null]", which should be "[black] [null]"

      Show
      1. deploy the attached AS7-6262 .war 2. go to http://127.0.0.1:8080/AS7-6262/index.jsf 3. click the "Add" button twice 4. Notice the string " [default] [null] ", which should be " [black] [null] "
    • Hide

      Disable partial state saving by putting this into web.xml:

          <context-param>
              <param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
              <param-value>false</param-value>
          </context-param>
      
      Show
      Disable partial state saving by putting this into web.xml: <context-param> <param-name>javax.faces.PARTIAL_STATE_SAVING</param-name> <param-value> false </param-value> </context-param>

      Dynamically created converters seems to be ignored in some special cases, like the following.

      Having a form like this:

          <h:form>
      
              <ul>
                  <ui:repeat value="#{basket.items}" var="i">
                      <li>Item #{i.number}
                          <h:selectOneMenu value="#{i.color}">
                              <test:selectColors />
                          </h:selectOneMenu>
                      </li>
                  </ui:repeat>
              </ul>
      
      
              <div>
                  <h:commandButton value="Add" action="#{basket.add}" />
              </div>
      
              <h:outputText value="#{basket.string}" />
      
              </h:form>
      

      Where SelectColors is

      @JsfComponent(description=@Description(displayName="org.jboss.seam.test.SelectColors",value="Creates a List<SelectItem> of colors."),
      family="javax.faces.SelectItems", type="org.jboss.seam.test.SelectColors",generate="org.jboss.seam.test.html.HtmlSelectColors", 
      tag = @Tag(baseClass="javax.faces.webapp.UIComponentTagBase", name="selectColors"))
      public class SelectColors extends javax.faces.component.UISelectItems implements SystemEventListener {
      
         public SelectColors() {
            FacesContext context = FacesContext.getCurrentInstance();
            UIViewRoot root = context.getViewRoot();
      
            root.subscribeToViewEvent( PreRenderViewEvent.class, this );
         }
      
         @Override
         public Object getValue() {
            List<SelectItem> ret = new LinkedList<SelectItem> ();
      
            ret.add(new SelectItem("default", "Select color... (black by default)"));
            ret.add(new SelectItem("red", "Red"));
            ret.add(new SelectItem("white", "White"));
            ret.add(new SelectItem("blue", "Blue"));
            ret.add(new SelectItem("black", "Black"));
      
            return ret;
         }
      
         private void addSelectionConverter() {
            UIComponent parentComponent = getParent();
            if (parentComponent instanceof ValueHolder) {
               ValueHolder parentValueHolder = (ValueHolder) parentComponent;
      
               Converter parentConverter = parentValueHolder.getConverter();
      
               if (parentConverter == null) {
                  parentValueHolder.setConverter(new DefaultColorConverter());
               }
            }
         }
      
         @Override
         public void processEvent(SystemEvent event) throws AbortProcessingException
         {
            if ( !FacesContext.getCurrentInstance().isPostback() ) {
               addSelectionConverter();
            }
         }
      
         @Override
         public boolean isListenerForSource(Object source)
         {
            return ( source instanceof UIViewRoot );
         }
      }
      
      

      and the DefaultColorConverter being:

      @FacesConverter(value="org.jboss.seam.test.DefaultColorConverter")
      public class DefaultColorConverter implements Converter
      {
         public static final String DEFAULT_COLOR = "black";
      
         public Object getAsObject(FacesContext context, UIComponent component, String value) throws ConverterException
         {
            if ("default".equals(value)) {
          	  return DEFAULT_COLOR;
            }
            
            return value;
         }
      
         public String getAsString(FacesContext context, UIComponent component, Object value) throws ConverterException
         {
            return value.toString();
         }
      }
      

      In the pre-Mojarra 2.1.16 upgrade, clicking on the add button repeatedly creates "black" items. Post mojarra 2.1.16, it sets the color to "default", which should never happen, as the converter should convert the "default" value into "black".

        1. reproducer-pure.war
          10 kB
        2. reproducer-pure.tar.gz
          7 kB
        3. reproducer.war
          16 kB
        4. reproducer.tar.gz
          7 kB
        5. AS7-6262.war
          6.99 MB
        6. AS7-6262.tar.gz
          8 kB

              maschmid@redhat.com Marek Schmidt
              maschmid@redhat.com Marek Schmidt
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: