在JSF

时间:2016-09-13 13:46:03

标签: forms validation jsf

我有一个id为first_form的表单。当我单击commandButton时,此表单将被隐藏,并呈现另一个具有id second_form的表单。但是在second_form验证器中不起作用。这是我的xhtml文件

<h:form id="first_form">
    <h:panelGroup id="panel1" rendered="#{userbean.visible1}">
        <div class="col-md-12">
            <div id = "inputform">
                <div id="col6-left" class="col-md-6">                                        
                    <div id="registration" style="padding:10px 40px; ">
                        <h3 style="text-align: center">Enter your car registration</h3>
                        <span  class="car-reg-widget" >
                            <h:inputText id="plate_number" value="#{userbean.plate_number}"
                                         required="true"
                                         requiredMessage="The plate number is required"
                                         label="The value" 
                                         validatorMessage="must be a number."/>   
                        </span>
                        <div style="text-align: center; margin-top:30px;">
                            <h3 style="text-align: center">Mileage</h3>
                            <h:inputText style="width:30%; font-size:1.4em; text-align:center; " 
                                         id="mileage-text" 
                                         value="#{userbean.mileage_number}"  
                                         required="true" 
                                         label="The value"
                                         requiredMessage="The mileage number is required"
                                         validatorMessage="must be a number."
                                         autocomplete="off">
                            </h:inputText><br/>
                            <h:message id="fooMessage" for="mileage-text" style="color:red" />
                            <br/><br/>
                            <h:commandButton value="Get Valuation" action="#{userbean.price()}" title="Get Valuation" class="btn btn-orange" style="alignment-adjust: central">
                                <f:ajax execute="first_form" render="first_form second_form"/>
                            </h:commandButton>
                            <br/>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </h:panelGroup>
</h:form>

<h:form id="second_form">
    <h:panelGroup id="panel2" rendered="#{userbean.visible2}">
        <div id="col6-left" class="col-md-6"><br/><br/><br/><br/><br/><br/><br/>
            <h4 style="text-align: center">Enter your details.</h4>
            <p style="text-align: center">Leave your contact info</p>
        </div>
        <div id="col6-right" class="col-md-6" style="padding:20px;; border-left:1px solid whitesmoke; background-color: whitesmoke; align-items: center">
            <h:outputLabel style="font-weight: bold">Name *</h:outputLabel><br/>
            <h:inputText style="width:100%" 
                         id="name"  required="true" 
                         requiredMessage="The Name field is required"
                         value="#{userbean.name}">
                <f:ajax event="keyup" execute="@this" render="NameMessage" />
                <f:validator validatorId="FnameValidator"/>
            </h:inputText><br/>
            <h:message id="NameMessage" for="name" style="color:red" /><br/>

            <h:outputLabel style="font-weight: bold">Email *</h:outputLabel><br/>
            <h:inputText style="width:100%" id="email" required="true" 
                         requiredMessage="The Email field is required"
                         value="#{userbean.email}">
                <f:ajax event="keyup" execute="@this" render="EmailMessage" />
                <f:validator validatorId="emailValidator"/>
            </h:inputText> <br/>
            <h:message id="EmailMessage" for="email" style="color:red" /><br/>

            <h:outputLabel style="font-weight: bold">Phone *</h:outputLabel><br/>
            <h:inputText style="width:100%" id="phone" required="true" 
                         requiredMessage="The Phone field is required"
                         value="#{userbean.phone}">
                <f:ajax event="keyup" execute="@this" render="PhoneMessage" />
                <f:validator validatorId="PhoneValidator"/>
            </h:inputText> <br/>
            <h:message id="PhoneMessage" for="phone" style="color:red" /><br/>

            <h:outputLabel style="font-weight: bold">Postcode *</h:outputLabel><br/>
            <h:inputText style="width:100%" id="postcode" required="true" 
                         requiredMessage="The Postcode field is required"
                         value="#{userbean.postcode}">
            </h:inputText> <br/>
            <h:message id="PostCodeMessage" for="postcode" style="color:red" /><br/>
            <h:commandButton class="btn btn-orange" 
                             value="Submit" 
                             action="#{userbean.address()}">
                <f:ajax execute="second_form" render="second_form third_form"/>
            </h:commandButton>
        </div>
    </h:panelGroup>
</h:form>

这是我的bean文件:

        public void price() throws MalformedURLException, IOException {
            visible1 = false;
            visible2 = true;
            System.out.println(plate_number);
            System.out.println(mileage_number);
        }

        public void address() throws MalformedURLException, IOException {
            visible3 = true;
            System.out.println("name: " + name);
            System.out.println("email: " + email);
            System.out.println("phone: " + phone);
            System.out.println("postcode: " + postcode);

        }

0 个答案:

没有答案