So my team has a jsf and we use an EL statement to read in the value of an input box, works fine but by default we have our value set as what should be filled into the field. How can I set a default value for the input while still having the EL statement work.
Example:
<h:inputText value="#{registrationBean.firstName}" styleClass="formEle"/>
I tried
<h:inputText value="#{registrationBean.firstName}First Name" styleClass="formEle"/>
but this breaks the connection when we submit.
Any ideas?
You’re looking for something which is called a “watermark” or “placeholder”. At low level, these days this is normally to be done by the HTML5
placeholderattribute:This works of course only in browsers supporting HTML5 and then only with JSF components supporting the new HTML5 attribute. The standard JSF
<h:inputText>doesn’t support this natively (yet). You’d need to look for 3rd party component libraries supporting this. Among them is PrimeFaces with its<p:watermark>:If using PrimeFaces is not an option for some reason, you’d need to reinvent it yourself in flavor of a custom component and/or a custom piece of JS/jQuery, exactly like
<p:watermark>is doing under the covers.