java - Dynamic required validation for different buttons? -


i'm learning jsf 2.0 core jsf 2.0 book + glassfish + cdi.

i have question validation feature of jsf.

let's have simple login application, has simple layout :

userid : (input field userid - using required="true")
password : (input secret password - using required="true")
loginbutton + registerbutton(using immediate="true") + checkuseridavailabilitybutton

now, let's loginbutton pressed, , userid , password left empty, validation error occur on both of fields, , that's working intended.

and when registerbutton pressed, doesnt care whether userid or password filled user, since it's using immediate="true", bypassing validation , command gets executed @ apply request value phase, , that's still working intended.

and here comes problem .. when checkuseridavailabilitybutton pressed, expect userid filled, , dont need care whether password field filled or not, password field throw error saying it's required field.

is there anyway resolve kind of problem ? know simple application, in working place, think design lots of screens this, save button along refresh button different required fields buttons in same page.

thank !

set both availability button , username field immediate="true" and put register button in separate <h:form>.

e.g.

<h:form>      <h:inputtext value="#{bean.username}" required="true" immediate="true" />      <h:inputsecret value="#{bean.password}" required="true" />      <h:commandbutton value="login" action="#{bean.login}" />      <h:commandbutton value="check name availability" action="#{bean.checknameavailability}" immediate="true" /> </h:form> <h:form>      <h:commandbutton value="register" action="#{bean.register}" /> </h:form> 

an alternative determine in required attribute button been pressed (it's present request parameter).

<h:form id="form">      <h:inputtext value="#{bean.username}" required="#{not empty param['form:login'] or not empty param['form:check']}" />      <h:inputsecret value="#{bean.password}" required="#{not empty param['form:login']}" />      <h:commandbutton id="login" value="login" action="#{bean.login}" />      <h:commandbutton id="check" value="check name availability" action="#{bean.checknameavailability}" />      <h:commandbutton value="register" action="#{bean.register}" /> </h:form> 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

c# - How to execute a particular part of code asynchronously in a class -

c# - Asterisk click to call -