Default text (placeholder) in InputText component

后端 未结 2 2000
悲&欢浪女
悲&欢浪女 2021-01-18 17:13

\"enter

I want to display a default Informative text in JSF/Primefaces inputTe

2条回答
  •  我在风中等你
    2021-01-18 18:10

    Primefaces provides a placeholder attribute in its latest versions which you can use for p:inputText. Also, there is a p:watermark component which creates a JS based solution for legacy browser compatibility. So you don't definitely need to set a default value into the backing bean. Just use one of the following solutions:

      
      
    

    For legacy browsers:

      
      
    
    

    Also if using JSF 2.2, you can use its passthrough attributes. Adding xmlns:pt="http://xmlns.jcp.org/jsf/passthrough" namespace to your page, you can achieve in the following way, both for JSF h:inputText and Primefaces p:inputText:

    
    

    Or wrapping it into the tag with a TagHandler:

    
        
    
    

    Which creates HTML 5 based input with placeholder attribute:

     
    

提交回复
热议问题