facelets
  1. facelets
  2. FACELETS-335

ui:repeat input map value cannot be cleared

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.1.14
    • Fix Version/s: 1.1.15
    • Component/s: impl
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      335

      Description

      Under the following conditions a text input backed by a map value is unable to
      set a null value into the map:

      1. The input is within a ui:repeat
      2. The input uses a converter that converts empty strings to null
      3. The map value is initialised to a non-null value via a @PostConstruct method

      With such a configuration I can change the value in the map to any other value,
      but attempting to input empty string (which is converted to null) causes the
      @PostConstruct default to be set into the map instead.

      This seems to be due to HtmlInputText.getValue() (which is implemented by the
      UIOutput ancestor class) re-evaluating the EL expression if the current value is
      null, even if the local value has already been set.

      This occurs with Facelets 1.1.14 and JSF 1.2_09. I have not tested with other
      releases.

      Following are some code snippets from a minimal example demonstrating this:

      MapExampleBean.java:
      package mapexample;

      import java.util.ArrayList;
      import java.util.HashMap;
      import java.util.List;
      import java.util.Map;

      import javax.annotation.PostConstruct;

      public class MapExampleBean {
      private Map<String, String> map = new HashMap<String, String>();

      @PostConstruct
      public void initialise()

      { map.put("One", "1"); }

      public Map<String, String> getMap()

      { return map; }

      public List<String> getMapKeys()

      { return new ArrayList<String>(map.keySet()); }

      public void actionSubmit()

      { System.out.println("MapTest.actionSubmit() - map " + map); }

      }

      MyStringConverter:
      package mapexample;

      import javax.faces.component.UIComponent;
      import javax.faces.component.html.HtmlInputText;
      import javax.faces.context.FacesContext;
      import javax.faces.convert.Converter;
      import javax.faces.convert.ConverterException;

      public class MyStringConverter
      implements Converter
      {
      public Object getAsObject(FacesContext context, UIComponent component, String
      value)
      {
      if (value == null || value.trim().length() == 0)

      { return null; }

      return value;
      }

      public String getAsString(FacesContext context, UIComponent component, Object
      value)
      {
      if (value == null)
      { return null; }

      return value.toString();
      }
      }

      mapExample:xhtml:
      <?xml version="1.0" encoding="UTF-8"?>

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

      <html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html">

      <h:form id="form">
      <ui:repeat id="repeat" value="#

      {mapExample.mapKeys}

      " var="key">
      <h:inputText value="#

      {mapExample.map[key]}

      " converter="MyStringConverter" />
      </ui:repeat>
      <h:commandButton id="submit" value="Submit"
      action="#

      {mapExample.actionSubmit}

      " />
      </h:form>

      </html>

        Activity

        Hide
        deaves added a comment -

        This issue has also been reported for the Mojarra project as I'm unsure where
        the problem resides. See
        https://javaserverfaces.dev.java.net/issues/show_bug.cgi?id=819

        Show
        deaves added a comment - This issue has also been reported for the Mojarra project as I'm unsure where the problem resides. See https://javaserverfaces.dev.java.net/issues/show_bug.cgi?id=819

          People

          • Assignee:
            Unassigned
            Reporter:
            deaves
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: