<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Adams Bros Blog &#187; AJAX</title>
	<atom:link href="http://blog.adamsbros.org/category/programming/ajax/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.adamsbros.org</link>
	<description></description>
	<lastBuildDate>Sun, 01 Jan 2012 03:28:41 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>ZK AJAX and EJB 3</title>
		<link>http://blog.adamsbros.org/2010/03/20/zk-ajax-and-ejb-3/</link>
		<comments>http://blog.adamsbros.org/2010/03/20/zk-ajax-and-ejb-3/#comments</comments>
		<pubDate>Sun, 21 Mar 2010 02:49:58 +0000</pubDate>
		<dc:creator>Trenton</dc:creator>
				<category><![CDATA[AJAX]]></category>

		<guid isPermaLink="false">http://blog.adamsbros.org/?p=250</guid>
		<description><![CDATA[I went through some issues with EJB3 and ZK.  I was using openejb at the time, integrated with tomcat 6.  I found that my methods that had role restrictions (using @RolesAllowed) were not accessible.  Whenever I clicked a button, an event would be fired, but I would get an error of "Unauthorized Access by [...]]]></description>
			<content:encoded><![CDATA[<p>I went through some issues with EJB3 and ZK.  I was using openejb at the time, integrated with tomcat 6.  I found that my methods that had role restrictions (using @RolesAllowed) were not accessible.  Whenever I clicked a button, an event would be fired, but I would get an error of "<strong>Unauthorized Access by Principal Denied</strong>", to that method, with a stack trace.<span id="more-250"></span></p>
<p>Here's an example, where I have a method in an EJB that has a role restriction...</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">﻿@RolesAllowed<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;admin&quot;</span>, <span style="color: #0000ff;">&quot;entryclerk&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> doSomething<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> action<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
...
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Whenever the doSomething thread was called from an event, such as a button click event, it would fail with an error like the following.  Take note of the bold sections, indicating the error, and the fact that it is a ZK thread.</p>
<pre>
<pre>      Message : Unauthorized Access by Principal Denied
      Exception : javax.ejb.EJBAccessException
      Stack : javax.ejb.EJBAccessException: <strong>Unauthorized Access by Principal Denied</strong>
	at org.apache.openejb.core.stateful.StatefulContainer.checkAuthorization(StatefulContainer.java:706)
	at org.apache.openejb.core.stateful.StatefulContainer.businessMethod(StatefulContainer.java:479)
	at org.apache.openejb.core.stateful.StatefulContainer.invoke(StatefulContainer.java:277)
	at org.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbObjectProxyHandler.java:217)
	at org.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectProxyHandler.java:77)
	at org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:281)
	at $Proxy47.isAuthenticated(Unknown Source)
	at com.example.main.SubmitButton.postTransaction(SubmitButton.java:65)
	at com.example.main.SubmitButton.onEvent(SubmitButton.java:186)
	at org.zkoss.zk.ui.impl.EventProcessor.process0(<strong>EventProcessor.java:197</strong>)
	at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:141)
	at org.zkoss.zk.ui.impl.EventProcessingThreadImpl.process0(<strong>EventProcessingThreadImpl.java:519</strong>)
	at org.zkoss.zk.ui.impl.EventProcessingThreadImpl.run(EventProcessingThreadImpl.java:446)</pre>
</pre>
<p>Threading is not allowed in EJB, and as a result, the user and role security was not propagated to the EJB calls I was making, as they calls were being made from within an entirely different thread than what was being managed by the EJB container.  The solution to this problem, is to disable ZK event threads.  ZK threads are enabled by default, but may be disabled in zk.xml, as follows.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;system-config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;disable-event-thread</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/system-config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Once the threads are disabled, the access denied errors disappear.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adamsbros.org/2010/03/20/zk-ajax-and-ejb-3/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ZK AJAX Status Bar</title>
		<link>http://blog.adamsbros.org/2010/01/31/zk-ajax-status-bar/</link>
		<comments>http://blog.adamsbros.org/2010/01/31/zk-ajax-status-bar/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 08:45:43 +0000</pubDate>
		<dc:creator>Trenton</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.adamsbros.org/?p=172</guid>
		<description><![CDATA[Seeing that my research project is a mini accounting system, I thought it necessary to be able to display items in a status bar, like a real application.  It is very slightly unfortunate that ZK doesn't have something integrated right in for this purpose.  But, given the versatility of ZK, it's easy enough to resolve.

Features
I [...]]]></description>
			<content:encoded><![CDATA[<p>Seeing that my research project is a mini accounting system, I thought it necessary to be able to display items in a status bar, like a real application.  It is very slightly unfortunate that ZK doesn't have something integrated right in for this purpose.  But, given the versatility of ZK, it's easy enough to resolve.</p>
<p><span id="more-172"></span></p>
<h2>Features</h2>
<p>I thought it important to have some useful features that make sense for what I've seen in status bars.</p>
<ul>
<li>a method to set the status, with a delay before the status bar is cleared</li>
<li>a method to simply set the status, and leave it as is.  It would be up to the developer to clear the status later, if need be.  Or, the next status item would take over.</li>
<li>a very simple interface abstraction in case we want to change the type of component we use later, or something of that nature.  This will help us prevent the need to refactor a lot of code that could be using the status bar; we would only need to refactor the implementing class of the interface, leaving all of the code accessing the status bar entirely intact.</li>
</ul>
<p>Future features might include...</p>
<ul>
<li>methods for setting the status with color text</li>
<li>methods for setting the status with html</li>
<li>any other suggestions are welcome.</li>
</ul>
<h2>Window Width Status Bar</h2>
<p>We first, of course, need to setup the actual status bar.  So, right before the end of the window, we do just that, with a "textbox".  Now, there's no reason you can't use some other type of control, if it makes sense to.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;textbox</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;1.2em&quot;</span> <span style="color: #000066;">sclass</span>=<span style="color: #ff0000;">&quot;status&quot;</span> <span style="color: #000066;">readonly</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;status&quot;</span> <span style="color: #000066;">use</span>=<span style="color: #ff0000;">&quot;com.example.system.StatusBar&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;timer</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;statusTimer&quot;</span> <span style="color: #000066;">running</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">repeats</span>=<span style="color: #ff0000;">&quot;false&quot;</span></span>
<span style="color: #009900;">       <span style="color: #000066;">onTimer</span>=<span style="color: #ff0000;">'status.setText(&quot;&quot;);'</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>The text box is implemented by a custom class, which we'll delve into in a moment.  We also have a ZK timer, for implementing the automatic clearing feature, because it is illegal to access ZK elements from outside of a ZK event.  i.e. You cannot write your own thread to do it at a later time, as ZK will throw an <strong><span style="color: #3366ff;">IllegalStateException</span></strong>.</p>
<h2>The Code</h2>
<h3>Interface Abstraction</h3>
<p>We've kept the interface very simple, just two methods.  For more information, read the javadoc comments.</p>
<ul>
<li>setStatus(String) allows setting of the status bar permanently</li>
<li>setStatus(String, int) allows setting of the status bar, and automatic clearing of it after a specified delay</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.example.system</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * Handles setting of status bar messages.  All calls to this object must be
 * done from within the ZK framework, such as inside an event.
 *
 * Hides the details of what component is actually a status bar.  It could be a
 * textbox, or something else, but we don't want to be dependant on any specific
 * type of control, in case it changes in the future.
 *
 * Created :  Jan 31, 2010 1:39:37 AM MST
 *
 * Modified : $Date$ UTC
 *
 * Revision : $Revision$
 *
 * @author Trenton D. Adams
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> IStatusBar
<span style="color: #009900;">&#123;</span>
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Sets the status bar text for the time period indicated.
     *
     * @param statusText status text
     * @param timePeriod delay in seconds, before the status bar will be
     *                   cleared.
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setStatus<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> statusText, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> timePeriod<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Sets the status bar text.  Pass null to clear.
     *
     * @param statusText status text or null to clear
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setStatus<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> statusText<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * @return the status text of the status bar.
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getStatus<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>Implementation</h3>
<p>Essentially, all we are doing with the implement is as follows</p>
<ul>
<li>implement AfterCompose, so we can setup a session variable to access the status bar from any ZK code, without much trouble</li>
<li>implement the setStatus() methods as described in the feature section.  One takes an extra argument for a delay, indicating how long before the status bar should be cleared.</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.example.system</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.log4j.Logger</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.zkoss.zk.ui.Session</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.zkoss.zk.ui.ext.AfterCompose</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.zkoss.zul.Textbox</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.zkoss.zul.Timer</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * StatusBar handles setting the status bar text, and clearing it after a given
 * timeout.  Implements IStatusBar, to hide the details of what a status bar is
 * from the client code.  We use a textbox, but we could change that, who knows.
 *
 * Created :  Jan 31, 2010 12:42:29 AM MST
 *
 * Modified : $Date$ UTC
 *
 * Revision : $Revision$
 *
 * @author Trenton D. Adams
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> StatusBar <span style="color: #000000; font-weight: bold;">extends</span> Textbox <span style="color: #000000; font-weight: bold;">implements</span> AfterCompose, IStatusBar
<span style="color: #009900;">&#123;</span>
    @SuppressWarnings<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;ConstantNamingConvention&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> Logger logger <span style="color: #339933;">=</span> Logger.<span style="color: #006633;">getLogger</span><span style="color: #009900;">&#40;</span>StatusBar.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> StatusBar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> afterCompose<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        logger.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;status bar running as &quot;</span> <span style="color: #339933;">+</span> getId<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// TODO find a better method, getFellow() didn't work</span>
        <span style="color: #000000; font-weight: bold;">final</span> Session session <span style="color: #339933;">=</span> getDesktop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getSession</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        session.<span style="color: #006633;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;status&quot;</span>, <span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setStatus<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> statusText, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> timePeriod<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        setStatus<span style="color: #009900;">&#40;</span>statusText<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// the timer must be in the page, or the page is inactive and this</span>
        <span style="color: #666666; font-style: italic;">// call would never happen?</span>
        <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Timer</span> timer <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Timer</span><span style="color: #009900;">&#41;</span> getFellow<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;statusTimer&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        timer.<span style="color: #006633;">setDelay</span><span style="color: #009900;">&#40;</span>timePeriod <span style="color: #339933;">*</span> <span style="color: #cc66cc;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        timer.<span style="color: #006633;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setStatus<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> statusText<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        setText<span style="color: #009900;">&#40;</span>statusText<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getStatus<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> getText<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>Using the Status Bar</h3>
<p>The following code must be used inside of a ZK event handler, such as one that comes from the click of a button, or a mouse over event, etc.  Basically, all we're doing is grabbing the status bar object from the session, and request the status be set.  That's all there is to it.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">final</span> Session session <span style="color: #339933;">=</span> getDesktop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getSession</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">final</span> IStatusBar statusBar <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>IStatusBar<span style="color: #009900;">&#41;</span> session.<span style="color: #006633;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;status&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
statusBar.<span style="color: #006633;">setStatus</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Transaction Posted&quot;</span>, <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h2>Results</h2>
<p>I'm attaching a screen shot of the results of my status bar.</p>
<p><a href="http://blog.adamsbros.org/wp-content/uploads/2010/01/status-bar.png"><img class="alignnone size-full wp-image-177" title="status-bar" src="http://blog.adamsbros.org/wp-content/uploads/2010/01/status-bar.png" alt="ZK Status bar" width="530" height="148" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adamsbros.org/2010/01/31/zk-ajax-status-bar/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ZK Exception Handling and Error Popup</title>
		<link>http://blog.adamsbros.org/2010/01/30/zk-exception-handling-and-error-popup/</link>
		<comments>http://blog.adamsbros.org/2010/01/30/zk-exception-handling-and-error-popup/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 01:28:09 +0000</pubDate>
		<dc:creator>Trenton</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.adamsbros.org/?p=160</guid>
		<description><![CDATA[Once I had some basic functionality in my mini accounting system that I'm writing (for research purposes), one of my goals was to have an adequate error display for the user, that was the same every time.  Suffice it to say, I was completely thrilled to find out that ZK could do exactly what I [...]]]></description>
			<content:encoded><![CDATA[<p>Once I had some basic functionality in my mini accounting system that I'm writing (for research purposes), one of my goals was to have an adequate error display for the user, that was the same every time.  Suffice it to say, I was completely thrilled to find out that ZK could do exactly what I wanted to do, and I didn't have to write an once of code.  All I did was write some ZUL, which wrapped a JSP inside of a ZK window.  I share how I did that in this post.</p>
<p><span id="more-160"></span></p>
<h2>Configuration</h2>
<p>The first thing to do is to configure ZK to handle your unhandled exceptions, and target a ZUL page for rendering.  This is done through the zk.xml file.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;error-page<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;exception-type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>java.lang.Throwable<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/exception-type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;location<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/error.zul<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/location<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/error-page<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<h2>ZK error.zul</h2>
<p>The second thing to do is create an error.zul page, which I pulled mostly from the ZK Developers Guide.  I added the bit where I include my error.jsp file.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;zk</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.zkoss.org/2005/zul&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul/zul.xsd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;window</span> <span style="color: #000066;">mode</span>=<span style="color: #ff0000;">&quot;modal&quot;</span> <span style="color: #000066;">sizable</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;">          <span style="color: #000066;">title</span>=<span style="color: #ff0000;">&quot;Error ${requesScope['javax.servlet.error.status_code']}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;vbox<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;hbox<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;/jsp/error.jsp&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/hbox<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;hbox</span> <span style="color: #000066;">style</span>=<span style="color: #ff0000;">&quot;margin-left:auto; margin-right:auto; text-align: center;&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Okay&quot;</span> <span style="color: #000066;">onClick</span>=<span style="color: #ff0000;">&quot;spaceOwner.detach()&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Reload Page&quot;</span> <span style="color: #000066;">onClick</span>=<span style="color: #ff0000;">&quot;Executions.sendRedirect(null)&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/hbox<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/vbox<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/window<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/zk<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<h2>JSP error.jsp</h2>
<p>I basically pulled this error page from the standard error page that I normally use, and tailored it a bit.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;">&lt;%@ page <span style="color: #000066;">import</span>=<span style="color: #ff0000;">&quot;java.io.PrintWriter&quot;</span> %<span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;">&lt;%@ page <span style="color: #000066;">import</span>=<span style="color: #ff0000;">&quot;java.io.StringWriter&quot;</span> %<span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;">&lt;%@ page <span style="color: #000066;">import</span>=<span style="color: #ff0000;">&quot;com.example.util.Util&quot;</span> %<span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;">&lt;%@ page <span style="color: #000066;">isErrorPage</span>=<span style="color: #ff0000;">&quot;true&quot;</span> %<span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;">&lt;%@ taglib <span style="color: #000066;">uri</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/jsp/jstl/core&quot;</span> <span style="color: #000066;">prefix</span>=<span style="color: #ff0000;">&quot;ce&quot;</span> %<span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;">&lt;%@ taglib <span style="color: #000066;">uri</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/jsp/jstl/functions&quot;</span> <span style="color: #000066;">prefix</span>=<span style="color: #ff0000;">&quot;fn&quot;</span> %<span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;">&lt;%@ taglib <span style="color: #000066;">uri</span>=<span style="color: #ff0000;">&quot;http://jakarta.apache.org/taglibs/string-1.1&quot;</span> <span style="color: #000066;">prefix</span>=<span style="color: #ff0000;">&quot;st&quot;</span> %<span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #808080; font-style: italic;">&lt;!-- BEGIN error.jsp --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;error&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;message&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>&lt;%=exception.getMessage<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>%<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>An error has occured. If you believe this error is a system problem, and you
  continue to get this error, please contact a special person via
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;mailto:'me@example.com' &quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>email<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ce:if</span> <span style="color: #000066;">test</span>=<span style="color: #ff0000;">&quot;&lt;%=Util.getBooleanItem(\&quot;</span>/debug\<span style="color: #ff0000;">&quot;)%&gt;</span></span>&quot;&gt;
    <span style="color: #009900;">&lt;%</span>
<span style="color: #009900;">      StringWriter sw = new StringWriter<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #009900;">      PrintWriter pw = new PrintWriter<span style="color: #66cc66;">&#40;</span>sw<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #009900;">      exception.printStackTrace<span style="color: #66cc66;">&#40;</span>pw<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #009900;">    %<span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ce:set</span> <span style="color: #000066;">var</span>=<span style="color: #ff0000;">&quot;exceptionStack&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>&lt;%=sw.toString<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>%<span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ce:set<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;debug&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      Message : <span style="color: #009900;">&lt;%=exception.getMessage<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>%<span style="color: #000000; font-weight: bold;">&gt;</span></span>
      Exception : <span style="color: #009900;">&lt;%=exception.getClass<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.getName<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>%<span style="color: #000000; font-weight: bold;">&gt;</span></span>
      Stack : ${fn:escapeXml(exceptionStack)}
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ce:if<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #808080; font-style: italic;">&lt;!-- END error.jsp --&gt;</span></pre></div></div>

<h2>Sample Error Page</h2>
<p>And, we have the result;  it looks quite nice.  If debug were enabled, it would have my stack trace displayed in a wrap-able fixed width font ; providing much easier diagnostics during development.</p>
<p><a href="http://blog.adamsbros.org/wp-content/uploads/2010/02/sample-error.png"><img class="alignnone size-full wp-image-186" title="ZK Sample Error" src="http://blog.adamsbros.org/wp-content/uploads/2010/02/sample-error.png" alt="ZK Sample Error Page" width="558" height="196" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adamsbros.org/2010/01/30/zk-exception-handling-and-error-popup/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ZK AJAX Framework Introduction</title>
		<link>http://blog.adamsbros.org/2010/01/30/zk-ajax-framework-introduction/</link>
		<comments>http://blog.adamsbros.org/2010/01/30/zk-ajax-framework-introduction/#comments</comments>
		<pubDate>Sat, 30 Jan 2010 23:33:43 +0000</pubDate>
		<dc:creator>Trenton</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.adamsbros.org/?p=139</guid>
		<description><![CDATA[I am in the process of working with and researching ZK as an AJAX framework to integrate into Java Web Development that I do.  So far, AJAX looks really amazing, and is fully integrated into the J2EE framework.  It is an event driven framework that has the option of hooking directly into existing JSP, or [...]]]></description>
			<content:encoded><![CDATA[<p>I am in the process of working with and researching ZK as an AJAX framework to integrate into Java Web Development that I do.  So far, AJAX looks really amazing, and is fully integrated into the J2EE framework.  It is an event driven framework that has the option of hooking directly into existing JSP, or entirely writing ZK event handlers to do the processing.  There is no wonder that ZK won the <a title="ZK - Simply Ajax and Mobile" href="http://sourceforge.net/blog/potm-200902/">Project of the Month Source Forge award</a>.</p>
<p><span id="more-139"></span></p>
<h2>Integration</h2>
<p>In the case of existing web applications that make heavy use of JSP for display, ZK can be easily integrated into specific controls on the page, such as drop downs, text boxes, etc, to provide AJAX for that individual component.  The component is then submitted using the normal GET/POST method.  You can thereby provide AJAX auto complete, or dynamic load functionality to your heart's content, without affecting the normal working of the page.  If your goal is to move toward entirely using AJAX for that application, you can easily do it incrementally, so as not to have an overly complex and long development cycle.  Just drop some of the ZUL includes directly into your JSP, write some ZSCRIPT or Java component/event classes, handle the processing, and you have yourself some event driven AJAX code.</p>
<h2>GUI Features</h2>
<p>ZUL files are essentially a derivative of XUL, defined for the purpose of AJAX handling in ZK.  You define your GUI layout in XML, and write code to handle each component as you choose.</p>
<p>One of many great benefits of ZK, is that it has many different ZUL components for the normal input text box.  You can make your text box a decimal box, a date box, int box, double box, etc, and AJAX will handle data validation for you, and wrapping it in the appropriate wrapper class such as BigDecimal, Integer, Double, etc.  In fact, in many cases, it won't even let you type in a character that is not allowed.  For example, if you have specified a number box of some type, such as decimal, int, double, etc, it won't even let you type an alpha character.  You can also place constraints on your inputs such as "<strong><span style="color: #3366ff;">no zero</span></strong>", or "<strong><span style="color: #3366ff;">no negative</span></strong>", which would indicate that the box cannot accept a negative or zero input, but could be empty.</p>
<p>Here is a quick example of a decimalbox in action.  I'll give two examples.  The first one has an implementing Java class, which you simply write a class that extends Decimalbox. The implementing class is just below that on the page. The second one achieves the exact same thing, but is not quite as flexible, for the simple reason that it's not as dynamic, because I you cannot go instantiating it from code.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;decimalbox</span> <span style="color: #000066;">use</span>=<span style="color: #ff0000;">&quot;com.example.common.LedgerDecimalBox&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;credit-0&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;decimalbox</span> <span style="color: #000066;">constraint</span>=<span style="color: #ff0000;">&quot;no negative,no zero&quot;</span> <span style="color: #000066;">format</span>=<span style="color: #ff0000;">&quot;#,##0.#&quot;</span> <span style="color: #000066;">scale</span>=<span style="color: #ff0000;">&quot;2&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.example.common</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.example.util.CVUtil</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.log4j.Logger</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.zkoss.zk.ui.ext.AfterCompose</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.zkoss.zul.Decimalbox</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> LedgerDecimalBox <span style="color: #000000; font-weight: bold;">extends</span> Decimalbox <span style="color: #000000; font-weight: bold;">implements</span> AfterCompose
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> Logger logger <span style="color: #339933;">=</span> Logger.<span style="color: #006633;">getLogger</span><span style="color: #009900;">&#40;</span>LedgerDecimalBox.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">public</span> LedgerDecimalBox<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>   <span style="color: #666666; font-style: italic;">// load configured options</span>
        setFormat<span style="color: #009900;">&#40;</span><span style="color: #003399;">Util</span>.<span style="color: #006633;">getStringItem</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/inputs/decimalbox/format&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        setConstraint<span style="color: #009900;">&#40;</span><span style="color: #003399;">Util</span>.<span style="color: #006633;">getStringItem</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/inputs/decimalbox/constraints&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        setScale<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> afterCompose<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        logger.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;id: &quot;</span> <span style="color: #339933;">+</span> getId<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>In all honesty, ZK seems to be absolutely amazing, very rich, very fast, very flexible, etc.  In my opinion, it is probably <strong>THE BEST</strong> AJAX framework on the planet, by a <strong>LONG</strong> shot.</p>
<p>You can totally expect me to write more on ZK, as I learn the framework, and blog about various ways of doing things.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adamsbros.org/2010/01/30/zk-ajax-framework-introduction/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

