完成所有字段验证后如何重定向zk另一个页面?

时间:2019-04-22 09:17:17

标签: java zk

在使用Java成功验证所有字段之后,如何重定向另一个zk页面? 在这里,我已经创建了用于表单创建的.zul页面,然后验证了Java类中的所有字段。现在,完成验证后,我必须重定向页面。

index.zul

<zk>
<style>
        .z-window-embedded-tl,.z-window-embedded-tr,.z-window-embedded-hl,.z-window-embedded-hr,
        .z-window-embedded-hm 
        { 
            background-image:none;
            background-color:#94D3D3; 
        } 
        .z-window-embedded-cnt 
        { 
            border:1px
            solid #7BADAD; 
        }
</style>
<script defer="true">
      var oldMessage = jq.alert;
      jq.alert = function(msg, opts) {
      if(!msg.indexOf('the request was rejected because its size') || !msg.indexOf('The request was rejected because the file size'))
      zk.Widget.$('$info').setValue("Oh! Upload fail because of Size.");
     else
      oldMessage(msg, opts);}
</script>
  <window border="normal" title="Register Form" position="center,top" mode="overlapped" width="700px"  apply="com.zk.form.ControllerClass,com.zk.form.Messages">

    <grid >
        <rows>
            <row> 
                <label value = "FirstName" />

                <textbox type = "text" placeholder="FirstName" id ="Fname" constraint="no empty:Please enter your first name" />

             </row>
             <row>  
                <label value = "LastName"/>
                <textbox type = "text" placeholder="LastName" id = "Lname" constraint="no empty:Please enter your last name" />
            </row>

            <row>
                <label value = "Gender" />
                <radiogroup id="gender" >
                    <radio id="male" label="Male" selected="true" />
                    <radio id="female" label="Female" />
                    <radio id="others" label="Others" />
                </radiogroup>
            </row>
            <row>
                <label value = "Martial Status" />
                <radiogroup id = "marry" >
                    <radio id = "single" label = "Single" selected="true"/>
                    <radio id = "married" label = "Married" />
              </radiogroup>
            </row>
            <row>
                <label value = "Date Of Birth" />
                <datebox id = "dob" placeholder="Date Of Birth" format="MM/dd/yyyy" constraint="no future,no empty"/>
            </row>
            <row>
                <label value = "Mobile No" />
                <longbox id = "mobile" placeholder="MobileNo"  maxlength="10" constraint="no empty"/>
            </row>
            <row>
                <label value = "Email Addres" />
                <textbox  type = "text" placeholder="Email" id = "email" constraint="no empty,/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/: Please enter valid e-mail address"/>
            </row>
            <row> 
                <label value="Password"/>
                <textbox type="password" placeholder="Password" id="password1" constraint="no empty,/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z0-9])(?!.*\s).{8,15}$/: please enter valid password"/>
            </row>
            <row> 
                <label value="ReEnter Your Password"/>
                <textbox type="password" placeholder="Password" id="password2" constraint="no empty,/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z0-9])(?!.*\s).{8,15}$/: please enter valid password"/>
            </row>
            <row>
                <label value = "Address" />
                <textbox rows="4" placeholder="Your Address" width="300px;" id = "address" constraint="no empty"/>
            </row>
            <row>
                <label value = "Id proof" />
                <combobox id = "idproof" constraint="no empty">
                    <comboitem label = "AdhaarCard" />
                    <comboitem label = "Driving_License" />
                    <comboitem label = "OterId" />
                    <comboitem label = "Passport" />
                    <comboitem label = "Pancard" />
                </combobox>
            </row>
            <row>
                <label value="Select file to upload"/>
                <cell>
                <button label="Upload Id Proof" id="uploadId" upload="true, maxsize=50"/><label id="info"/> 
                </cell>
            </row>
        </rows>
    </grid>
    <space/>

    <div align="center">

        <button id="button"  label="Click Me"  />
    </div>

  </window>
</zk>

Validations.java

package com.zk.form;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.Date;

import org.zkoss.zk.ui.event.*;
import org.zkoss.zk.ui.util.*;
import org.zkoss.zul.*;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zul.Label;

@SuppressWarnings({ "serial", "rawtypes" })
public class ControllerClass extends GenericForwardComposer{

    //private static final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("E MMM dd HH:mm:ss Z yyyy");

     @Wire
     private Textbox Fname;

     @Wire
     private Textbox Lname;

     @Wire
     private Radiogroup gender;

     @Wire
     private Radiogroup marry;

     @Wire
     private Datebox dob;

     @Wire 
     private Longbox mobile;

     @Wire
     private Textbox email;

     @Wire
     private Textbox password1;

     @Wire
     private Textbox password2;

     @Wire
     private Textbox address;

     @Wire 
     private Combobox idproof;

     @Wire
     private Button uploadId;

     @Wire
     private Label info; 

     public void onClick$button(Event e) throws InterruptedException, ParseException
    {

      String fname = Fname.getValue();
      String lname = Lname.getValue();
      String gend = gender.getSelectedItem().getLabel();
      String marryStatus = marry.getSelectedItem().getLabel();
      Date birth = dob.getValue();
      Long mobileNo = mobile.longValue();
      //convert long value to String
      String phone = Long.toString(mobileNo);
      String mail = email.getValue();
      String pwd1 = password1.getValue();
      String pwd2 = password2.getValue();
      String add = address.getValue();
      String id = idproof.getValue();
      String upload = uploadId.getHoverImage();

    //DateFormat inputFormat = new SimpleDateFormat("E MMM dd HH:mm:ss Z yyyy");
      DateFormat input = new SimpleDateFormat("yyyy");
      String formatDate = input.format(birth);
      int birthYear = Integer.parseInt(formatDate);
    //System.out.println(Integer.parseInt(formatDate));

      LocalDateTime today = LocalDateTime.now();
      int diff = today.getYear() - birthYear;

    //Age Calculation................................
      if(diff < 18){
          alert("Age Should have 18+");
      }

    //Mobile No calculation..........................
      if (!(phone.charAt(0) == '9' || phone.charAt(0) == '8' || phone.charAt(0) == '7' || phone.charAt(0) == '6' )){

          alert("Mobile No. should start with 9 or 8 or 7 or 6");
      }

    //Password matching validatio......................

      if(! pwd1.equals(pwd2)){
          alert("Password not match ");
      }



    }
}

请提出建议。我是ZK的新手

1 个答案:

答案 0 :(得分:0)

您可以使用Executions.sendRedirect(String url)Executions.forward(String)

在此处阅读有关Forward and Redirect的文档