0

how to provide the validation in controller for a form

asked 2011-07-02 06:20:47 +0800

user1 gravatar image user1
48 1

<?page title="new page title" contentType="text/html;charset=UTF-8" id="productnew_page_ID"?>
<zk>
<style>
textarea {
resize: none;
}
</style>
<grid width="100%" vflex="1" fixedLayout="true" mold="paging">
<rows>
<row>
Product Name*
<textbox width="150px" id="productname_textbox_ID" constraint="no empty,//:Product name cannot be blank" focus="true"/>
</row>
<row>
Release Name
<textbox width="150px" id="releasename_textbox_ID" />
</row>
<row>
Product Type*

<combobox width="155px" id="prodcttype_combo_ID" constraint="no empty,//:Product type cannot be blank">
<comboitem label="New" />


<comboitem label="Patch" />
<comboitem label="Release" />
<comboitem label="Upgrade" />
</combobox>
</row>
<row>
Product Version
<intbox width="151px" id="prodctversion_intbox_ID" />
</row>
<row>
Start Date*
<datebox width="155px" id="startdate_datebox_ID" constraint="no empty:Start date cannot be blank" format="yyyy/MM/dd"/>
</row>
<row>
End Date
<datebox width="155px" id="enddate_datebox_ID"/>
</row>
<row>
Market Tag Name*
<combobox width="155px" id="markettag_combo_ID" constraint="no empty,//:Market tag cannot be blank">
<comboitem label="My Tag" />
<comboitem label="New Tag" />
</combobox>
</row>
<row>
Description
<textbox rows="3" width="150px" id="description_textbox_ID"/>
</row>
<row>
Director of Products*
<intbox width="150px" id="directorofproduct_intbox_ID" constraint="no empty,/[0-9]/:director of products cannot be blank"/>
</row>
<row>
Product Manager*
<textbox width="150px" id="productmanager_textbox_ID" constraint="no empty,//:Product manager cannot be blank"/>
</row>
</rows>
</grid>
</zk>

This is a form in which i have provided validation using constraints
but how to provide the same validations using a controller


package com.genapt.thinktank.controller.product;


import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.util.Clients;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.Intbox;
import org.zkoss.zul.Textbox;

public class CustomernewDivIDViewCtrl extends GenericForwardComposer {

private static final long serialVersionUID = 1L;
private Textbox customer_customername_Textbox_ID;
private Textbox customer_contactperson_Textbox_ID;
private Textbox customer_email1_Textbox_ID;
private Intbox customer_mobileno_intbox_ID;

public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);
}
public void constrint(){
customer_contactperson_Textbox_ID.setConstraint("//:Starting only characters are allowed");
}
public void constrint1(){

}
public void onClick$save_Button_ID() {
Clients.clearWrongValue(new Component[] {customer_customername_Textbox_ID,customer_contactperson_Textbox_ID,customer_mobileno_intbox_ID,customer_email1_Textbox_ID});

if(customer_customername_Textbox_ID.getValue() == "" ){
//customer_customername_Textbox_ID.setConstraint("//:Starting only characters are allowed");
Clients.wrongValue(customer_customername_Textbox_ID, "Customername cannot be emprty");
}
else if(customer_customername_Textbox_ID.getValue() != "//"){
Clients.wrongValue(customer_customername_Textbox_ID, "Stating only characters are allowed");
}

else if(customer_contactperson_Textbox_ID.getValue() == "" ){
//constrint();
Clients.wrongValue(customer_contactperson_Textbox_ID, "Contact cannot be emprty");
}
else if(customer_mobileno_intbox_ID.getValue() == null ){
Clients.wrongValue(customer_mobileno_intbox_ID, "Contact cannot be emprty");
}
else if(customer_email1_Textbox_ID.getValue() == "" ){
customer_email1_Textbox_ID.setConstraint("/[a-zA-Z0-9._\\-]+@[a-zA-Z0-9.\\-]+\\.{2,4}/:Eneter proper email Id");
Clients.wrongValue(customer_email1_Textbox_ID, "Email cannot be emprty");
}
}
}


i tried this but if i enter correct values also its not validating .its raising an error like alert box
so any one can guid eme regarding this issue
thank u in advance

delete flag offensive retag edit

1 Reply

Sort by ยป oldest newest

answered 2011-07-04 06:53:35 +0800

benbai gravatar image benbai
2228 6
http://www.zkoss.org

the code below works fine for me:

zul file:

<zk>
	<window apply="support.TestComposer">
		<textbox id="myText" />
		<button id="myButton" label="test" onClick="" />
	</window>
</zk>

composer

package support;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.util.Clients;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.Button;
import org.zkoss.zul.Textbox;

public class TestComposer extends GenericForwardComposer {
	private Button myButton;
	private Textbox myText;
	
	public void onClick$myButton() {
		if( !"abc".equals(myText.getValue()) ){
			Clients.wrongValue(myText, "only accept abc in myText");
		}
	}
	public void onClick$myText() {
		Clients.clearWrongValue(new Component[] {myText});
	}
}

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2011-07-02 06:20:47 +0800

Seen: 350 times

Last updated: Jul 04 '11

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More