0

how to print error message on screen when condition from controller is false?

asked 2013-05-24 07:53:58 +0800

demizon gravatar image demizon
179 1 6

updated 2013-05-24 08:12:49 +0800

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

delete flag offensive retag edit

Comments

it works, thx!

demizon ( 2013-05-24 13:10:01 +0800 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2013-05-24 10:52:26 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

I think you can do following code for this..

if(personExist==0) {
Messagebox.show("Person not Exist", "Error", Messagebox.OK, Messagebox.ERROR);
}
link publish delete flag offensive edit
Your answer
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
1 follower

RSS

Stats

Asked: 2013-05-24 07:53:58 +0800

Seen: 33 times

Last updated: May 24 '13

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