Requirement Constraints

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Wednesday, 27 June 2012

Combo Box– Show images for Items based on some condition

Posted on 20:05 by Unknown

We will see how we can also show the images for the combo items bases on some conditions.

ZK Version 6
Project Name : ComboItemIcons
Project Structure:

image

Demo.zul

<?page title="new page title" contentType="text/html;charset=UTF-8"?>
<zk>
<window id="myWin" title="new page title" border="normal"
apply="org.zkoss.bind.BindComposer"
viewModel="@id('myvm') @init('mydomainUI.DemoVM')">
Users:
<combobox model="@load(myvm.allUsers)">
<template name="model" var="p1">
<comboitem label="@load(p1.userName)"
image="@load(p1.active eq 'Y' ? './img/active.png' : './img/inactive.png')"
value="@load(p1.userCode)" />
</template>
</combobox>
</window>
</zk>


users.java


package mydomain;

public class users {

private String userCode;
private String userName;
private String userPassword;
private String active;
private String firstName;
private String lastName;
private String homePhone;
private String mobilePhone;

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public String getHomePhone() {
return homePhone;
}

public void setHomePhone(String homePhone) {
this.homePhone = homePhone;
}

public String getMobilePhone() {
return mobilePhone;
}

public void setMobilePhone(String mobilePhone) {
this.mobilePhone = mobilePhone;
}

public String getUserCode() {
return userCode;
}

public void setUserCode(String userCode) {
this.userCode = userCode;
}

public String getUserName() {
return userName;
}

public void setUserName(String userName) {
this.userName = userName;
}

public String getUserPassword() {
return userPassword;
}

public void setUserPassword(String userPassword) {
this.userPassword = userPassword;
}

public String getActive() {
return active;
}

public void setActive(String active) {
this.active = active;
}

}


usersDAO.java


package domainDAO;

import java.util.ArrayList;
import java.util.List;
import mydomain.users;

public class usersDAO {

public List<users> getUsers() {

List<users> allUsers = new ArrayList<users>();

users u1 = new users();
u1.setUserName("John");
u1.setUserCode("User101");
u1.setUserPassword("xxxxx");
u1.setFirstName("JohnFirstName");
u1.setLastName("JohnLastName");
u1.setHomePhone("1111111111");
u1.setMobilePhone("222222");
u1.setActive("Y");
allUsers.add(u1);

u1 = new users();
u1.setUserName("Robert");
u1.setUserCode("User102");
u1.setUserPassword("xxxxx");
u1.setActive("Y");
u1.setFirstName("RobertFirstName");
u1.setLastName("RobertLastName");
u1.setHomePhone("53534343");
u1.setMobilePhone("4534343");
allUsers.add(u1);

u1 = new users();
u1.setUserName("Sean");
u1.setUserCode("User105");
u1.setUserPassword("xxxxx");
u1.setFirstName("SeanFirstName");
u1.setLastName("SeanLastName");
u1.setHomePhone("1111111111");
u1.setMobilePhone("222222");
u1.setActive("Y");
allUsers.add(u1);

u1 = new users();
u1.setUserName("Marry");
u1.setUserCode("User112");
u1.setUserPassword("xxxxx");
u1.setActive("N");
u1.setFirstName("MarryFirstName");
u1.setLastName("MarryLastName");
u1.setHomePhone("53534343");
u1.setMobilePhone("4534343");
allUsers.add(u1);

return allUsers;
}

}


DemoVM.java


package mydomainUI;

import java.util.ArrayList;
import java.util.List;
import org.zkoss.bind.annotation.Init;

import domainDAO.usersDAO;
import mydomain.users;

public class DemoVM {

private List<users> allUsers = new ArrayList<users>();

public List<users> getAllUsers() {
return allUsers;
}

public void setAllUsers(List<users> allUsers) {
this.allUsers = allUsers;
}


@Init
public void initSetup() {
// Load the department first
allUsers = new usersDAO().getUsers();

}

}


Now you can run demo.zul. The output as follows


image



You can download source here

Read More
Posted in ZK MVVM Combo | No comments

Tuesday, 26 June 2012

ZK Border Layout–Another example

Posted on 23:04 by Unknown

This examples show how you can use ZK Border Layout to show the product information on clicking image.

ZK Version 6
Project Name : BorderLayout2
Project Structure:

image

Output:

image

Demo.zul

<zk>

<window border="none" width="100%" height="100%" id="main">
<separator />
<div left="20px" height="25px">
<image src="/images/zklogo_s.png"
style="padding-left: 10px;" height="30px" width="auto" />
</div>
<separator />
<borderlayout id="mainlayout">
<north border="normal" height="70px">
<div id="Menu" sclass="Mainmenudiv">
<include src="mainmenu.zul" />
</div>
</north>
<west title=" " size="20%" flex="true" splittable="true"
collapsible="true">
<div id="nav" style="background:white; height:100%">
<include src="navmenu.zul" />
</div>
</west>
<center border="normal">
<div height="99%" id="Screen"></div>
</center>
<south height="70px">
<div align="center">
<label
value="Copyright © 2012 xxxxxxxx All Rights Reserved. Powered By xxxxx"
sclass="loginlabel" />
</div>
</south>
</borderlayout>
</window>
</zk>

mainmenu.zul
<?page title="Main Menu" contentType="text/html;charset=UTF-8"?>
<zk>
<label value="Welcome to ZK" style="color: #696569; font-size : 34px; font-weight: bold;" />
</zk>

navmenu.zul
<?page title="Method3"?>

<zk>
<style>
.z-groupbox-3d-hm { background-image: none; background-color:
#0A246A !important; } .z-groupbox-3d-header .z-caption { color:
yellow; font-weight: bold;; } .z-groupbox-3d-cnt{
background-image: none; background-color: #EAECF0 !important; }

.open-true {float:right; background:url('img/UP201.png')
no-repeat right 0; height: 16px; padding-right: 20px;
font-weight: bold; }

.open-false {float:right; background:url('img/Down201.png')
no-repeat right 0; height: 16px; padding-right: 20px;
font-weight: bold; }

</style>
<window title="Administration" border="normal" width="270px"
apply="mydomain.democomposer">
<groupbox width="250px" mold="3d">
<attribute name="onOpen"><![CDATA[
arrow1.setSclass("open-" + self.isOpen());
]]></attribute>
<caption label="Products">
<div id="arrow1" class="open-true"></div>
</caption>

<vbox>
<image id = "product1" src="/img/product1.png" forward="onClick=onClickMenu()"
style="padding-left: 10px; cursor: pointer" height="100px" width="auto" />
<separator bar="true" width="250px"/>
<image id = "product2" src="/img/product2.png" forward="onClick=onClickMenu()"
style="padding-left: 10px; cursor: pointer" height="100px" width="auto" />
<separator bar="true" width="250px"/>
<image id = "product3" src="/img/product3.png" forward="onClick=onClickMenu()"
style="padding-left: 10px; cursor: pointer" height="100px" width="auto" />
<separator bar="true" width="250px"/>

</vbox>
</groupbox>

</window>
</zk>


product1.zul


<?page title="Main Menu" contentType="text/html;charset=UTF-8"?>
<zk>
<label value="Product 1 Information goes here" style="color: #696569; font-size : 34px; font-weight: bold;" />
</zk>

product2.zul
<?page title="Main Menu" contentType="text/html;charset=UTF-8"?>
<zk>
<label value="Product 2 Information goes here" style="color: #696569; font-size : 34px; font-weight: bold;" />
</zk>

product3.zul
<?page title="Main Menu" contentType="text/html;charset=UTF-8"?>
<zk>
<label value="Product 3 Information goes here" style="color: #696569; font-size : 34px; font-weight: bold;" />
</zk>


democomposer.java


package mydomain;

import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.MouseEvent;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.Path;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.Borderlayout;
import org.zkoss.zul.Center;
import org.zkoss.zul.Messagebox;

public class democomposer extends GenericForwardComposer {

public void onClickMenu(MouseEvent event) {

String zulFilePathName;
Borderlayout bl = (Borderlayout) Path.getComponent("/main/mainlayout");
/* get an instance of the searched CENTER layout area */
Center center = bl.getCenter();

/* clear the center child comps */
center.getChildren().clear();

//Messagebox.show("inside" + event.getTarget().getId());
zulFilePathName = event.getTarget().getId() + ".zul";
/* create the page and put it in the center layout area */
Executions.createComponents(zulFilePathName, center, null);
}
}


You can download source here

Read More
Posted in ZK Layout | No comments

Monday, 25 June 2012

MVVM–List Item–Hibernate–MySQL–Part 3

Posted on 17:49 by Unknown

Note: This is continuation of my previous article Part 2.  Please click here to go to Part 2

In this Part 3, we will enhance our Listing and model window as follows

1. We will include one more column as last named as Actions. This action will contain image such as edit, activate and delete.
2. We will also give hyperlink for the first column. If the user clicks the first column, then we will show the information in the read-only and if the user clicks the edit image in the action column, then we will show the information in the read only and will allow the user to edit and save.

image

Project Structure

image

Demo.zul

<?page title="Listitem MVVM Demo with Hibernate" contentType="text/html;charset=UTF-8"?>
<zk>
<style>
.z-listcell.red .z-listcell-cnt, .z-label.red{ color:red; }

/* Start: Action Images- Edit
---------------------------------------------- */

.fimageedit { width: 25px; background-image:
url('./images/icon-edit.png'); background-repeat: no-repeat;
border: 0 none; cursor: pointer; }

/* End: Action Images - Edit
---------------------------------------------- */


/* Start: Action Images- Delete
---------------------------------------------- */

.fimageDelete { width: 25px; background-image:
url('./images/icon-trash-red.png'); background-repeat:
no-repeat; border: 0 none; cursor: pointer; }

/* End: Action Images - Delete
---------------------------------------------- */


/* Start: Action Images- Active
---------------------------------------------- */

.fimageActive { width: 25px; background-image:
url('./images/icon-enable.png'); background-repeat: no-repeat;
border: 0 none; cursor: pointer; }

/* End: Action Images - Active
---------------------------------------------- */

/* Start: Action Images- Inactive' ]

---------------------------------------------- */

.fimageInactive { width: 25px; background-image:
url('./images/icon-disable.png'); background-repeat: no-repeat;
border: 0 none; cursor: pointer; }

/* End: Action Images - InActive
---------------------------------------------- */

.z-listcell.highlightcell .z-listcell-cnt,
.z-label.highlightcell { color:blue; cursor: pointer; }


</style>
<window title="Listitem MVVM Demo with Hibernate" border="normal"
apply="org.zkoss.bind.BindComposer"
viewModel="@id('myvm') @init('domainVMS.PersonVM')">
<div>
<button label="Add Person"
onClick="@command('addNewPerson')" />
</div>
<separator />

<listbox id="test" model="@load(myvm.allPersons)"
selectedItem="@bind(myvm.curSelectedPerson)">
<listhead sizable="true">
<listheader label="First Name" width="400px"
sort="auto(firstName)" />
<listheader label="Last Name" width="285px"
sort="auto(lastName)" />
<listheader label="email" width="285px"
sort="auto(email)" />
<listheader label="Action" />
</listhead>
<template name="model" var="p1">
<listitem>
<listcell label="@load(p1.firstName)"
onClick="@command('openAsReadOnly')" sclass="highlightcell" />
<listcell label="@load(p1.lastName)"
sclass="@load(empty p1.email ?'red':'')" />
<listcell label="@load(p1.email)" />
<listcell>
<hbox spacing="20px">
<image sclass="fimageActive" />
<image sclass="fimageDelete" />
<image sclass="fimageedit"
onClick="@command('editThisPerson')" />
</hbox>
</listcell>
</listitem>
</template>
</listbox>
</window>
</zk>



PersonVM.java

package domainVMS;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import mydomain.Person;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.Init;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zul.Messagebox;
import domainDAO.PersonDAO;
import org.zkoss.bind.annotation.BindingParam;
import org.zkoss.bind.annotation.GlobalCommand;
import org.zkoss.bind.annotation.NotifyChange;

public class PersonVM {

private List<Person> persons = new ArrayList<Person>();
private Person curSelectedPerson;

public Person getCurSelectedPerson() {
return curSelectedPerson;
}

public void setCurSelectedPerson(Person curSelectedPerson) {
this.curSelectedPerson = curSelectedPerson;
}

public List<Person> getallPersons() {
return persons;
}

@Init
public void initSetup() {
persons = new PersonDAO().getAllPersons();

}

@Command
public void editThisPerson () {
final HashMap<String, Object> map = new HashMap<String, Object>();
map.put("selectedPerson", curSelectedPerson);
map.put("recordMode", "EDIT");
Executions.createComponents("AddPerson.zul", null, map);
}

@Command
public void openAsReadOnly()
{
final HashMap<String, Object> map = new HashMap<String, Object>();
map.put("recordMode", "READ");
map.put("selectedPerson", curSelectedPerson);
Executions.createComponents("AddPerson.zul", null, map);

}

@Command
public void addNewPerson() {
final HashMap<String, Object> map = new HashMap<String, Object>();
map.put("selectedPerson", null);
map.put("recordMode", "NEW");
Executions.createComponents("AddPerson.zul", null, map);
}


//note this will be executed after when we new person from the model window
@GlobalCommand
@NotifyChange("allPersons")
public void refreshList(@BindingParam("newadded") Person p1)
{
persons.add(p1);
}

}


PersonCRUDVM.java


package domainVMS;

import java.util.HashMap;
import org.zkoss.zul.Button;
import java.util.List;
import java.util.Map;
import org.zkoss.bind.BindUtils;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.ContextParam;
import org.zkoss.bind.annotation.ContextType;
import org.zkoss.bind.annotation.ExecutionArgParam;
import org.zkoss.bind.annotation.Init;
import org.zkoss.bind.annotation.NotifyChange;
import org.zkoss.zul.Messagebox;
import org.zkoss.zk.ui.Component;
import domainDAO.PersonDAO;
import mydomain.Person;
import org.zkoss.zk.ui.select.Selectors;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zul.Window;
import org.zkoss.zul.impl.InputElement;

public class PersonCRUDVM {

@Wire("#win")
private Window win;
@Wire
private Button submit;
@Wire
private Button cancel;
@Wire("textbox")
List<InputElement> inputs;

private Person selectedPerson;

public Person getSelectedPerson() {
return selectedPerson;
}

public void setSelectedPerson(Person selectedPerson) {
this.selectedPerson = selectedPerson;
}

@Init
public void initSetup(@ContextParam(ContextType.VIEW) Component view,
@ExecutionArgParam("selectedPerson") Person selectedPerson,
@ExecutionArgParam("recordMode") String recordMode) {
Selectors.wireComponents(view, this, false);
if (selectedPerson == null)
this.selectedPerson = new Person();
else
this.selectedPerson = selectedPerson;

if (recordMode == "READ") {
submit.setVisible(false);
cancel.setLabel("Ok");
for (InputElement i : inputs)
i.setReadonly(true);
win.setTitle(win.getTitle() + " (Readonly)");
}

}

@Command
public void save() {
new PersonDAO().saveOrUpdate(this.selectedPerson);
Map args = new HashMap();
args.put("newadded", this.selectedPerson);
BindUtils.postGlobalCommand(null, null, "refreshList", args);
win.detach();
}

@Command
public void closeThis() {
win.detach();
}
}


AddPerson.zul


<zk>
<window id="win" title="Person" width="520px" height="220px"
border="normal" minimizable="false" mode="modal" maximizable="false"
closable="true" action="show: slideDown;hide: slideUp"
apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('domainVMS.PersonCRUDVM')" >
<separator />
<label value="Person information" />
<separator />
<panel width="100%">
<panelchildren>
<separator />
<grid width="99.5%">
<columns>
<column label="" width="150px" />
<column label="" />
</columns>
<rows>
<row>
<hbox>
<label value="First Name" />
<label value="*" />
</hbox>
<textbox name="firstName"
value="@bind(vm.selectedPerson.firstName)" cols="50" />
</row>
<row>
<hbox>
<label value="Last Name" />
<label value="*" />
</hbox>
<textbox name="firstName"
value="@bind(vm.selectedPerson.lastName)" cols="50" />
</row>
<row>
<hbox>
<label value="email" />
<label value="*" />
</hbox>
<textbox name="email"
value="@bind(vm.selectedPerson.email)" cols="50" />
</row>
</rows>
</grid>
</panelchildren>
</panel>
<separator />
<div align="center">
<button id="submit" label="Submit" onClick="@command('save')" />
<button id="cancel" label="Cancel" onClick="@command('closeThis')" />
</div>
</window>
</zk>



Download the source as war file




Download as individual files as follows

hibernate.cfg.xml
Person.java
HibernateUtil.java
PersonVM.java
PersonCRUDVM.java
PersonDAO.java
icon-trash-red.png
icon-edit.png
icon-enable.png
Demo.zul
AddPerson.zul
Read More
Posted in ZK MVVM ListBox | No comments

Saturday, 23 June 2012

C Workbook

Posted on 21:55 by Unknown

In the year 1999-2002, I was working as faculty in a computer center. During that period, I developed a small VB Application to explain the concept of C. Here are the some screenshots from that VB Project

image

 

image

 

image

 

image

 

image

 

image

Read More
Posted in C Workbook | No comments

Friday, 22 June 2012

MVVM Modal window–Pass Parameter and Return values

Posted on 19:39 by Unknown

In this post, we will see how we can pass some values to the modal window when calling from the parent window and also vice versa (i.e) return some values from the modal window to parent window

 

Project Name : MVVMModalWindow
Project Structure:

image

Demo.zul

<?page title="new page title" contentType="text/html;charset=UTF-8"?>
<zk>
<window title="MVVM Modal window Passing arguments and retur values"
border="normal" apply="org.zkoss.bind.BindComposer"
viewModel="@id('e') @init('com.demo.UI.demoVM')">
Type any value and Press the Model Window Button
<separator />
Value 1 :
<textbox value="@bind(e.value1)" />
Value 2 :
<textbox value="@bind(e.value2)" />
<button label="Model Window" onClick="@command('showModelWin')" />
</window>
</zk>

 

demoVM.java

 

package com.demo.UI;

import java.util.HashMap;

import org.zkoss.bind.annotation.BindingParam;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.GlobalCommand;
import org.zkoss.zk.ui.Executions;
import org.zkoss.bind.annotation.NotifyChange;

public class demoVM {

private String value1;
private String value2;


public String getValue1() {
return value1;
}

public void setValue1(String value1) {
this.value1 = value1;
}

public String getValue2() {
return value2;
}

public void setValue2(String value2) {
this.value2 = value2;
}

@Command
public void showModelWin()
{
final HashMap<String, Object> map = new HashMap<String, Object>();
map.put("value1", this.value1 );
map.put("value2", this.value2);
Executions.createComponents("ModelWindow.zul", null, map);
}

@GlobalCommand
@NotifyChange({"value1","value2"})
public void refreshvalues(@BindingParam("returnvalue1") String str1, @BindingParam("returnvalue2") String str2)
{
this.value1 = str1;
this.value2 = str2;
}
}


ModelWindow.zul

<?page title="new page title" contentType="text/html;charset=UTF-8"?>
<zk>

<window id="modalDialog"
title="MVVM Modal window Passing arguments and retur values"
width="420px" height="auto" border="normal" minimizable="false"
mode="modal" maximizable="false" closable="true"
action="hide: slideUp" apply="org.zkoss.bind.BindComposer"
onCancel="@command('closeThis')"
viewModel="@id('e') @init('com.demo.UI.ModelWindowVM')">

Change the values and Press the Ok Button to return changed
values.
<separator />
Value 1 :
<textbox value="@bind(e.value1)" />
Value 2 :
<textbox value="@bind(e.value2)" />
<button label="Ok" onClick="@command('save')" />
</window>
</zk>


ModelWindowVM.java

 


package com.demo.UI;

import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.ContextParam;
import org.zkoss.bind.annotation.ContextType;
import org.zkoss.bind.annotation.ExecutionArgParam;
import org.zkoss.bind.annotation.Init;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.select.Selectors;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zul.Window;
import java.util.HashMap;
import org.zkoss.bind.BindUtils;
import java.util.Map;

public class ModelWindowVM {

@Wire("#modalDialog")
private Window win;
private String value1;
private String value2;


public String getValue1() {
return value1;
}

public void setValue1(String value1) {
this.value1 = value1;
}

public String getValue2() {
return value2;
}

public void setValue2(String value2) {
this.value2 = value2;
}

@Init
public void init(@ContextParam(ContextType.VIEW) Component view,
@ExecutionArgParam("value1") String v1,
@ExecutionArgParam("value2") String v2) {
Selectors.wireComponents(view, this, false);
this.value1 = v1;
this.value2 = v2;

}

@SuppressWarnings({ "unchecked", "rawtypes" })
@Command
public void save() {
Map args = new HashMap();
args.put("returnvalue1", this.value1);
args.put("returnvalue2", this.value2);
BindUtils.postGlobalCommand(null, null, "refreshvalues", args);
win.detach();
}

@Command
public void closeThis() {
win.detach();
}
}


Now you can run the demo.zul file
Read More
Posted in ZK MVVM | No comments

Wednesday, 20 June 2012

C++ Workbook

Posted on 19:19 by Unknown
In the year 1999-2002, I was working as faculty in a computer center. During that period, I developed a small VB Application to explain the concept of C++. Here are the some screenshots from that VB Project
Home Page
image
Chapters List
image
Sample Program
image

image

image
Read More
Posted in C Workbook, C++ Workbook | No comments

Monday, 18 June 2012

ZK Border Layout–Menu on the left and content on the right.

Posted on 10:45 by Unknown

In this post, let us see how we can load all our project menu in the left and on click of each of menu, then we will load individual zul file on the right side. Here, we are going to use border layout, where north border going to content menu and west border will be used to load the individual zul file.

Left hugMany thanks Stephan who helped me to complete this task. Here is the forum thread
http://www.zkoss.org/forum/listComment/18840-Menu-Links-on-Left-Side-and-Page-Content-on-Right-Side?lang=en

ZK Version : ZK 6

Project Name :BorderLayout

Project Structure;

image

Demo.zul

<zk>

<window border="none" width="100%" height="100%" id="main">
<separator />
<div left="20px" height="25px">
<image src="/images/zklogo_s.png"
style="padding-left: 10px;" height="30px" width="auto" />
</div>
<separator />
<borderlayout id="mainlayout">
<north border="normal" height="70px">
<div id="Menu" sclass="Mainmenudiv">
<include src="mainmenu.zul" />
</div>
</north>
<west title=" " size="20%" flex="true" splittable="true"
collapsible="true">
<div id="nav" style="background:white; height:100%">
<include src="navmenu.zul" />
</div>
</west>
<center border="normal">
<div height="99%" id="Screen"></div>
</center>
<south height="70px">
<div align="center">
<label
value="Copyright © 2012 xxxxxxxx All Rights Reserved. Powered By xxxxx"
sclass="loginlabel" />
</div>
</south>
</borderlayout>
</window>
</zk>


democomposer.java


package mydomain;

import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.MouseEvent;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.Path;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.Borderlayout;
import org.zkoss.zul.Center;
import org.zkoss.zul.Messagebox;

public class democomposer extends GenericForwardComposer {

public void onClickMenu(MouseEvent event) {

String zulFilePathName;
Borderlayout bl = (Borderlayout) Path.getComponent("/main/mainlayout");
/* get an instance of the searched CENTER layout area */
Center center = bl.getCenter();

/* clear the center child comps */
center.getChildren().clear();

//Messagebox.show("inside" + event.getTarget().getId());
zulFilePathName = event.getTarget().getId() + ".zul";
/* create the page and put it in the center layout area */
Executions.createComponents(zulFilePathName, center, null);
}
}


zk.zul



<?page title="Main Menu" contentType="text/html;charset=UTF-8"?>
<zk>
<label value="ZK Contents goes here" style="color: #696569; font-size : 34px; font-weight: bold;" />
</zk>

 


blog.zul



<?page title="Main Menu" contentType="text/html;charset=UTF-8"?>
<zk>
<label value="ZK blog Contents goes here" style="color: #696569; font-size : 34px; font-weight: bold;" />
</zk>


Contributors.zul


<?page title="Main Menu" contentType="text/html;charset=UTF-8"?>
<zk>
<label value="ZK Contributors Contents goes here" style="color: #696569; font-size : 34px; font-weight: bold;" />
</zk>


forum.zul


<?page title="Main Menu" contentType="text/html;charset=UTF-8"?>
<zk>
<label value="ZK forum goes here" style="color: #696569; font-size : 34px; font-weight: bold;" />
</zk>


mainmenu.zul


<?page title="Main Menu" contentType="text/html;charset=UTF-8"?>
<zk>
<label value="Welcome to ZK" style="color: #696569; font-size : 34px; font-weight: bold;" />
</zk>


navmenu.zul


<?page title="Method3"?>

<zk>
<style>
.z-groupbox-3d-hm { background-image: none; background-color:
#0A246A !important; } .z-groupbox-3d-header .z-caption { color:
yellow; font-weight: bold;; } .z-groupbox-3d-cnt{
background-image: none; background-color: #EAECF0 !important; }

.open-true {float:right; background:url('img/UP201.png')
no-repeat right 0; height: 16px; padding-right: 20px;
font-weight: bold; }

.open-false {float:right; background:url('img/Down201.png')
no-repeat right 0; height: 16px; padding-right: 20px;
font-weight: bold; }

</style>
<window title="Administration" border="normal" width="270px" apply="mydomain.democomposer">
<groupbox width="250px" mold="3d">
<attribute name="onOpen"><![CDATA[
arrow1.setSclass("open-" + self.isOpen());
]]></attribute>
<caption label="Products">
<div id="arrow1" class="open-true"></div>
</caption>

<vbox>
<toolbarbutton id="ZK" label="ZK" forward="onClick=onClickMenu()"/>
<toolbarbutton id="ZkStudio" label="ZK Studio" forward="onClick=onClickMenu()"/>
<toolbarbutton id="ZkSpring" label="ZK Spring" forward="onClick=onClickMenu()"/>
<toolbarbutton id="ZKSpread" label="ZK SpreadSheet" forward="onClick=onClickMenu()"/>
</vbox>
</groupbox>
<groupbox width="250px" mold="3d">
<attribute name="onOpen"><![CDATA[
arrow2.setSclass("open-" + self.isOpen());
]]></attribute>
<caption label="ZK Demo">
<div id="arrow2" class="open-true"></div>
</caption>

<vbox>
<toolbarbutton id="ZKCalender"
label="ZK Calender" forward="onClick=onClickMenu()"/>
<toolbarbutton id="ZKWebmail" label="ZK Web Mail" forward="onClick=onClickMenu()"/>
<toolbarbutton id="ZKSandbox"
label="ZK Sand Box" forward="onClick=onClickMenu()"/>
<toolbarbutton id="ZKPiv" label="ZK Pivottable" forward="onClick=onClickMenu()"/>
</vbox>
</groupbox>
<groupbox width="250px" mold="3d">
<attribute name="onOpen"><![CDATA[
arrow.setSclass("open-" + self.isOpen());
]]></attribute>
<caption label="Community">
<div id="arrow" class="open-true"></div>
</caption>

<vbox>
<toolbarbutton id="forum"
label="forum" forward="onClick=onClickMenu()"/>
<toolbarbutton id="blog"
label="Blog" forward="onClick=onClickMenu()"/>
<toolbarbutton id="Contributors"
label="ZK Contributors" forward="onClick=onClickMenu()"/>
</vbox>
</groupbox>

</window>
</zk>


ZKCalender.zul


<?page title="Main Menu" contentType="text/html;charset=UTF-8"?>
<zk>
<label value="ZK calender contents goes here" style="color: #696569; font-size : 34px; font-weight: bold;" />
</zk>


ZKPiv.zul


<?page title="Main Menu" contentType="text/html;charset=UTF-8"?>
<zk>
<label value="ZK pivottable contents goes here" style="color: #696569; font-size : 34px; font-weight: bold;" />
</zk>


ZKSandbox.zul


<?page title="Main Menu" contentType="text/html;charset=UTF-8"?>
<zk>
<label value="ZK sandbox goes here" style="color: #696569; font-size : 34px; font-weight: bold;" />
</zk>


ZKSpread.zul


<?page title="Main Menu" contentType="text/html;charset=UTF-8"?>
<zk>
<label value="ZK spreadsheet content goes here" style="color: #696569; font-size : 34px; font-weight: bold;" />
</zk>


ZkSpring.zul


<?page title="Main Menu" contentType="text/html;charset=UTF-8"?>
<zk>
<label value="ZK spring content goes here" style="color: #696569; font-size : 34px; font-weight: bold;" />
</zk>


Now run the demo.zul and Click on the links on the left menu


image


Click here to see the demo


Download the source as war file

Read More
Posted in ZK Layout | No comments

Sunday, 17 June 2012

MVVM–List Item–Hibernate–MySQL–Part 2

Posted on 23:56 by Unknown
In the part 1, we have seen, how to list the records from DB using ZK List box. Now let us go further and see how we can add new record and edit exiting record and update into DB.
In this post, we will see how we can do the following stuffs
1. Add new person by calling a model window in MVVM and update in the DB
2. On Double click of the records in the list item, edit the existing record by calling a modal window in MVVM and update in the DB
3. Then after edit and add, we will refresh the list. Note, after edit, we no need to do anything, because data binding will take care. But after adding new person, we will refresh the list using Global command

Left hug     Many thanks to potix Jimmy who helped me to complete this part 2. http://www.zkoss.org/forum/listComment/19829-ZK-MVVM-Modal-Window

ZK Version : ZK 6

Project Name :ListItemMVVMHibernate

Project Structure;

image

Demo.zul



<?page title="Listitem MVVM Demo with Hibernate" contentType="text/html;charset=UTF-8"?>
<zk>
<style>
.z-listcell.red .z-listcell-cnt, .z-label.red{ color:red; }
</style>
<window title="Listitem MVVM Demo with Hibernate" border="normal"
apply="org.zkoss.bind.BindComposer"
viewModel="@id('myvm') @init('domainVMS.PersonVM')">
<div>
<button label="Add Person"
onClick="@command('addNewPerson')" />
</div>
<separator />

<listbox id="test" model="@load(myvm.allPersons)"
selectedItem="@bind(myvm.curSelectedPerson)">
<listhead sizable="true">
<listheader label="First Name" width="400px"
sort="auto(firstName)" />
<listheader label="Last Name" width="285px"
sort="auto(lastName)" />
<listheader label="email" width="285px"
sort="auto(email)" />
</listhead>
<template name="model" var="p1">
<listitem onDoubleClick="@command('onDoubleClicked')">
<listcell label="@load(p1.firstName)"
sclass="@load(empty p1.email ?'red':'')" />
<listcell label="@load(p1.lastName)"
sclass="@load(empty p1.email ?'red':'')" />
<listcell label="@load(p1.email)" />
</listitem>
</template>
</listbox>
</window>
</zk>



AddPerson.zul

<zk>
<window id="win" title=" " width="520px" height="220px"
border="normal" minimizable="false" mode="modal" maximizable="false"
closable="true" action="show: slideDown;hide: slideUp"
apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('domainVMS.PersonCRUDVM')" >
<separator />
<label value="Person information" />
<separator />
<panel width="100%">
<panelchildren>
<separator />
<grid width="99.5%">
<columns>
<column label="" width="150px" />
<column label="" />
</columns>
<rows>
<row>
<hbox>
<label value="First Name" />
<label value="*" />
</hbox>
<textbox name="firstName"
value="@bind(vm.selectedPerson.firstName)" cols="50" />
</row>
<row>
<hbox>
<label value="Last Name" />
<label value="*" />
</hbox>
<textbox name="firstName"
value="@bind(vm.selectedPerson.lastName)" cols="50" />
</row>
<row>
<hbox>
<label value="email" />
<label value="*" />
</hbox>
<textbox name="email"
value="@bind(vm.selectedPerson.email)" cols="50" />
</row>
</rows>
</grid>
</panelchildren>
</panel>
<separator />
<div align="center">
<button label="Submit" onClick="@command('save')" />
<button label="Cancel" onClick="@command('closeThis')" />
</div>
</window>
</zk>



PersonDAO.java

package domainDAO;

import java.util.List;
import org.hibernate.Session;
import org.hibernate.Query;
import org.zkoss.zul.Messagebox;

import HibernateUtilities.HibernateUtil;
import mydomain.Person;

public class PersonDAO {

@SuppressWarnings("unchecked")
public List<Person> getAllPersons() {
List<Person> allrecords = null;
try {
Session session = HibernateUtil.beginTransaction();
Query q1 = session.createQuery("from Person");
allrecords = q1.list();
HibernateUtil.CommitTransaction();
} catch (RuntimeException e) {
e.printStackTrace();
}
return allrecords;
}

public void saveOrUpdate(Person p1) {

try {
Session session = HibernateUtil.beginTransaction();
session.saveOrUpdate(p1);
HibernateUtil.CommitTransaction();
} catch (RuntimeException e) {
e.printStackTrace();
}

}
}


PersonCRUDVM.java


package domainVMS;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.zkoss.bind.BindUtils;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.ContextParam;
import org.zkoss.bind.annotation.ContextType;
import org.zkoss.bind.annotation.ExecutionArgParam;
import org.zkoss.bind.annotation.Init;
import org.zkoss.bind.annotation.NotifyChange;
import org.zkoss.zul.Messagebox;
import org.zkoss.zk.ui.Component;
import domainDAO.PersonDAO;
import mydomain.Person;
import org.zkoss.zk.ui.select.Selectors;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zul.Window;

public class PersonCRUDVM {

@Wire("#win")
private Window win;

private Person selectedPerson;

public Person getSelectedPerson() {
return selectedPerson;
}

public void setSelectedPerson(Person selectedPerson) {
this.selectedPerson = selectedPerson;
}

@Init
public void initSetup(@ContextParam(ContextType.VIEW) Component view, @ExecutionArgParam("selectedPerson") Person selectedPerson) {
Selectors.wireComponents(view, this, false);
if (selectedPerson == null)
this.selectedPerson = new Person();
else
this.selectedPerson = selectedPerson;

}

@Command
public void save() {
new PersonDAO().saveOrUpdate(this.selectedPerson);
Map args = new HashMap();
args.put("newadded", this.selectedPerson);
BindUtils.postGlobalCommand(null, null, "refreshList", args);
win.detach();
}

@Command
public void closeThis() {
win.detach();
}
}


PersonVM.java


package domainVMS;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import mydomain.Person;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.Init;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zul.Messagebox;
import domainDAO.PersonDAO;
import org.zkoss.bind.annotation.BindingParam;
import org.zkoss.bind.annotation.GlobalCommand;
import org.zkoss.bind.annotation.NotifyChange;

public class PersonVM {

private List<Person> persons = new ArrayList<Person>();
private Person curSelectedPerson;

public Person getCurSelectedPerson() {
return curSelectedPerson;
}

public void setCurSelectedPerson(Person curSelectedPerson) {
this.curSelectedPerson = curSelectedPerson;
}

public List<Person> getallPersons() {
return persons;
}

@Init
public void initSetup() {
persons = new PersonDAO().getAllPersons();

}

@Command
public void onDoubleClicked() {
final HashMap<String, Object> map = new HashMap<String, Object>();
map.put("selectedPerson", curSelectedPerson);
Executions.createComponents("AddPerson.zul", null, map);
}

@Command
public void addNewPerson() {
final HashMap<String, Object> map = new HashMap<String, Object>();
map.put("selectedPerson", null);
Executions.createComponents("AddPerson.zul", null, map);
}

//note this will be executed after when we new person from the model window
@GlobalCommand
@NotifyChange("allPersons")
public void refreshList(@BindingParam("newadded") Person p1)
{
persons.add(p1);
}

}




HibernateUtil.java

package HibernateUtilities;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;

public class HibernateUtil {

private static SessionFactory factory;
private static ServiceRegistry serviceRegistry;

public static Configuration getInitConfiguration() {
Configuration config = new Configuration();
config.configure();
return config;
}

public static Session getSession() {
if (factory == null) {
Configuration config = HibernateUtil.getInitConfiguration();
serviceRegistry = new ServiceRegistryBuilder().applySettings(
config.getProperties()).buildServiceRegistry();
factory = config.buildSessionFactory(serviceRegistry);
}
Session hibernateSession = factory.getCurrentSession();
return hibernateSession;
}

public static Session beginTransaction() {
Session hibernateSession;
hibernateSession = HibernateUtil.getSession();
hibernateSession.beginTransaction();
return hibernateSession;
}

public static void CommitTransaction() {
HibernateUtil.getSession().getTransaction().commit();
}

public static void closeSession() {
HibernateUtil.getSession().close();
}

public static void rollbackTransaction() {
HibernateUtil.getSession().getTransaction().rollback();
}

}



Now you can run the demo.zul. And click Add Person to add new person or double click any one of the list items to edit.

image

Download the source as war file

continued on next post - Part 3

Read More
Posted in ZK MVVM ListBox | No comments
Newer Posts Older Posts Home
Subscribe to: Posts (Atom)

Popular Posts

  • ZK Example for inline Editing with Add New and Delete
    I am quite impressed on this demo from ZK . But adding new record and delete existing record is missing as part of typical CRUD. So i thoug...
  • EDI 5010 Documentation 837 Professional - Loop 2010BB Payer Name
    2010BB Payer Name          In this loop, all the information will be taken from Insurance master screen. Take a look of our sample screen...
  • EDI 5010 Documentation–837 - BHT - Beginning of Hierarchical Transaction
    BHT – Beginning of Hierarchical Transaction Loop Seg ID Segment Name Format Length Ref# Req Value   BHT Beginning of Hier...
  • Hibernate Validator Example 2
    In this example, we will see some more validation constraints such as @email, @past, @length, etc. And also we will also define custom error...
  • ZK Passing Parameter between two files using MVVM–Part 1
    Overview This is the first series of articles about Passing parameter between two zul files using MVVM Design pattern .This article will fo...
  • MVVM Command annotation and Notify change example
    Here is an example, how to pass parameter on a zul through MVVM Command binding annotation. ZK URL http://books.zkoss.org/wiki/ZK%20Develo...
  • History of Present Illness
    HPI - One of the main component of Clinical History. What is an HPI ? The history of present illness (HPI) is a chronological description...
  • Patient Demographics
    Patient browse (search) is the key element for any EMR / PMS Software. In my past 15 years experience, i involved more than 5 times in desig...
  • ViewModel Class Java Annotation @Init, @NotifyChange, @Command
    In following sections we'll list all syntaxes that can be used in implementing a ViewModel and applying ZK bind annotation. The ZK binde...
  • Good Website Design Links
    Form Design Label Placement in Forms International Address Fields in Web Forms 40 Eye-Catching Registration Pages blog-comment-form-...

Categories

  • Billing Process
  • C Workbook
  • C++ Workbook
  • Eclipse Tips
  • EDI 5010
  • EMR Appointment Features
  • EMR Labs Stuff
  • EMR PMS Links
  • EMR Use cases
  • EMR Vital Sign
  • Good Website Design
  • Hibernate Criteria Queries
  • Hibernate Introduction
  • Hibernate Introduction Setup
  • Hibernate Mapping
  • Hibernate POC
  • Hibernate Validator
  • Hibernate–Java Environment setup
  • HPI
  • Java
  • Maven
  • MU Certification
  • NPI
  • PQRS
  • Practice Management System
  • Spring Security
  • Tech Links
  • Today Tech Stuff
  • zk
  • ZK Hibernate
  • ZK 5 Databinding
  • ZK Application
  • ZK Calling Another ZUL
  • ZK CheckBox
  • ZK CreateComponents
  • ZK CSS
  • ZK extended Components
  • ZK Foreach
  • ZK Forum Posts
  • ZK Framework
  • ZK Hibernate Setup
  • ZK ID Space
  • ZK Include
  • ZK Installation
  • ZK iReport
  • ZK Layout
  • ZK Listitem Pagination
  • ZK Message Box
  • ZK MVC
  • ZK MVC Combox Box
  • ZK MVC CRUD Examples
  • ZK MVC Listbox
  • ZK MVVM
  • ZK MVVM Combo
  • ZK MVVM CRUD
  • ZK MVVM ListBox
  • ZK Spring
  • ZK TextBox

Blog Archive

  • ►  2013 (105)
    • ►  December (3)
    • ►  September (7)
    • ►  August (13)
    • ►  July (1)
    • ►  June (11)
    • ►  May (3)
    • ►  April (14)
    • ►  March (19)
    • ►  February (21)
    • ►  January (13)
  • ▼  2012 (177)
    • ►  December (1)
    • ►  November (13)
    • ►  October (19)
    • ►  September (24)
    • ►  August (26)
    • ►  July (6)
    • ▼  June (37)
      • Combo Box– Show images for Items based on some con...
      • ZK Border Layout–Another example
      • MVVM–List Item–Hibernate–MySQL–Part 3
      • C Workbook
      • MVVM Modal window–Pass Parameter and Return values
      • C++ Workbook
      • ZK Border Layout–Menu on the left and content on t...
      • MVVM–List Item–Hibernate–MySQL–Part 2
      • Charge Entry Screen
      • Practice management System– PMS–Billing
      • Phone Box–Using j Query and Extending ZK Textbox
      • MVC Two combo Box – Fill second combo based on fir...
      • MVVM Two combo Box – Fill second combo based on fi...
      • MVVM–List Item–Hibernate–MySQL–Part 1
      • MVC Combo Box Data binding
      • MVVM Combo Box Data binding
      • List Item Double click event on selected Item usin...
      • MVVM Example for Form Validation
      • List Item on Select, show more details by using se...
      • List item Change background color for some particu...
      • List Item Double click event on selected Item
      • ViewModel Class Java Annotation @Init, @NotifyChan...
      • ZK MVVM CRUD - Part 3
      • ZK MVVM CRUD - Part 2
      • Select only few columns in Hibernate create query API
      • ZK MVVM CRUD - Part 1
      • Java List and ArrayList
      • Annotate non persistent properties with the @Trans...
      • MVVM Example 3–List item
      • Tab box with tool bar CSS
      • Change the location of the label in radio element
      • Hibernate 4.1.1 will create the column if we missp...
      • MVC–CRUD Application with ZK 5 Data Binding
      • Hibernate–Java Environment setup
      • How to refer CSS File in ZK Style tag
      • MVVM Examples–Example 2
      • MVVM Examples–Example 1
    • ►  May (30)
    • ►  April (16)
    • ►  March (1)
    • ►  January (4)
  • ►  2011 (5)
    • ►  December (1)
    • ►  November (1)
    • ►  July (1)
    • ►  June (1)
    • ►  April (1)
  • ►  2010 (1)
    • ►  September (1)
Powered by Blogger.

About Me

Unknown
View my complete profile