Forums de discussion

how-t mark mandatory (required) fields in browser

PortletFaces Community Member, modifié il y a 12 années.

how-t mark mandatory (required) fields in browser

Regular Member Publications: 199 Date d'inscription: 03/04/12 Publications récentes
Hi,
I have the following field definition on my form

  <h:inputtext id="address1" required="true" value="#{registrantModelBean.registrant.address.street1}" />


Is there a way to mark this field with a red asterisk so that users know that input is mandatory?

I would like the required="true" or required="false" to trigger the generation of the asterisk - (and) or for that matter a css class that can be customised.

Separate question - is it possible to attach mouse-over text displays to a portletfaces-bridge form field?

thanks

Chris
thumbnail
Neil Griffin, modifié il y a 12 années.

RE: how-t mark mandatory (required) fields in browser

Liferay Legend Publications: 2655 Date d'inscription: 27/07/05 Publications récentes
The h:inputText tag is a stock JSF2 component. It simply renders an HTML <input type="text" />

What you want to do with an asterisk is a good candidate for a Facelet composite component. You can find a few example composite components in the JSF2 portlet example:
https://github.com/liferay/liferay-faces/blob/master/demos/bridge/jsf2-portlet/src/main/webapp/resources/example-cc/

For example, if you had <my:inputText required="true" /> then your composite component would do something like this:

<h:inputText required="#{cc.attrs.required"} styleClass="required-field" />