有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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

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

索引。祖尔

<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>

验证。爪哇

包com。zk。形式

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) 个答案

  1. # 1 楼答案

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

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