Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package se.conecte.view.validators;
- import javax.faces.application.FacesMessage;
- import javax.faces.component.UIComponent;
- import javax.faces.context.FacesContext;
- import javax.faces.validator.Validator;
- import javax.faces.validator.ValidatorException;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.context.annotation.Scope;
- import org.springframework.stereotype.Component;
- import se.conecte.services.IUserService;
- /**
- *
- * @author Arthur Gregorio
- *
- * @category
- *
- * @since 1.0
- * @version 1.0, 05/11/2012
- */
- @Scope("request")
- @Component("userLoginValidator")
- public class UserLoginValidator implements Validator {
- @Autowired
- private IUserService userService;
- @Override
- public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
- final boolean isSaved = (Boolean) component.getAttributes().get("isSaved");
- if (!isSaved) {
- final String username = value.toString();
- if (userService.findByLogin(username) != null) {
- FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
- "Erro!", "Nome de usuário duplicado!");
- throw new ValidatorException(message);
- }
- }
- }
- }
- <p:inputText id="inLogin"
- required="true"
- value="#{userController.user.login}"
- validatorMessage="Login informado é inválido">
- <f:validateRegex pattern="[a-zA-Z0-9_]{3,16}" />
- <f:validator binding="#{userLoginValidator}"/>
- <f:attribute name="isSaved" value="#{userController.user.saved}"/>
- </p:inputText>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement