0 Replies Latest reply on Oct 31, 2014 7:11 AM by bluez974

    RF 4.5 - render an input with placeholder attached

    bluez974

      Hello,

      I find a bug on placeholder and i have got a work-around too.

       

      When i click the add Button, it add a new line to the table and empties the inputText.

      But after rendering the inputText the placeholder doesn't appear anymore and the value of the inputText is not updated anymore when clicking again the add button.

      Even the required attribute is not taken in account.

       

      Here after is the facelet and the bean to reproduce the issue.

       

      <h:form id="frm">
        <h:inputText id="itName" required="true" value="#{placeHolderBean.newName}" >
             <rich:placeholder value="Type a name" />
        </h:inputText>
        <rich:message for="itName" />
      
        <a4j:commandButton value="Add" 
             execute="itName"
             actionListener="#{placeHolderBean.addName}" 
             render="itName,dtNames"/> 
      
      
        <rich:dataTable id="dtNames" value="#{placeHolderBean.names}" var="n" >
             <rich:column>
                  <f:facet name="header">Names</f:facet>
                  <h:outputText value="#{n}" />
             </rich:column>
        </rich:dataTable>
      </h:form>
      

       

       

      import java.util.ArrayList;
      import java.util.List;
      
      
      import javax.faces.bean.ManagedBean;
      import javax.faces.bean.ViewScoped;
      import javax.faces.event.ActionEvent;
      
      
      @ManagedBean
      @ViewScoped
      public class PlaceHolderBean {
      
        public List<String> names = new ArrayList<String>();
      
        public String newName;
      
        public void addName(ActionEvent event) {
             names.add(newName);
             newName = "";
        }
      
        public List<String> getNames() {
             return names;
        }
        public void setNames(List<String> names) {
             this.names = names;
        }
        public String getNewName() {
             return newName;
        }
        public void setNewName(String newName) {
            this.newName = newName;
        }
      
      }
      

       

      The work-around is :

      - to put the placeholder outside the inputText and use its @selector

      - to also render the placeholder

       

       

      <h:form id="frm">
        <h:inputText id="itName" required="true" value="#{placeHolderBean.newName}" >
      
        </h:inputText>
        <rich:placeholder id="phName" value="Type a name" selector="#frm\:itName" />
        <rich:message for="itName" />
        <a4j:commandButton value="Add" 
             execute="itName"
             actionListener="#{placeHolderBean.addName}" 
             render="itName,dtNames,phName"/> 
      
      
        <rich:dataTable id="dtNames" value="#{placeHolderBean.names}" var="n" >
        <rich:column>
        <f:facet name="header">Names</f:facet>
        <h:outputText value="#{n}" />
        </rich:column>
      
        </rich:dataTable>
      </h:form>