Announcement Announcement Module
Collapse
No announcement yet.
SWF + Faces showing Errors from Validator Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • SWF + Faces showing Errors from Validator

    I have defined flow:
    <view-state id="registrationForm">
    <on-render>
    <evaluate expression="registrationA.setupForm"/>
    </on-render>
    <transition on="potvrdit" to="registrationCheck">
    <evaluate expression="registrationA.bindAndValidate"/>
    </transition>
    <transition on="zrusit" to="cancel"/>
    </view-state>
    Form Action with Validator:
    <bean id="registrationA" class="org.springframework.webflow.action.FormActi on">
    <property name="formObjectName" value="newUser"/>
    <property name="formObjectClass" value="cz.sis.domain.User" />
    <property name="validator" ref="userValidator"/>
    <property name="formObjectScope" value="CONVERSATION"/>
    <property name="formErrorsScope" value="CONVERSATION"/>
    </bean>
    Validator:
    @Component("userValidator")
    public class UserValidator implements Validator {
    private RegistrationService registrationService;

    @Override
    public boolean supports(Class clazz) {
    return User.class.equals(clazz);
    }

    @Override
    public void validate(Object object, Errors errors) {
    User user = (User) object;

    if(registrationService.existUsername(user.getUsern ame())){
    errors.rejectValue("username","errorCode","This username exists!");
    }
    }

    public RegistrationService getRegistrationService() {
    return registrationService;
    }

    @Autowired
    public void setRegistrationService(RegistrationService registrationService) {
    this.registrationService = registrationService;
    }
    }
    The validator works well but I donīt know how to show error message in JSF view...I tried this:
    <h:outputLabel for="username">#{resourceBundle.user_form_login}</h:outputLabel>
    <sf:clientTextValidator required="true" regExp="^.{1,32}" invalidMessage="#{resourceBundle.user_form_login_r egexp}">
    <h:inputText id="username" value="#{newUser.username}" />
    </sf:clientTextValidator>
    <h:message for="username" errorClass="errors"/>
    But nothing was shown. Can you hel me please???
Working...
X