X12 EDI Examples
C++ Workbook
ZK Border Layout–Menu on the left and content on the right.
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.
Many 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
MVVM–List Item–Hibernate–MySQL–Part 2
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
Practice management System– PMS–Billing
Last year I was involved in developing an independent system for PMS using VB6 with sql server 2005. I really enjoyed myself and love to work/complete that project. One of my best period in my life. But unfortunately, we could not able to market the product because of VB6 no longer used widely in the industry.
Here are some of the screens which I like most in my development of VB6
Phone Box–Using j Query and Extending ZK Textbox
Summary
In this post, we will see how we can use jquery with ZK for US Phone number format. And also later on, we will see how we can this as a reusable component by extending the ZK Textbox
Thanks to the following ZK Forum and all the contributors who helped me to create this articlehttp://www.zkoss.org/forum/listComment/17490-How-to-apply-a-mask-in-a-Textbox-not-rendered-by-a-zul-file
MVC Two combo Box – Fill second combo based on first combo selection
We will see how to fill the second combo box based on first combo box selection using MVC Data binding.
MVVM Two combo Box – Fill second combo based on first combo selection
We will see how to fill the second combo box based on first combo box selection using MVVM Data binding.
MVVM–List Item–Hibernate–MySQL–Part 1
In every application, we will always have the listing page where we can list the records from the DB, from there another model window will be used to Add/Edit records.
In this post, we will see how we can do the following stuffs
1. Bind the List Item Using New zk 6 Data binding with MVVM Pattern
2. Retrieve the values from the DB – Mysql using Hibernate as ORM Tool.
3. How to change the color of the particular row based on some condition.
4. How to handle double click event on the List item.
5. How to sort the values in the List Item.
MVC Combo Box Data binding
List Item Double click event on selected Item using MVVM
MVVM Example for Form Validation
List Item on Select, show more details by using selectedItem
List item Change background color for some particular items based on some conditions
List Item Double click event on selected Item
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.
ZK MVVM CRUD - Part 3
Previous Part 2
In Part 2, we slightly change the retrieve of objects by adding constructor. Now we will move forward. Let us take a look on the output as follows
Apart from the listing the records, we also have two search parameters such as Practice name and Show only active or inactive practices. So what we are going to do with this ? Well, if the list is big, then user has to move to particular page to locate the desired practice, instead of that we will filter the practice as soon as user starts typing the first few characters of the practice name. And also, by default we will show all the active (soft delete) records. If the user want to see all the records including deactivated, then on click of check box, we will also do that.
So here are the conditions
Case 1:
If no character present in the Practice name filter text area and also Show only active is unchecked, then let us show all the records from the DB.
Case 2:
If some characters are typed in the practice name filter and check box is unchecked, then show all active and inactive records for the practice whose first characters are matched with the filter text
Case 3:
If no character in practice name filter text area and check box is checked, then we will show all the active practices only.
Case 4:
If both the search parameters contains values, then we will retrieve the records accordingly.
And also, we are going to Apply new ZK Bind Annotation such as @NotifyChange and @Command. Please refer here for examples in this subject.
And also very important, we are not going hit the database for each character is typed or check box is checked or unchecked. First time we will hit the DB to bring the records and then we will do all the filter locally.
Step 1:
From the View, we need to pass the value of Practice name text area and Check box state (checked or unchecked) to the View Model to filter the record. So we will write the following getter and setter method.
private String practiceStartWith;
private boolean showOnlyActive;
public String getPracticeStartWith() {
return practiceStartWith;
}
public void setPracticeStartWith(String practiceStartWith) {
this.practiceStartWith = practiceStartWith;
}
public boolean isShowOnlyActive() {
return showOnlyActive;
}
public void setShowOnlyActive(boolean showOnlyActive) {
this.showOnlyActive = showOnlyActive;
}
Step 2:
Here is the modified PracticeVM.Javapackage UIVMs; import domain.Practice; import java.util.ArrayList; import java.util.List; import org.zkoss.bind.annotation.Command; import org.zkoss.bind.annotation.NotifyChange; import DomainDAO.practiceDAO; public class PracticeListVM { private List<Practice> AllPracticeInDB = null; private List<Practice> filteredPractices = null; private String practiceStartWith; private boolean showOnlyActive = true; public String getPracticeStartWith() { return practiceStartWith; } public void setPracticeStartWith(String practiceStartWith) { this.practiceStartWith = practiceStartWith; } public boolean isShowOnlyActive() { return showOnlyActive; } public void setShowOnlyActive(boolean pActive) { this.showOnlyActive = pActive; } public List<Practice> getprlist() { if (AllPracticeInDB == null) { filteredPractices = new ArrayList<Practice>(); AllPracticeInDB = new practiceDAO().getListingItems(); setShowOnlyActive(true); for (Practice item : AllPracticeInDB) { if (item.getIsActive() == 1) filteredPractices.add(item); } } return filteredPractices; } @NotifyChange("prlist") @Command public void doFilter() { filteredPractices.clear(); /* if no filter characters and check box is un checked. Then get all */ /* 0 and 0 */ if ((practiceStartWith == null || "".equals(practiceStartWith)) && (showOnlyActive == false)) { filteredPractices.addAll(AllPracticeInDB); } /* * if there are filter characters and check box is un checked. Then get * filtered by filter text */ /* 1 and 0 */ if ((practiceStartWith != null && !practiceStartWith.equals("")) && (showOnlyActive == false)) { for (Practice item : AllPracticeInDB) { if (item.getPracticeName().toLowerCase() .indexOf(practiceStartWith.toLowerCase()) == 0) filteredPractices.add(item); } } /* * if no filter characters and check box is checked. Then get only * active practices */ /* 0 and 1 */ if ((practiceStartWith == null || "".equals(practiceStartWith)) && (showOnlyActive == true)) { for (Practice item : AllPracticeInDB) { if (item.getIsActive() == 1) filteredPractices.add(item); } } /* * Both Contains values i.e filter contains some text and check box is * checked */ /* 1 and 1 */ if ((practiceStartWith != null && !practiceStartWith.equals("")) && (showOnlyActive == true)) { for (Practice item : AllPracticeInDB) { if (item.getPracticeName().toLowerCase() .indexOf(practiceStartWith.toLowerCase()) == 0) if (item.getIsActive() == 1) filteredPractices.add(item); } } } }
Step 3:
Here is the modified practiceList.zul
<?page title="Practice List" contentType="text/html;charset=UTF-8"?> <zk> <window apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('UIVMs.PracticeListVM')"> <div> <button label="Add Practice" /> </div> <separator /> <groupbox height="40px"> <label value="Practice Name" /> <space /> <space /> <textbox width="250px" value="@bind(vm.practiceStartWith)" onChange="@command('doFilter')" instant="true" /> <button id="gobutton" label="Go" /> <space spacing="20px" /> <checkbox id="activechk" label="Show only active" checked="@bind(vm.showOnlyActive)" onCheck="@command('doFilter')" /> <space spacing="20px" /> </groupbox> <separator /> <listbox id="PracticeList" model="@load(vm.prlist)"> <listhead sizable="true"> <listheader label="Practice Name" sort="auto" /> <listheader label="City" sort="auto" /> <listheader label="State" sort="auto" /> <listheader label="Zip Code" sort="auto" /> </listhead> <template name="model" var="p1"> <listitem> <listcell label="@load(p1.practiceName)" /> <listcell label="@load(p1.city)" /> <listcell label="@load(p1.state)" /> <listcell label="@load(p1.zipCode)" /> </listitem> </template> </listbox> </window> </zk>
Step 4:
Now we can run and play around both practice name filter and check box.
The following is the execution flow
1. An Instance will be created for our PracticeListVM
2. Since we declared true value initially for showonlyactive, and also we bind our checkbox with showactiveonly, so first set method of showonlyactive will take place.
3. Then our getprList will take place because we bind our list to this get method.
ZK MVVM CRUD - Part 2
Previous Part 1
In the part 1, we have listed all the records from the DB.
I would like to do some changes in the Part 1 without adding any other stuff. Open PracticeDAO. Java and let us have a close look on the following line;
Query q1 = session.createQuery("from Practice ");
Here, we did not specify any columns, so it will fill up the values for all the columns matching with our java bean. But in the list, we need only to display four columns such as Practice Name, city, State and Zip Code.
So how we can retrieve only selected columns in the create query ? You can see this example to achieve the result.
So as per that example, first let us constructors in our practice.java as shown here.
package domain; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.Table; @Entity @Table(name = "practice") public class Practice { private Integer practiceID; private String practiceName; private String city; private String ZipCode; private String state; private Integer isActive; // Our default Constructor public Practice() { } // constructor with fields needed for our listing public Practice(Integer pID, String prname, String pCity, String pState, String pZipCode, Integer pIsActive ) { this.practiceID = pID; this.practiceName = prname; this.city = pCity; this.state = pState; this.ZipCode = pZipCode; this.isActive = pIsActive; } @Id @GeneratedValue @Column(name = "PRACTICE_ID") public Integer getPracticeID() { return practiceID; } public void setPracticeID(Integer practiceID) { this.practiceID = practiceID; } @Column(name = "PRACTICE_NAME") public String getPracticeName() { return practiceName; } public void setPracticeName(String practiceName) { this.practiceName = practiceName; } @Column(name = "CITY") public String getCity() { return city; } public void setCity(String city) { this.city = city; } @Column(name = "POSTAL_CODE") public String getZipCode() { return ZipCode; } public void setZipCode(String zipCode) { ZipCode = zipCode; } @Column(name = "STATE_PROVINCE_GEO") public String getState() { return state; } public void setState(String state) { this.state = state; } @Column(name = "IS_ACTIVE") public Integer getIsActive() { if (isActive== null) return 1; else return isActive; } public void setIsActive(Integer isActive) { this.isActive = isActive; } }
Now let us change our DAO as follows
Query q1 = session.createQuery("Select new Practice(practiceID, practiceName,city,state,zipCode,isActive) from Practice ");
Next Part 3
Select only few columns in Hibernate create query API
Step : 1
Set up Java + Hibernate Environment as by this post.
Step : 2
Alter our patient table as shown
Step : 3
Now let go back to our patient.java and add the columns as follows
package mypack;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Column;
import javax.persistence.Transient;
@Entity
@Table(name = "patient")
public class patient {
private Integer id;
private String firstName;
private String lastName;
private String password;
private String email;
private String address1;
private String address2;
private String city;
private String state;
private String zipCode;
@Transient
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Id
@GeneratedValue
@Column(name = "ID")
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
@Column(name = "firstname")
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
@Column(name = "lastname")
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getAddress1() {
return address1;
}
public void setAddress1(String address1) {
this.address1 = address1;
}
public String getAddress2() {
return address2;
}
public void setAddress2(String address2) {
this.address2 = address2;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getZipCode() {
return zipCode;
}
public void setZipCode(String zipCode) {
this.zipCode = zipCode;
}
}
Step : 4
Modify our Test.java file as follows
package mypack;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import Utility.HibernateUtil;
public class Test {
public static void main(String[] args) {
getAllRecords();
}
public static void getAllRecords() {
List<patient> allpatients;
Session session = HibernateUtil.beginTransaction();
Query q1 = session.createQuery("from patient");
allpatients = q1.list();
for (int i = 0; i < allpatients.size(); i++) {
patient pt = (patient) allpatients.get(i);
System.out.println(pt.getLastName());
}
HibernateUtil.CommitTransaction();
}
}
Step : 5
Please remember from the above step, it will retrieve all the columns from the DB, you can check this by printing each value. But suppose if we want to select Firstname, lastname, then how we can do that ? Let us try now
package mypack;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import Utility.HibernateUtil;
public class Test {
public static void main(String[] args) {
getAllRecords();
}
public static void getAllRecords() {
List<patient> allpatients = null;
Session session = HibernateUtil.beginTransaction();
Query q1 = session.createQuery("Select firstName, lastName from patient");
for (int i = 0; i < allpatients.size(); i++) {
patient pt = (patient) allpatients.get(i);
System.out.println(pt.getLastName());
}
allpatients = q1.list();
HibernateUtil.CommitTransaction();
}
}If we now run this, then it will throw error, just let us remove the for loop and see
package mypack;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import Utility.HibernateUtil;
public class Test {
public static void main(String[] args) {
getAllRecords();
}
public static void getAllRecords() {
List<patient> allpatients = null;
Session session = HibernateUtil.beginTransaction();
Query q1 = session.createQuery("Select firstName, lastName from patient");
allpatients = q1.list();
HibernateUtil.CommitTransaction();
}
}Now it will compile and run even though there is no output.
So what is happening ? Here is the concept
if you use select, then it becomes Native SQL Query. So the output will not be your collection of patient objects, instead of that it will return list of object arrays. So we need to change our for loop as follows
package mypack;
import java.util.Iterator;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import Utility.HibernateUtil;
public class Test {
public static void main(String[] args) {
getAllRecords();
}
public static void getAllRecords() {
List allpatients;
Session session = HibernateUtil.beginTransaction();
Query q1 = session.createQuery("Select firstName, lastName from patient");
allpatients= q1.list();
for (Iterator it = allpatients.iterator(); it.hasNext(); ) {
Object[] myResult = (Object[]) it.next();
String firstName = (String) myResult[0];
String lastName = (String) myResult[1];
System.out.println( "Found " + firstName + " " + lastName );
}
HibernateUtil.CommitTransaction();
}
}Now if you run , you can see the output as follows
Hibernate: select patient0_.firstname as col_0_0_, patient0_.lastname as col_1_0_ from patient patient0_
Found Simth John
Found ROBERT DAVID
Found RICHARD JOSEPH
Found Mark Anderson
Step : 6
What is the alternate way to retrieve as patient objects ?
Here you go
Query q1 = session.createQuery("Select new patient(firstName,lastName) from patient");
Before this step, we should have proper constructor to create object with only two values. Now let us go back to our patient.java and add the constructor as follows
package mypack;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Column;
import javax.persistence.Transient;
@Entity
@Table(name = "patient")
public class patient {
private Integer id;
private String firstName;
private String lastName;
private String password;
private String email;
private String address1;
private String address2;
private String city;
private String state;
private String zipCode;
//Our default Constructor
public patient()
{
}
//constructor with only two columns
public patient(String fname, String lname)
{
this.firstName= fname;
this.lastName = lname;
}
@Transient
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Id
@GeneratedValue
@Column(name = "ID")
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
@Column(name = "firstname")
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
@Column(name = "lastname")
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getAddress1() {
return address1;
}
public void setAddress1(String address1) {
this.address1 = address1;
}
public String getAddress2() {
return address2;
}
public void setAddress2(String address2) {
this.address2 = address2;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getZipCode() {
return zipCode;
}
public void setZipCode(String zipCode) {
this.zipCode = zipCode;
}
}
Step : 7
Let us modify our test.java file as follows
package mypack;
import java.util.Iterator;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import Utility.HibernateUtil;
public class Test {
public static void main(String[] args) {
getAllRecords();
}
public static void getAllRecords() {
List allpatients;
Session session = HibernateUtil.beginTransaction();
Query q1 = session.createQuery("Select new patient(firstName,lastName) from patient");
allpatients = q1.list();
for (int i = 0; i < allpatients.size(); i++) {
patient pt = (patient) allpatients.get(i);
System.out.println(pt.getLastName());
System.out.println(pt.getFirstName());
}
HibernateUtil.CommitTransaction();
}
}Now you can run and see the output. Now it retrieves as patient objects