Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

jsf

primefaces

When I set an inputText to required, the the outputLabel I have associated with the inputText gets an asterisk added to it automatically. How do I prevent the asterisk from appearing?

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

I am using PrimeFaces 4.0

like image 682
Nick Avatar asked Feb 10 '14 19:02

Nick


3 Answers

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

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

This removes the asterisk but keeps the label correctly associated with the input element. This is important for accessibility.

like image 161
spencer Avatar answered Oct 19 '22 18:10

spencer


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

<p:outputLabel value="Target Species"
               for="idInputText"
               indicateRequired="false"/>  
<p:inputText id="idInputText"
             required="true"
             value="#{controller.string}"/>
like image 23
Jasper de Vries Avatar answered Oct 19 '22 20:10

Jasper de Vries


Another option is to use css to hide the asterisk:

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

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

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

like image 28
schmeic Avatar answered Oct 19 '22 20:10

schmeic