How to redirect another zk page after all fields validation successfully with java ? Here i have created .zul page for form creation and then validate all fields in java class. Now i have to redirect page after completion of validations.
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 ");
}
}
}
please suggest how to do that.i am new to ZK
You can use Executions.sendRedirect(String url)
or Executions.forward(String)
Read documentation about Forward and Redirect here
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.