Friday, 6 July 2012

ZK Component extend

In this post, we will see how we can create our component by extending ZK Component. All the jquery plugin can be used in ZK. The following example will explain how to create Phonebox, Zip Code and Tax ID.

For your further reference, you can see the following http://www.zkoss.org/zkdemo/effects/form_effect
You can download the jquery plugin from http://digitalbush.com/projects/masked-input-plugin/

ZK Version 6
Project Name : MyComponents
Project Structure:

image

Download the jquery plugin and Add in webcontent/js folder.

Here is the source for other files

Demo.jul

<?page title="new page title" contentType="text/html;charset=UTF-8"?>
<zk>
<window id="myWin" title="new page title" border="normal" >
<label value="Phone :" />
<phonebox id="phone" width='150px' />
<label value="Extension :" />
<Extension id="txtPhoneExt" />
<label value="zipCode :" />
<ZipCode id="txtZipCode" />
<label value="Tax ID:" />
<EIN id="txtEIN" />
<label value="Alpha Numeric :" />
<AlphaNumeric />
</window>
</zk>


AlphaNumeric.java


package components;

import org.zkoss.zul.Textbox;

public class AlphaNumeric extends Textbox {
private static final long serialVersionUID = 1L;

public AlphaNumeric() {
setWidgetListener("onBind", "jq(this).mask('******');");
}
}


EIN.java

package components;
import org.zkoss.zul.Textbox;

public class EIN extends Textbox {
private static final long serialVersionUID = 1L;
public EIN() {
setWidgetListener("onBind", "jq(this).mask('99-9999999');");
}
}

Extension.java

package components;

import org.zkoss.zul.Textbox;

public class Extension extends Textbox {
private static final long serialVersionUID = 1L;

public Extension() {
setWidgetListener("onBind", "jq(this).mask('99999');");
}
}

NPI.java

package components;

import org.zkoss.zul.Textbox;

public class NPI extends Textbox {
private static final long serialVersionUID = 1L;
public NPI() {
setWidgetListener("onBind", "jq(this).mask('9999999999');");
}
}

Phonebox.java

package components;
import org.zkoss.zul.Textbox;

public class Phonebox extends Textbox {
private static final long serialVersionUID = 1L;
public Phonebox() {
setWidgetListener("onBind", "jq(this).mask('(999) 999-9999');");
}
}

ZipCode.java

package components;

import org.zkoss.zul.Textbox;

public class ZipCode extends Textbox {
private static final long serialVersionUID = 1L;

public ZipCode() {
setWidgetListener("onBind", "jq(this).mask('99999-9999');");
}
}


In the webcontent folder, create a file in the name of my-addon.xml (you can keep any file name)


<?xml version="1.0" encoding="UTF-8"?>
<language-addon>
<addon-name>ecosmos</addon-name>
<language-name>xul/html</language-name>

<component>
<component-name>phonebox</component-name>
<component-class>components.Phonebox
</component-class>
<extends>textbox</extends>
</component>

<component>
<component-name>EIN</component-name>
<component-class>components.EIN</component-class>
<extends>textbox</extends>
</component>

<component>
<component-name>NPI</component-name>
<component-class>components.NPI</component-class>
<extends>textbox</extends>
</component>

<component>
<component-name>Extension</component-name>
<component-class>components.Extension
</component-class>
<extends>textbox</extends>
</component>


<component>
<component-name>ZipCode</component-name>
<component-class>components.ZipCode
</component-class>
<extends>textbox</extends>
</component>

<component>
<component-name>AlphaNumeric</component-name>
<component-class>components.AlphaNumeric
</component-class>
<extends>textbox</extends>
</component>





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

</language-addon>


And in the ZK.Xml , add the reference for the above file as follows


<?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>


Now you can run the demo.zul and check the output


image


You can download source here

3 comments:

  1. Can you post any Macro Component Demo in zk6

    ReplyDelete
  2. I delight in the content on your internet site. Cheers!

    Generic Viagra

    ReplyDelete
  3. We are a third party technical support service. Avast Customer Support is here to help you out with the whole procedure to Download Avast Antivirus online, We not only fix your Avast Support related issues but will guide with how to get started with your new Avast product once it gets installed successfully. Call on our Toll Free no. 1 855 966 3855
    Gmail Customer service is a third party technical support service for Gmail users when they face any technical issue or error in their Gmail account. Our Gmail Customer Support team solves issues like forgot Gmail account password, Gmail configuration or Sync issues, recover deleted emails and many more. Toll Free number (800) 986-9271
    How you install or reinstall Office 365 or Office 2016 depends on whether your Office product is part of an Office for home or Office for business plan. If you're not sure what you have, see what office com setup products are included in each plan and then follow the steps for your product. The steps below also apply if you're installing a single, stand-alone Office application such as Access 2016 or Visio 2016. Need Help with office setup Enter Product Key? Call 1-800-000-0000 Toll Free
    Norton Tech Support is a third party service provider and not in any way associated with Norton or any of its partner companies. We offer support for Norton products and sell subscription based additional warranty on computer and other peripheral devices. Call our Toll Free number 1 855 966 3855
    Other Services
    Norton Toll Free , Office-Setup , office.com/setup.

    ReplyDelete