T
- Type of the entity.public class AUniqueNameValidator<T extends INameProviding & de.xima.cmn.dao.interfaces.IEntity<Long>> extends ABackendJSFContext implements javax.faces.validator.Validator, Serializable
Attach this validator to the input field for the INameProviding.getName()
of an IEntity
. Validates
whether that name is unique, that is, whether the current entity is the only one with that given name. This requires
that we know which entity is the current entity. Attach the "currentEntityId" to the input component or one of its
parents, like so:
<p:outputPanel> <p:inputText value="#{bean.entity.name}" /> <f:attribute name="currentEntity" value="#{bean.entity}" /> </p:outputPanel>
In case the attribute is not attached to the component or one of its parents, we fall back to the old behavior: Skip the validation iff the new value is equal to the old (previous) value of the component. Please note that this fails when creating a new entity and setting a default value for the name -- validation of the name will be skipped when saving the entity.
AJSFContext.RedirectOptions, AJSFContext.RedirectOptionsBuilder
Constructor and Description |
---|
AUniqueNameValidator(Class<T> clazz) |
Modifier and Type | Method and Description |
---|---|
protected de.xima.cmn.criteria.QueryCriteriaManager |
setupQcm(de.xima.cmn.criteria.QueryCriteriaManager qcm,
T currentEntity)
To check for duplicate names, we create a query criteria manager for all entities with the given name, excluding
the current entity.
|
void |
throwError() |
void |
validate(javax.faces.context.FacesContext context,
javax.faces.component.UIComponent component,
Object value) |
ec, isDetached, isHasDB
destroySessionBean, encodeURL, findBean, findBean, findBean, findBean, findBean, findBean, findBean, findCurrentView, getBeanName, getBeanName, getContext, getCurrentViewBean, getLocaleBean, getRequest, getResponse, getSession, getSession, getSessionAttribute, isMasterServerContext, loadLazy, redirect, redirect, redirect, redirect, redirectToDashboard, redirectToDashboard, setLocaleBean, setSessionAttribute, uc
addErrorMsg, addErrorMsg, addErrorMsg, addErrorMsg, addErrorMsg, addErrorMsg, addErrorMsgFromString, addErrorMsgFromString, addErrorMsgToComponent, addErrorMsgToComponent, addErrorMsgToComponent, addErrorMsgToComponent, addErrorMsgToComponent, addErrorMsgToComponent, addInfoMsg, addInfoMsg, addInfoMsg, addInfoMsg, addInfoMsgFromString, addInfoMsgFromString, addInfoMsgToComponent, addInfoMsgToComponent, addInfoMsgToComponent, addInfoMsgToComponent, addMsg, addMsg, addMsg, addMsg, addMsgs, addMsgToComponent, addMsgToComponent, addWarnMsg, addWarnMsg, addWarnMsg, addWarnMsg, addWarnMsgFromString, addWarnMsgFromString, addWarnMsgToComponent, addWarnMsgToComponent, addWarnMsgToComponent, addWarnMsgToComponent, cleanErrorMsg, getErrorMessage, getNewErrorMsg, getNewErrorMsg, getNewErrorMsg, getNewInfoMsg, getNewInfoMsg, getNewMsg, getNewWarnMsg, getNewWarnMsg
public void validate(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, Object value) throws javax.faces.validator.ValidatorException
validate
in interface javax.faces.validator.Validator
javax.faces.validator.ValidatorException
protected de.xima.cmn.criteria.QueryCriteriaManager setupQcm(de.xima.cmn.criteria.QueryCriteriaManager qcm, T currentEntity)
qcm
- Current query criteria manager.currentEntity
- The current entitity whose name is validated. Might be null
.public void throwError() throws javax.faces.validator.ValidatorException
javax.faces.validator.ValidatorException
Copyright © 2021 XIMA MEDIA GmbH. All rights reserved.