How to set inputText to required without affecting the output label in Primefaces?

When I set the required inputText, the outputLabel element associated with the inputText gets an asterisk added to it automatically. How to prevent the appearance of an asterisk?

<p:outputLabel value="Target Species" for="idInputText" />  
<p:inputText id="idInputText" required="true" value="#{controller.string}"/>

I am using PrimeFaces 4.0

+4
source share
4 answers
<p:outputLabel value="Target Species" for="idInputText" />  
<p:inputText id="idInputText" required="true" value="#{controller.string}"/>

In your code, you specifically set this label for inputText, and it will asterisk.

Remove "for"from outputLabel. It should look like this:

 <p:outputLabel value="Target Species" />  

Now you will not have asterisk.

-3
source

I would recommend using plain JSF <h:ouputLabel… />

<h:outputLabel value="Target Species" for="idInputText" />  
<p:inputText id="idInputText" required="true" value="#{controller.string}"/>

, . .

+11

Not sure if this also works for 4, but for PrimeFaces 5.3: just add indicateRequired="false". So:

<p:outputLabel value="Target Species"
               for="idInputText"
               indicateRequired="false"/>  
<p:inputText id="idInputText"
             required="true"
             value="#{controller.string}"/>
+6
source

Another option is to use css to hide asterisk:

.ui-outputlabel-rfi { display: none; }

Then the label will still be associated with the input, and you can still use the Label Provider if you want:

http://cagataycivici.wordpress.com/2011/02/11/label-provider-for-jsf-input-components/

+5
source

Source: https://habr.com/ru/post/1526230/


All Articles