Requirement Constraints

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

Wednesday, 16 January 2013

ZK Datebox: Customize Datebox as Yearbox/Monthbox

Posted on 22:10 by Unknown

This article based on Bai Ben from his blog. You can check here.

Left hug My sincere thanks to him who helped me in this example

ZK Version : 6.5.0

Concepts used in this example
  1. ZK Client side Programming using Javascript
  2. Widget Customization
  3. UI Composing.
  4. Put in a Separate File and Reference it in Language Addon.
  5. Language Definition
  6. Sample of a Language Definition
  7. Client Side Programming
Step 1:
If you are new ZK, then first we need to setup the development environment. This document will help you to do the same.

Step 2:
Let us create the Project in eclipse. Click File -> New -> ZK Project . Let us name the project as ZKMVCListing1. After creating the New ZK Project, the folder structure should look as follows

image

image

Step 3:
Now let us add the javascript which will override default behavior of zk native datebox component.


image

Here java script file
zk.afterLoad("zul.db", function () {
// Datebox Calendar Renderer
var _Cwgt = {};
zk
.override(
zul.db.CalendarPop.prototype,
_Cwgt,
{
// switch the view after redraw or open as needed
redraw : function(out) {
_Cwgt.redraw.apply(this, arguments); // call the
// original
// method
this._customChangeView();
},
open : function(silent) {
_Cwgt.open.apply(this, arguments); // call the
// original
// method
this._customChangeView();
},
_customChangeView : function() {
// cannot show month/day
if (jq(this.parent.$n()).hasClass(
'datebox-year-only')) {
var view = this._view;
// switch to year view as needed
if (view == 'month' || view == 'day')
this._setView("year");
} else if (jq(this.parent.$n()).hasClass(
'datebox-month-only')) {
// cannot show day view
// switch to month view as needed
if (this._view == 'day')
this._setView("month");
}
},
// customize the chooseDate function
_chooseDate : function(target, val) {
var view = this._view;
if (jq(this.parent.$n()).hasClass(
'datebox-month-only')
|| jq(this.parent.$n()).hasClass(
'datebox-year-only')) {
// do customize chooseDate if the parent
// (datebox)
// has specific class
var date = this.getTime(), year = (view == 'decade' || view == 'year') ? val
: date.getFullYear(), month = view == 'month' ? val
: 0, date = 1;
// set date value
this._setTime(year, month, 1);
if (view == 'decade') {
// switch to year view if at decade view
this._setView("year");
} else if (jq(this.parent.$n()).hasClass(
'datebox-month-only')
&& view == 'year') {
// switch to month view if at year view and
// the month view is allowed
this._setView("month");
} else if (jq(this.parent.$n()).hasClass(
'datebox-month-only')
&& view == 'month'
|| jq(this.parent.$n()).hasClass(
'datebox-year-only')
&& view == 'year') {
// close calendar and update value if
// already at the smallest allowed view
this.close();
this.parent.updateChange_();
}
} else {
_Cwgt._chooseDate.apply(this, arguments); // call
// the
// original
// method
}
}
});
});


Step 4:
We will create addon file and refer the above Java script file as follows

image

my-addon.xml
<?xml version="1.0" encoding="UTF-8"?>
<language-addon>
<addon-name>myaddon</addon-name>
<language-name>xul/html</language-name>
<addon-name>my.extension</addon-name><!-- any name you like -->
<javascript src="js/YearBox.js" /> <!-- assume you package it as /myjs/foo.js -->
</language-addon>

 
Step 5:
Next we will say that we are using our own addon file in the ZK.xml

image

ZK.XML


<?xml version="1.0" encoding="UTF-8"?>
<!-- Created by ZK Studio -->
<zk>
<device-config>
<device-type>ajax</device-type>
<timeout-uri>/timeout.zul</timeout-uri><!-- An empty URL can cause the 
browser to reload the same URL -->



</device-config>
<language-config>
<addon-uri>/WEB-INF/my-addon.xml</addon-uri>
</language-config>
</zk>


Step 6:
That’s all, We can update our index.zul file as follows to see the output




<?page title="Auto Generated index.zul"?>
<window title="Hello World!!" border="normal" width="200px">
<label value="You are using: ${desktop.webApp.version}"/>
<vbox>
<label value="datebox that do not allow the month/day view" />
<datebox id="dbx" sclass="datebox-year-only"
format="yyyy">
<attribute name="onChange"><![CDATA[
Date date = self.getValue();
alert("Year: " + (date.getYear()+1900));
]]></attribute>
</datebox>
<label value="datebox that do not allow the day view" />
<datebox id="dbx2" sclass="datebox-month-only"
format="yyyy-MM">
<attribute name="onChange"><![CDATA[
Date date = self.getValue();
alert("Year: " + (date.getYear()+1900) + "\n"
+ "Month: " + (date.getMonth()+1));
]]></attribute>
</datebox>
<label value="a normal datebox" />
<datebox id="dbx3">
<attribute name="onChange"><![CDATA[
Date date = self.getValue();
alert("Year: " + (date.getYear()+1900) + "\n"
+ "Month: " + (date.getMonth()+1) + "\n"
+ "Day: " + date.getDate());
]]></attribute>
</datebox>
</vbox>
</window>



Now we run our index.zul to see the output

image
You can download the source here.
Wait. Still my objective is not solved. My objective is as follows

1. I am trying to created as separate ZK Extended component as follows

<yearbox></yearbox>

<monthyearbox></monthyearbox>

I tried by extending the datebox and added the reference in addon file as follows

<?xml version="1.0" encoding="UTF-8"?>
<language-addon>
    <addon-name>ecosmos</addon-name>
    <language-name>xul/html</language-name>
    <component>
        <component-name>ZKYearBox</component-name>
        <component-class>com.ecosmos.zkoss.ext.ZKYearBox</component-class>
        <extends>datebox</extends>
    </component>

    <addon-name>my.extension</addon-name><!-- any name you like -->
    <javascript src="js/YearBox.js" /> <!-- assume you package it as /myjs/foo.js -->

</language-addon>

And also in the java class, I tried to call the override function as follows
package com.ecosmos.zkoss.ext;
import org.zkoss.zul.Datebox;

public class ZKYearBox extends Datebox {
    private static final long serialVersionUID = 1L;
    public ZKYearBox() {
        setWidgetOverride("onBind", "zk.afterLoad('zul.db', function ()");
    }
}

But it is not working.

If I found the solution, I will complete this example


About Me
Email ThisBlogThis!Share to XShare to Facebook
Posted in ZK extended Components | 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...
  • EDI 270–5010 Documentation - ISA – Interchange Control Header
    ISA – Interchange Control Header ISA – Interchange Control Header   The ISA is a fixed record length segment and all positions within ea...
  • Understanding EDI Structure
    EDI Structure Primary Levels are 1. Interchange Envelops 2. Functional Group 3. Transaction set Data Element A data element is equival...
  • EDI Instructions
    HIPAA Compliant Codes All the Health care EDI Transaction set should use only the following HIPAA Compliant Codes Physicians Current Pro...
  • ZK ListBox
    Let us first design a simple  static list box with crud Buttons as last column. Here is the code <?page title="Practice List" c...
  • List Item Connected with Hibernate and Search Parameter
      Summary This example contains one list box with First name and Last Name as search Field. If the user do not give any values for first n...
  • Physician Quality Reporting System - PQRS
    Let me just summarized the information which i understood clearly about PQRS . The following information are taken from different websites a...
  • EDI 270 - 5010 Health Care Eligibility/Benefit Inquiry
    If you are new to Medical Billing, then please read this article first . If you are new to EDI, then  read the following articles 1. What i...
  • Types of Reimbursement
    Fee-For-Service Fee-for-service is a method of payment where the provider is paid a fee for each procedure performed and billed.Most payer ...
  • 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...

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)
      • ZK With Spring + JPA + Hibernate Entity Manager
      • ZK MVC CRUD With Spring 3 + JPA + Hibernate 4 Enti...
      • ZK MVC CRUD With Spring 3 + JPA + Hibernate 4 Enti...
      • ZK MVC CRUD With Spring 3 + JPA + Hibernate 4 Enti...
      • ZK Datebox: Customize Datebox as Yearbox/Monthbox
      • Listing Search using MVC Pattern
      • ZK MVC CRUD With Spring 3 + JPA + Hibernate 4 Enti...
      • ZK MVC CRUD With Spring 3 + JPA + Hibernate 4 Enti...
      • Some Button CSS In ZK
      • ZK Passing Parameter between two files using MVC -...
      • How to set Textbox Maxlength in the view model ?
      • MVVM Pass Parameter between two zul files using UR...
      • Spring Security Form Login Example
  • ►  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