Requirement Constraints

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

Wednesday, 10 April 2013

ZK MVVM Form Binding CRUD with Spring and Hibernate - Part 7

Posted on 04:22 by Unknown

Some more features.

        


So we have successfully completed our spring security integration with ZK Application as per the previous article.
In this post, we will add some more features to our application.

Define System Level users.
In the standard login based application, always there will be some users are defined as system and the end users of the application cannot modify or Delete those users from the system. That’s what we are going to do now.

As a first step, in the mysql table, add one more column as shown

image

As you can see, we have given default value for this column as zero. So any user created thru the application will have zero value. So users having system=0 will be treated as normal user and users having system=1 will be treated as system normal users. So in the back end itself, make some users are system by changing the value to 1.

Next step, we need add this new column in our domain object. In the zkexample.domain.UserProfile.java add this and include the getter and setter as shown.

private Integer system;

public Integer getSystem() {
return system;
}

public void setSystem(Integer system) {
this.system = system;
}


Next step, we need to modify our userList.zul. For system users, we will NOT show EDIT and DELETE action. We will only allow View option.
And also, we will see how we can use ZK Popup component for this use case.(Please refer here and here). For system users, we will show one more question mark image with popup bind to inform the user about this.

Update style.css


/* Start: Action Images- Auditlog
---------------------------------------------- */
.fImageAudit {
width: 25px;
background-image: url('../images/AuditLog.jpg');
background-repeat: no-repeat;
border: 0 none;
cursor: pointer;
}

And you need to have the QuestionmarkButton-16x16.png in the images folder
Here is the modified zul file



<?page title="Users List" contentType="text/html;charset=UTF-8"?>
<zk>
<window id="userList" border="none" height="80%" width="96%"
apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('zkexample.zkoss.UserListVM')">
<separator />
<separator />
<div width="100%">
<div sclass="sectionTitle">
<separator />
<label value="Users" sclass="sectionTitleLabel" />
<separator />
</div>
<div style="float:right">
<button label="Add New" onClick="@command('onAddNew')"
mold="trendy" sclass="mybutton button blue small" />
<button label="Logout" mold="trendy" id="btnlogout"
sclass="mybutton button blue small" onClick="@command('Logout')" />
</div>
<div style="clear: both;"></div>
<div sclass="sectionSeperator"></div>
</div>
<separator />
<listbox id="" mold="paging" pageSize="11" pagingPosition="top"
sclass="mylist" selectedItem="@bind(vm.selectedItem)"
model="@load(vm.dataSet)">
<listhead sizable="true">
<listheader label="First Name" sortDirection="ascending"
sort="auto(firstName)" />
<listheader label="Last Name" sort="auto(lastName)" />
<listheader label="Email" sort="auto(email)" />
<listheader label="Login ID" sort="auto(userLoginID)" />
<listheader label="Action" />
</listhead>
<template name="model" var="p1">
<listitem>
<listcell label="@load(p1.firstName)" />
<listcell label="@load(p1.lastName)" />
<listcell label="@load(p1.email)" />
<listcell label="@load(p1.userLoginID)" />
<listcell>
<hbox spacing="20px">
<image
onClick="@command('onEdit',userRecord=p1)" sclass="fimageedit"
visible="@load(p1.system eq 0)"
tooltiptext="To Edit the user details">
</image>
<image
onClick="@command('openAsReadOnly',userRecord=p1)"
sclass="fimageView" tooltiptext="To view the user details">
</image>
<image
tooltip="msgPopup, position=before_start, delay=500" sclass="fImageSystem"
visible="@load(p1.system eq 1)" />
<image
onClick="@command('onDelete',userRecord=p1)"
visible="@load(p1.system eq 0)" sclass="fimageDelete"
tooltiptext="To Delete the user ">
</image>
</hbox>
</listcell>
</listitem>
</template>
</listbox>
<popup id="msgPopup">
<label id="msg"
value="Sytem defined user. Edit and Delete are not allowed.">
</label>
</popup>
</window>
</zk>


List Data Filter.
Next we will add data filter option as shown in ZK Demo here. First let us add datafilter class in our project. Create one more class named as Datafilter under the zkoss package as shown.
image


package zkexample.zkoss;

public class DataFilter {

private String code = "";
private String firstName = "";
private String lastName = "";
private String email = "";
private String loginID= "";

public String getCode() {
return code;
}

public void setCode(String code) {
this.code = code == null ? "" : code.trim();
}

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName == null ? "" : firstName.trim();
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName == null ? "" : lastName.trim();
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email == null ? "" : email.trim();
}

public String getLoginID() {
return loginID;
}

public void setLoginID(String loginID) {
this.loginID = loginID == null ? "" : loginID.trim();
}

}

Next we need to add auxhead in our listing file. Here is the modified userList.zul and UserListVM

UserList.zul


<?page title="Users List" contentType="text/html;charset=UTF-8"?>
<zk>
<window id="userList" border="none" height="80%" width="96%"
apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('zkexample.zkoss.UserListVM')">
<separator />
<separator />
<div width="100%">
<div sclass="sectionTitle">
<separator />
<label value="Users" sclass="sectionTitleLabel" />
<separator />
</div>
<div style="float:right">
<button label="Add New" onClick="@command('onAddNew')"
mold="trendy" sclass="mybutton button blue small" />
<button label="Logout" mold="trendy" id="btnlogout"
sclass="mybutton button blue small" onClick="@command('Logout')" />
</div>
<div style="clear: both;"></div>
<div sclass="sectionSeperator"></div>
</div>
<separator />
<listbox id="" mold="paging" pageSize="11" pagingPosition="top"
sclass="mylist" selectedItem="@bind(vm.selectedItem)"
model="@load(vm.dataSet)">
<auxhead>
<auxheader colspan="1">
<image sclass="fImageFilter" />
<textbox cols="30" mold="rounded"
value="@bind(vm.dataFilter.firstName)"
onChange="@command('doFilter')" instant="true" />
</auxheader>
<auxheader colspan="1">
<image sclass="fImageFilter" />
<textbox cols="30" mold="rounded"
value="@bind(vm.dataFilter.lastName)"
onChange="@command('doFilter')" instant="true" />
</auxheader>
<auxheader colspan="1">
<image sclass="fImageFilter" />
<textbox cols="30" mold="rounded"
value="@bind(vm.dataFilter.email)" onChange="@command('doFilter')"
instant="true" />
</auxheader>
<auxheader colspan="1">
<image sclass="fImageFilter" />
<textbox cols="33" mold="rounded"
value="@bind(vm.dataFilter.loginID)"
onChange="@command('doFilter')" instant="true" />
</auxheader>

</auxhead>
<listhead sizable="true">
<listheader label="First Name" sortDirection="ascending"
sort="auto(firstName)" />
<listheader label="Last Name" sort="auto(lastName)" />
<listheader label="Email" sort="auto(email)" />
<listheader label="Login ID" sort="auto(userLoginID)" />
<listheader label="Action" />
</listhead>
<template name="model" var="p1">
<listitem>
<listcell label="@load(p1.firstName)" />
<listcell label="@load(p1.lastName)" />
<listcell label="@load(p1.email)" />
<listcell label="@load(p1.userLoginID)" />
<listcell>
<hbox spacing="20px">
<image
onClick="@command('onEdit',userRecord=p1)" sclass="fimageedit"
visible="@load(p1.system eq 0)"
tooltiptext="To Edit the user details">
</image>
<image
onClick="@command('openAsReadOnly',userRecord=p1)"
sclass="fimageView" tooltiptext="To view the user details">
</image>
<image
tooltip="msgPopup, position=before_start, delay=500"
sclass="fImageSystem" visible="@load(p1.system eq 1)" />
<image
onClick="@command('onDelete',userRecord=p1)"
visible="@load(p1.system eq 0)" sclass="fimageDelete"
tooltiptext="To Delete the user ">
</image>
</hbox>
</listcell>
</listitem>
</template>
</listbox>
<popup id="msgPopup">
<label id="msg"
value="Sytem defined user. Edit and Delete are not allowed.">
</label>
</popup>
</window>
</zk>

UserListVM


package zkexample.zkoss;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import org.zkoss.bind.BindUtils;
import org.zkoss.bind.annotation.AfterCompose;
import org.zkoss.bind.annotation.BindingParam;
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.NotifyChange;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.select.Selectors;
import org.zkoss.zk.ui.select.annotation.WireVariable;
import org.zkoss.zkplus.spring.SpringUtil;
import org.zkoss.zul.Center;
import org.zkoss.zul.Messagebox;

import zkexample.domain.UserProfile;
import zkexample.service.CRUDService;

public class UserListVM {

private Center centerArea;
private DataFilter dataFilter = new DataFilter();

@WireVariable
private CRUDService CRUDService;

private UserProfile selectedItem;
private List<UserProfile> allReordsInDB = null;
private List<UserProfile> userList = null;

public UserProfile getSelectedItem() {
return selectedItem;
}

public void setSelectedItem(UserProfile selectedItem) {
this.selectedItem = selectedItem;
}

public DataFilter getDataFilter() {
return dataFilter;
}

public void setDataFilter(DataFilter dataFilter) {
this.dataFilter = dataFilter;
}

@AfterCompose
public void initSetup(@ContextParam(ContextType.VIEW) Component view,
@ExecutionArgParam("centerArea") Center centerArea) {
Selectors.wireComponents(view, this, false);
this.centerArea = centerArea;
CRUDService = (CRUDService) SpringUtil.getBean("CRUDService");
allReordsInDB = CRUDService.getAll(UserProfile.class);
userList = new ArrayList<UserProfile>((allReordsInDB));

}

public List<UserProfile> getDataSet() {
return allReordsInDB;
}

@Command
public void onAddNew() {
final HashMap<String, Object> map = new HashMap<String, Object>();
map.put("selectedRecord", null);
map.put("recordMode", "NEW");
map.put("centerArea", centerArea);
centerArea.getChildren().clear();
Executions.createComponents("UserCRUD.zul", centerArea, map);
}

@Command
public void onEdit(@BindingParam("userRecord") UserProfile userProfile) {

final HashMap<String, Object> map = new HashMap<String, Object>();
map.put("selectedRecord", userProfile);
map.put("recordMode", "EDIT");
map.put("centerArea", centerArea);
centerArea.getChildren().clear();
Executions.createComponents("UserCRUD.zul", centerArea, map);
}

@Command
public void openAsReadOnly(
@BindingParam("userRecord") UserProfile userProfile) {

final HashMap<String, Object> map = new HashMap<String, Object>();
map.put("selectedRecord", userProfile);
map.put("recordMode", "READ");
map.put("centerArea", centerArea);
centerArea.getChildren().clear();
Executions.createComponents("UserCRUD.zul", centerArea, map);
}

@SuppressWarnings({ "rawtypes", "unchecked" })
@Command
public void onDelete(@BindingParam("userRecord") UserProfile userProfile) {
int OkCancel;
this.selectedItem = userProfile;
String str = "The Selected \"" + userProfile.getUserLoginID()
+ "\" will be deleted.";
OkCancel = Messagebox.show(str, "Confirm", Messagebox.OK
| Messagebox.CANCEL, Messagebox.QUESTION);
if (OkCancel == Messagebox.CANCEL) {
return;
}

str = "The \""
+ userProfile.getUserLoginID()
+ "\" will be permanently deleted and the action cannot be undone.";

Messagebox.show(str, "Confirm", Messagebox.OK | Messagebox.CANCEL,
Messagebox.QUESTION, new EventListener() {
public void onEvent(Event event) throws Exception {
if (((Integer) event.getData()).intValue() == Messagebox.OK) {

CRUDService.delete(selectedItem);
allReordsInDB.remove(allReordsInDB
.indexOf(selectedItem));
BindUtils.postNotifyChange(null, null,
UserListVM.this, "dataSet");

}
}
});
}

@NotifyChange("dataSet")
@Command
public void doFilter() {
allReordsInDB = new ArrayList<UserProfile>();;
for (Iterator<UserProfile> i = userList.iterator(); i.hasNext();) {
UserProfile tmp = i.next();
if (tmp.getFirstName().toLowerCase()
.indexOf(dataFilter.getFirstName().toLowerCase()) == 0
&& tmp.getLastName().toLowerCase()
.indexOf(dataFilter.getLastName().toLowerCase()) == 0
&& tmp.getEmail().toLowerCase()
.indexOf(dataFilter.getEmail().toLowerCase()) == 0
&& tmp.getUserLoginID().toLowerCase()
.indexOf(dataFilter.getLoginID().toLowerCase()) == 0) {
allReordsInDB.add(tmp);

}
}

}

@Command
public void Logout() {
Executions.sendRedirect("/j_spring_security_logout");
}

}


Now the output will be as shown.
image

In the next part 8, ZK Theme customization for each user
You can download the source here.



        

Email ThisBlogThis!Share to XShare to Facebook
Posted in | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (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...
  • 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...
  • 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...
  • 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...
  • 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...
  • ZK Border Layout–Another example
    This examples show how you can use ZK Border Layout to show the product information on clicking image. ZK Version 6 Project Name : BorderL...
  • 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...
  • Good Website Design Links
    Form Design Label Placement in Forms International Address Fields in Web Forms 40 Eye-Catching Registration Pages blog-comment-form-...
  • ZK MVVM Form Binding CRUD with Spring and Hibernate - Part 4
    Presentation Layer using ZK Framework          In part 3 , We have completed Spring integration with hibernate. In this post, we will des...

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)
      • EDI 270–5010 Documentation - ISA – Interchange Con...
      • EDI 270 - 5010 Health Care Eligibility/Benefit Inq...
      • ZK MVVM Form Binding CRUD with Spring and Hibernate
      • ZK MVVM Form Binding CRUD with Spring and Hibernat...
      • Login form CSS
      • ZK MVVM Form Binding CRUD with Spring and Hibernat...
      • ZK MVVM Form Binding CRUD with Spring and Hibernat...
      • ZK MVVM Form Binding CRUD with Spring and Hibernat...
      • ZK MVVM Form Binding CRUD with Spring and Hibernat...
      • ZK + Spring Security Custom Login form
      • ZK + Spring Security Login form–Part 5
      • ZK MVC CRUD With Spring 3 + JPA + Hibernate 4 Enti...
      • Medical Billing Process in detail
      • Clearing House
    • ►  March (19)
    • ►  February (21)
    • ►  January (13)
  • ►  2012 (177)
    • ►  December (1)
    • ►  November (13)
    • ►  October (19)
    • ►  September (24)
    • ►  August (26)
    • ►  July (6)
    • ►  June (37)
    • ►  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