|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object javax.faces.component.UIComponent javax.faces.component.UIComponentBase org.omnifaces.component.script.ScriptFamily org.omnifaces.component.script.OnloadScript org.omnifaces.component.script.Highlight
public class Highlight
Highlight is a helper component which highlights all invalid UIInput
components by adding
an error style class to them. Additionally, it by default focuses the first invalid UIInput
component. The
<o:highlight />
component can be placed anywhere in the view, as long as there's only one of it.
Preferably put it somewhere in the master template for forms.
<h:form> <h:inputText value="#{bean.input1}" required="true" /> <h:inputText value="#{bean.input2}" required="true" /> <h:commandButton value="Submit" action="#{bean.submit}" /> </h:form> <o:highlight />
The default error style class name is error. You need to specify a CSS style associated with the class yourself. For example,
.error { background-color: #fee; }
You can override the default error style class by the styleClass
attribute:
<o:highlight styleClass="invalid" />
You can disable the default focus on the first invalid input element setting the focus
attribute.
<o:highlight styleClass="invalid" focus="false" />
Field Summary | |
---|---|
static java.lang.String |
COMPONENT_TYPE
The standard component type. |
Fields inherited from class org.omnifaces.component.script.ScriptFamily |
---|
COMPONENT_FAMILY |
Fields inherited from class javax.faces.component.UIComponent |
---|
BEANINFO_KEY, bindings, COMPOSITE_COMPONENT_TYPE_KEY, COMPOSITE_FACET_NAME, CURRENT_COMPONENT, CURRENT_COMPOSITE_COMPONENT, FACETS_KEY, VIEW_LOCATION_KEY |
Constructor Summary | |
---|---|
Highlight()
Constructs the Highlight component. |
Method Summary | |
---|---|
void |
encodeChildren(javax.faces.context.FacesContext context)
Visit all components of the current UIForm , check if they are an instance of UIInput and are not
UIInput.isValid() and finally append them to an array in JSON format and render the script. |
java.lang.String |
getStyleClass()
Returns the error style class which is to be applied on invalid inputs. |
boolean |
isFocus()
Returns whether the first error element should gain focus. |
void |
setFocus(boolean focus)
Sets whether the first error element should gain focus. |
void |
setStyleClass(java.lang.String styleClass)
Sets the error style class which is to be applied on invalid inputs. |
Methods inherited from class org.omnifaces.component.script.OnloadScript |
---|
encodeBegin, encodeEnd, isListenerForSource, processEvent, processEvent |
Methods inherited from class org.omnifaces.component.script.ScriptFamily |
---|
getFamily, getRendersChildren |
Methods inherited from class javax.faces.component.UIComponentBase |
---|
addClientBehavior, addFacesListener, broadcast, clearInitialState, decode, findComponent, getAttributes, getChildCount, getChildren, getClientBehaviors, getClientId, getDefaultEventName, getEventNames, getFacesContext, getFacesListeners, getFacet, getFacetCount, getFacets, getFacetsAndChildren, getId, getParent, getRenderer, getRendererType, getValueBinding, invokeOnComponent, isRendered, isTransient, markInitialState, processDecodes, processRestoreState, processSaveState, processUpdates, processValidators, queueEvent, removeFacesListener, restoreAttachedState, restoreState, saveAttachedState, saveState, setId, setParent, setRendered, setRendererType, setTransient, setValueBinding |
Methods inherited from class javax.faces.component.UIComponent |
---|
encodeAll, getClientId, getCompositeComponentParent, getContainerClientId, getCurrentComponent, getCurrentCompositeComponent, getListenersForEventClass, getNamingContainer, getResourceBundleMap, getStateHelper, getStateHelper, getValueExpression, initialStateMarked, isCompositeComponent, isInView, isVisitable, popComponentFromEL, pushComponentToEL, setInView, setValueExpression, subscribeToEvent, unsubscribeFromEvent, visitTree |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String COMPONENT_TYPE
Constructor Detail |
---|
public Highlight()
Method Detail |
---|
public void encodeChildren(javax.faces.context.FacesContext context) throws java.io.IOException
UIForm
, check if they are an instance of UIInput
and are not
UIInput.isValid()
and finally append them to an array in JSON format and render the script.
Note that the FacesContext.getClientIdsWithMessages()
could also be consulted, but it does not indicate
whether the components associated with those client IDs are actually UIInput
components which are not
UIInput.isValid()
. Also note that the highlighting is been done by delegating the job to JavaScript
instead of directly changing the component's own styleClass
attribute; this is chosen so because we
don't want the changed style class to be saved in the server side view state as it may result in potential
inconsitenties because it's supposed to be an one-time change.
encodeChildren
in class javax.faces.component.UIComponentBase
java.io.IOException
public java.lang.String getStyleClass()
public void setStyleClass(java.lang.String styleClass)
styleClass
- The error style class which is to be applied on invalid inputs.public boolean isFocus()
true
.
public void setFocus(boolean focus)
focus
- Whether the first error element should gain focus.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |