-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi, I got following problem..
I have application to add records into DB, dialog consists of 2 textboxes- "personID","code" and submitbutton. At the moment when I write in proper personID into PersonID textbox, some string to code textbox and press submitbutton, record is saved into DB, but when i write in code, bad personID(personID doesnt exist in table) and press submitbutton nothings happen(code is not recorded into table-i have condition in controller source code, which controls if personID exists in DB), but what i want to do is to show error message like "ERROR person is not in db..." something like: if (personID not in DB){send error to zul file}
here is my zul file:
<window title="Tlac etikiet" border="normal" apply="generator.GenController" >
kod:<textbox constraint="no empty" id="keywordBox" />
ID pracovnika:<textbox constraint="no empty" id="personBox" />
<button id="genButton" label="OK" />
</window>
GenController.java:
package generator;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.select.SelectorComposer;
import org.zkoss.zk.ui.select.annotation.*;
import org.zkoss.zul.*;
import java.sql.*;
public class GenController extends SelectorComposer<Component> {
@Wire
private Label countPag, countVw;
@Wire
private Textbox keywordBox;
@Wire
private Textbox personBox;
public void generateNr(int personId,String code){
try {
//...connect to db code...
if(personExist==0) {
................................I WANT HERE TO ADD CODE THAT WILL SEND ERROR MSG TO ZUL FILE (to browser screen)...........................
}
//if person ID exists in DB
else{
String delimiter = ",";
String[] temp;
temp = code.split(delimiter);
for(int i =0; i < temp.length ; i++)
System.out.println(temp[i]);
int numOfKz= Integer.parseInt(temp[1]);
int listNr= Integer.parseInt(temp[2]);
//upadete count in table KZ_TYP
String queryKz_typUpd="UPDATE KZ_TYP SET last_count = last_count+"+numOfKz+"WHERE name = "+temp[0];
PreparedStatement pstmt = con.prepareStatement(queryKz_typUpd);
pstmt.executeUpdate();
//insert new records in table KZ
for(int i =0; i < numOfKz ; i++){
String queryKzInsert = "INSERT INTO kz (kz_nr, kunden_nr, ma_nr, create_time) VALUES("+kz_nr+", "+kundenId+", "+personId+", NOW())";
PreparedStatement pstmtInsert= con.prepareStatement(queryKzInsert);
pstmtInsert.executeUpdate();
}
}
con.close();
} catch (ClassNotFoundException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
catch (SQLException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
@Listen("onClick = #genButton")
public void genButton(){
int persId = Integer.parseInt(personBox.getValue());
String code = personBox.getValue();
generateNr(persId, code);
}
}
thank you for your help
I think you can do following code for this..
if(personExist==0) {
Messagebox.show("Person not Exist", "Error", Messagebox.OK, Messagebox.ERROR);
}
Asked: 2013-05-24 07:53:58 +0800
Seen: 33 times
Last updated: May 24 '13
Problem binding values to a composite component
How to access static member field of a class in zul without zscript
How can i load a constant in .zul
MVVM Validator: class not found ? [closed]
MVVM tab box - delay @load until tab pane displayed?
mvvm, load or save with after or before for seach command
how to fire an event when a variable value loaded through VM
is there any event trigger from zk component on binding ?
ZK team plans to dispose of Composer EventQueues no longer in scope? [closed]
it works, thx!
demizon ( 2013-05-24 13:10:01 +0800 )edit