Fórumok

how-t mark mandatory (required) fields in browser

PortletFaces Community Member, módosítva 12 év-val korábban

how-t mark mandatory (required) fields in browser

Regular Member Bejegyzések: 199 Csatlakozás dátuma: 2012.04.03. Legújabb bejegyzések
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, módosítva 12 év-val korábban

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

Liferay Legend Bejegyzések: 2655 Csatlakozás dátuma: 2005.07.27. Legújabb bejegyzések
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" />