0

Problem with constraints validations...

asked 2007-03-06 11:41:16 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4193086

By: mikomax

Hi all,

I have implemented a form with constraints on some fields(zk native contraints and RegEx).

the constraints seems NOT to work correctly! Perhaps have I made a mistake?

when the page is loaded, only the ZK constraints are well executed BUT not the regex if I call "isValid()" on the fields.
if I modify the fields(setValue/setRawValue or with binding), the constraints validation also has a strange behaviour...
neither the screen popups(wrongvalueException), neither the isValid method are running properly.

here is my code(a simple zul page with its associated class + some test cases procedures to simulate the different error cases)



thank you for your help...
Michael.


TEST CASE:

only the "Initiales", "Nom" and "Prenom" fields will be tested in these test cases. the others are figurative...

1)open the page, just push on validate button. "Initiales"(native zk contraint),
"Nom"(regex) and "Prenom"(regex) fields should be detected as erroneous but only the Initiales is well detected by isValid()

2)without reloading and directly after test 1) go through all fields with the tab key, you will see the error popups!(here the fields are well validated???) and then click on validate button -> the isValid() has well detected the erroneous fields(only when the have been stimulated by the onChange event?)

3)-reload the page to reset everithing.
-click on "bind" button then on "validate" button, now the three fields are well detected as erroneous.
-put some value("abc") in the fields then click on validate. -> the isValid reacts as expected, no error detected, that's normal.
-now, click on "bind" button again then on "validate" button and NO error is detected by the isValid() however, the Textbox value is"" and should have been detected.
-go through the fields with the tab(or mouse click) to stimulate the onChange event -> you can now see ONLY the error popup for the native ZK constraint BUT not for the regex.
click on validate button and only the native constraint is well executed...


4)do the same as test case 3 but instead of using the "bind" button, click on "setvals" button... you will have nearby the same reaction...




/// ZUL file
<?xml version="1.0" encoding="UTF-8"?>
<?page id="detailAgent" ?>
<!-- <?init class="be.ciger.d121.regie.ui.gestionAgents.AjoutEditVisuAgentInit"
?> -->
<zk
xmlns="http://www.zkoss.org/2005/zul"
xmlns:a="http://www.zkoss.org/2005/zk/annotation"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.zkoss.org/2005/zul
http://www.zkoss.org/2005/zul/zul.xsd ">
<window
id="detailWindow"
width="400px"
use="be.ciger.d121.regie.ui.gestionAgents.AjoutEditVisuAgentWindow2">
<!-- border="normal" closable="true" -->
<groupbox
closable="false"
open="true"
mold="3d">
<caption label="Detail"></caption>
<grid id="gridDetail">
<columns>
<column width="75"></column>
<column></column>
<column width="5"></column>
</columns>

<rows>
<row>
<label value="Initiales"></label>
<hbox>
<a:bind value="agentBean.initiales" />
<!-- maxlength="30" -->
<textbox
id="Initiales"

constraint="no empty:Champ obligatoire, sans espaces">
</textbox><!-- onChanging="detailWindow.hasChanged()" -->
*
</hbox>
</row>
<row>

<label value="Nom"></label>
<hbox>
<a:bind value="agentBean.nom" />
<textbox
id="Nom"

constraint="/[A-Za-z' ]+/:Champ obligatoire">
</textbox><!-- onChanging="detailWindow.hasChanged()" /[A-Za-z' ]+/ -->
*
</hbox>
</row>
<row>
<label value="Prenom"></label>
<a:bind value="agentBean.prenom" />
<textbox
constraint="/[A-Za-z' ]+/:Champ obligatoire"
id="Prenom"
><!-- onChanging="detailWindow.hasChanged()" -->
</textbox>
</row>
<row>
<label value="EMail"></label><!-- -->
<a:bind value="agentBean.mail" />
<textbox
id="Mail"

constraint="/([A-Za-z0-9-_.]+@[A-Za-z0-9-_.]+[\.][A-Za-z]{2,4})?/:le
champ eMail doit etre encode avec le format suivant [email protected]"><!-- onChanging="detailWindow.hasChanged()" -->
</textbox>
</row>
<row>
<label value="GSM"></label>
<a:bind value="agentBean.gsm" />
<textbox
id="GSM"

constraint="/([0-9]{4}[\/][0-9]{6})?/:Le numero de GSM doit etre encode avec ce format xxxx/xxxxxx">
</textbox><!-- onChanging="detailWindow.hasChanged()" -->
</row>
<row>
<label value="NX ULIS"></label>
<!-- <a:bind value="agentBean.noUlis" />-->
<textbox
id="Ulis"

constraint="/([0-9]+)?/:le NX ULIS doit avoir un format numerique"><!-- onChanging="detailWindow.hasChanged()" -->
</textbox>
</row>
<row>
<label value="Commentaire"></label>
<!-- <a:bind value="agentBean.commentaire" />-->
<textbox
onChanging="detailWindow.hasChanged()"
id="Commentaire"
width="100%"
rows="2">
<!-- onChanging="detailWindow.hasChanged()" -->
</textbox>
</row>
<row>
<label value="Metiers"></label>
<hbox width="100%">
<!-- <a:bind model="metiersListeDisponibles" /> -->
<listbox
id="lbMetiersDisponibles"
rows="3"
width="140"
height="80"
droppable="unRole"
onDrop="detailWindow.swap(event.dragged)">
<listhead>
<listheader
label="Role(s) disponible(s)">
</listheader>
</listhead>

</listbox>
<listbox
id="lbMetiersAssignes"
rows="3"
width="140"
height="80"
droppable="unRole"
onDrop="detailWindow.swap(event.dragged)">
<listhead>
<listheader
label="Role(s) assigne(s)">
</listheader>
</listhead>
</listbox>
</hbox>
</row>
<row>
<label value="Actif"></label>
<!-- <a:bind
checked="agentBean.swActif;converter:be.ciger.d121.neve.ui.neve.ActifType
Converter" />-->
<checkbox
id="Check"
checked="true"
>
</checkbox>
</row>
<row>
<label></label>
<hbox>
<button
id="btnValidate"
label="validate"
onClick="detailWindow.validateConstraintsInFields()"
disabled="false"
image="/images/icons/check.gif">
</button>
<button
id="btnBind"
label="bind"
onClick="detailWindow.bind()"
disabled="false"
image="/images/icons/check.gif">
</button>
<button
id="btnSetvals"
label="setvals"
onClick="detailWindow.setFieldsValues()"
disabled="false"
image="/images/icons/check.gif">
</button>
</hbox>
</row>
</rows>
</grid>
<window
id="errorWindow"
border="normal"
visible="false"
width="99%"
title="Messages d'erreurs">
<label
id="errorMessageZone"
multiline="true"
style="color:red; font-weight:900" />
</window>
</groupbox>
</window>

</zk>




/// java code


import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.zkoss.zk.ui.Page;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zkplus.databind.AnnotateDataBinder;
import org.zkoss.zkplus.spring.SpringUtil;
import org.zkoss.zul.Button;
import org.zkoss.zul.Checkbox;
import org.zkoss.zul.Label;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.Textbox;
import org.zkoss.zul.Window;

import be.ciger.d121.common.model.Para;
import be.ciger.d121.common.service.CommonManager;
import be.ciger.d121.neve.Constants;
import be.ciger.d121.regie.model.Agent;
import be.ciger.d121.regie.model.AgentRole;
import be.ciger.d121.regie.service.RegieManager;

public class AjoutEditVisuAgentWindow2 extends Window {
private String mode = "";
private boolean modified = false;


public void bind() {
//bind with new bean to
Agent agent= new Agent();
agent.setCommentaire("");
agent.setGsm("");
agent.setInitiales("");
agent.setMail("");
agent.setNom("");
agent.setNoUlis("");
agent.setPrenom("");
AnnotateDataBinder binder = new
AnnotateDataBinder(this.getDesktop().getPage("detailAgent").getFellow("detailWin
dow"));
binder.bindBean("agentBean", agent);
// this.getDesktop().getPage("detailAgent").setVariable("agentBean", agent);
binder.loadAll();
}

/**
* fonction qui pour un textbox donne, permet de concatener au msg, le
* message d'erreur eventuel recupere lors de la validation de ce champ.
*
* @param tb
* @param msg
* @return
*/
public String getErrorMessageIfInvalid(Textbox tb, String msg) {
String errMsg = msg;

if (!tb.isValid()) {
try {
// on force l'exception de vlidation
tb.getValue();
} catch (Exception e) {
// on recupere le message d'erreur venant de l'exception(celui
// sette dans la constraint dans le zul file.)
errMsg += "- " + tb.getId() + " :" + e.getMessage()
+ System.getProperty("line.separator");
}
}
return errMsg;
}

/**
* permet de mettre un message d'erreur dans le petit error window box.
*
* @param errMsg
*/
public void setErrorBoxMessage(String errMsg) {
((Label) getFellow("errorWindow").getFellow("errorMessageZone")).setValue(errM
sg);
getFellow("errorWindow").setVisible(true);
}

/**
* avant l'ajout et l'update, il faut s'assurer que le user a bien respecte
* les contraintes. fait partie de la double validation au moment du submit
*
* @return
*/
public boolean validateConstraintsInFields() {
String errMsg = "";

Textbox tb = (Textbox) this.getFellow("Initiales");
errMsg = getErrorMessageIfInvalid(tb, errMsg);

tb = (Textbox) this.getFellow("Nom");
errMsg = getErrorMessageIfInvalid(tb, errMsg);
tb = (Textbox) this.getFellow("Prenom");
errMsg = getErrorMessageIfInvalid(tb, errMsg);

tb = (Textbox) this.getFellow("Mail");
errMsg = getErrorMessageIfInvalid(tb, errMsg);

tb = (Textbox) this.getFellow("GSM");
errMsg = getErrorMessageIfInvalid(tb, errMsg);

tb = (Textbox) this.getFellow("Ulis");
errMsg = getErrorMessageIfInvalid(tb, errMsg);
//if (!errMsg.equals("")) {
setErrorBoxMessage(errMsg);
// return false;
// }
return true;
}

public void setFieldsValues() {
((Textbox) this.getFellow("Initiales")).setRawValue("");
((Textbox) this.getFellow("Initiales")).invalidate();
//((Textbox) this.getFellow("Initiales")).
((Textbox) this.getFellow("Nom")).setRawValue("");
((Textbox) this.getFellow("Nom")).invalidate();
((Textbox) this.getFellow("Prenom")).setRawValue("");
((Textbox) this.getFellow("Prenom")).invalidate();
((Textbox) this.getFellow("Mail")).setRawValue("");
((Textbox) this.getFellow("Mail")).invalidate();
((Textbox) this.getFellow("GSM")).setRawValue("");
((Textbox) this.getFellow("GSM")).invalidate();
((Textbox) this.getFellow("Ulis")).setRawValue("");
((Textbox) this.getFellow("Ulis")).invalidate();
((Textbox) this.getFellow("Commentaire")).setRawValue("");
((Textbox) this.getFellow("Commentaire")).invalidate();
((Checkbox) this.getFellow("Check")).setChecked(true);

}
}



/// bean code


import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import be.ciger.d121.common.model.Service;

public class Agent {

private Service service;
private List metiers = new ArrayList();



private Integer idAgent;

private Integer idService;

private String initiales;

private String nom;

private String prenom;

private String mail;

private String gsm;

private String noUlis;

private String commentaire;

private String swActif;

private String userCre;

private Date dateCre;

private String userMaj;

private Date dateMaj;

public Integer getIdAgent() {
return idAgent;
}

public void setIdAgent(Integer idAgent) {
this.idAgent = idAgent;
}

public Integer getIdService() {
return idService;
}

public void setIdService(Integer idService) {
this.idService = idService;
}

public String getInitiales() {
return initiales;
}

public void setInitiales(String initiales) {
this.initiales = initiales;
}


public String getNom() {
return nom;
}


public void setNom(String nom) {
this.nom = nom;
}

public String getPrenom() {
return prenom;
}

public void setPrenom(String prenom) {
this.prenom = prenom;
}

public String getMail() {
return mail;
}

public void setMail(String mail) {
this.mail = mail;
}

public String getGsm() {
return gsm;
}

public void setGsm(String gsm) {
this.gsm = gsm;
}

public String getNoUlis() {
return noUlis;
}

public void setNoUlis(String noUlis) {
this.noUlis = noUlis;
}

public String getCommentaire() {
return commentaire;
}

public void setCommentaire(String commentaire) {
this.commentaire = commentaire;
}

public String getSwActif() {
return swActif;
}

public void setSwActif(String swActif) {
this.swActif = swActif;
}

public String getUserCre() {
return userCre;
}

public void setUserCre(String userCre) {
this.userCre = userCre;
}

public Date getDateCre() {
return dateCre;
}

public void setDateCre(Date dateCre) {
this.dateCre = dateCre;
}

public String getUserMaj() {
return userMaj;
}

public void setUserMaj(String userMaj) {
this.userMaj = userMaj;
}

public Date getDateMaj() {
return dateMaj;
}

public void setDateMaj(Date dateMaj) {
this.dateMaj = dateMaj;
}

// methodes custom par Michael.
public List getMetiers() {
return metiers;
}

public void setMetiers(List metiers) {
this.metiers = metiers;
}

public Service getService() {
return service;
}

public void setService(Service service) {
this.service = service;
setIdService(service.getIdService());
}

}




delete flag offensive retag edit

3 Replies

Sort by ยป oldest newest

answered 2007-03-08 07:51:07 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4196626

By: mikomax

Hi,
Can you tell me if that behaviour is normal or not? can you also tell me how to avoid that behaviour?

thanks for all.

Michael.

link publish delete flag offensive edit

answered 2007-03-09 05:24:43 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4199151

By: robbiecheng

Please post this to bug list, and upload your reduced sample code, thx a lot

/robbie

link publish delete flag offensive edit

answered 2007-03-09 14:05:08 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4199729

By: mikomax

ok, I'll do that asap.

thank you for your support... have a nice WE.
Michael Planamente.

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: 2007-03-06 11:41:16 +0800

Seen: 1,381 times

Last updated: Mar 09 '07

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