Monday, February 25, 2013

ZK pass values in ViewModel Without removing focus from textbox

I was facing some issue like i have a textbox and when user will enter some values in textbox and doubleclick inside textbox then the same time value o send value to ViewModel ....

Thursday, February 21, 2013

ZK forEach with Template

Here you can see how we can use forEach with template...

Tuesday, February 5, 2013

ZK Set desire selection in Listbox model

If someone want when a Zk listbox render in browser a item will be default selected for achieving this you can run this demo code.. ZUL file..... And Viewmodel or Java class for this demo example... In this example you can see this code.. this method will do selection the item in listbox which you would like ... For more Information you can refer..ZK Official document

For Senthil Question

Monday, February 4, 2013

ZK KeyStroke event with Windows Component in Java

If you do not like my previous post Zk KeyStroke Event where iused ZScript to show example but lots of developer do not like ZScript even i am not comfortable with Zscript even in my project i disable Zscript feature . Here i would like to show how can you capture which CTRL key pressed by user in ZUL page and capture that Key in your class file then you can follow the below demo example.... ZUL Code for this Demo
<?page title="new page title" contentType="text/html;charset=UTF-8"?>
<zk>
 <window title="new page title" border="normal" id="inp"
  viewModel="@id('vm') @init('com.team.MyListbox')" apply="org.zkoss.bind.BindComposer" ctrlKeys="^a^s^d#f8" onCtrlKey="@command('ctrlKeyClick',item=event.getKeyCode())">
  <button label="AddItem" onClick="@command('addNewItem')"  ></button>
   
  <listbox model="@bind(vm.dataList)">
   <listhead>
    <listheader value="A"></listheader>
    <listheader value="B"></listheader>
    <listheader value="C"></listheader>

   </listhead>
   <template name="model" var="mymodel">
    <listitem>
     <listcell>

      <textbox value="@bind(mymodel.a)" />
     </listcell>
     <listcell>
      <label value="@bind(mymodel.b)" />

     </listcell>
     <listcell>
      <label value="@bind(mymodel.c)" />

     </listcell>
    </listitem>
   </template>
  </listbox>
 </window>
</zk>
And Java Code for this demo
package com.team;

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

import org.zkoss.bind.annotation.AfterCompose;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.ContextParam;
import org.zkoss.bind.annotation.ContextType;
import org.zkoss.bind.annotation.NotifyChange;
import org.zkoss.zhtml.Messagebox;
import org.zkoss.zk.ui.Component;


public class MyListbox  {

 private List dataList;

 @AfterCompose
 public void afterCompose(@ContextParam(ContextType.VIEW) Component view) {
  try {
   dataList = new ArrayList();
   Data data;
   data = new Data("a1", "b1", "c1");
   dataList.add(data);
   data = new Data("a2", "b2", "c2");
   dataList.add(data);
   data = new Data("a3", "b3", "c3");
   dataList.add(data);
  } catch (Exception e) {

  }
 }

 @Command
 public void ctrlKeyClick(@org.zkoss.bind.annotation.BindingParam("item") String ctekKeyCode ){
   int keyCode =Integer.parseInt(ctekKeyCode);
         String s = "";
         switch(keyCode){
             case 65: s = "Ctrl+A";break;
             case 119: s = "F8";break;
             case 83:s="Ctrl+S";break;
             case 68:s="Ctrl+D";break;
         }
         Messagebox.show(s+" is pressed", "CtrlKey",
                 Messagebox.OK, Messagebox.EXCLAMATION);
  System.out.println("I am clicked");
 }
 
 @Command
 @NotifyChange("dataList")
 public void addNewItem(){
  Data data = new Data("", "", "");
  dataList.add(data);
 }
 public List getDataList() {
  return dataList;
 }

 public void setDataList(List dataList) {
  this.dataList = dataList;
 }

 public class Data {
  String a;
  String b;
  String c;
  public String getA() {
   return a;
  }
  public String getB() {
   return b;
  }
  public String getC() {
   return c;
  }
  public void setA(String a) {
   this.a = a;
  }
  public void setB(String b) {
   this.b = b;
  }
  public void setC(String c) {
   this.c = c;
  }
  public Data(String a, String b, String c) {
   super();
   this.a = a;
   this.b = b;
   this.c = c;
  }

 }
}

ZK KeyStroke event with Windows Component in ZUL

ZK provide KeyStroke event we can see how can we add these KeyStroke event with windows in ZUL..
<?page title="new page title" contentType="text/html;charset=UTF-8"?>
<zk>
 <window title="new page title" border="normal" id="inp"
    ctrlKeys="^a^s^d#f8"  attribute name="onOK"><![CDATA[
                        Messagebox.show("ENTER key is pressed", "OK",
                                Messagebox.OK, Messagebox.EXCLAMATION);
                        self.focus();
                    ]]></attribute>
                    <attribute name="onCancel"><![CDATA[
                        Messagebox.show("ESC key is pressed", "CANCEL",
                                Messagebox.OK, Messagebox.EXCLAMATION);
                        self.focus();
                    ]]></attribute>
                    <attribute name="onCtrlKey"><![CDATA[
                        int keyCode = ((KeyEvent) event).getKeyCode();
                        System.out.println(keyCode);
                        String s = "";
                        switch(keyCode){
                            case 65: s = "Ctrl+A";break;
                            case 119: s = "F8";break;
                            case 83:s="Ctrl+S";break;
                            case 68:s="Ctrl+D";break;
                        }
                        Messagebox.show(s+" is pressed", "CtrlKey",
                                Messagebox.OK, Messagebox.EXCLAMATION);
                        inp.focus();
                    ]]></attribute>
   
  
  
 </window>
</zk>

ZK Listbox add a new item

Today we will see how can we add a new item when user click on a button for this you can follow this example... ZUL file code for this And Java class or viewmodel for this... for any issue please leave a comment.