<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Developer Notes</title>
	
	<link>http://achorniy.wordpress.com</link>
	<description>Practical notes, advises on application development (java, seam, android, google api)</description>
	<lastBuildDate>Mon, 13 May 2013 21:54:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain="achorniy.wordpress.com" port="80" path="/?rsscloud=notify" registerProcedure="" protocol="http-post" />
<image>
		<url>http://0.gravatar.com/blavatar/450b7c8b424121321987bccf7b59625e?s=96&amp;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Developer Notes</title>
		<link>http://achorniy.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://achorniy.wordpress.com/osd.xml" title="Developer Notes" />
	
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/achorniy/sdevelopment" /><feedburner:info uri="achorniy/sdevelopment" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://achorniy.wordpress.com/?pushpress=hub" /><item>
		<title>Manage server throughput for large downloads</title>
		<link>http://feedproxy.google.com/~r/achorniy/sdevelopment/~3/MoLEYCqyuFw/</link>
		<comments>http://achorniy.wordpress.com/2013/04/12/manage-server-throughput-for-large-downloads/#comments</comments>
		<pubDate>Fri, 12 Apr 2013 17:14:54 +0000</pubDate>
		<dc:creator>Andrey Chorniy</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[bandwidth]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[servlet]]></category>
		<category><![CDATA[throughput]]></category>

		<guid isPermaLink="false">http://achorniy.wordpress.com/?p=486</guid>
		<description><![CDATA[Manage server throughput for large downloads Initially I want to explore the solutions to implement Servlet/OutputStream with limited throughput in order to limit single download to some bandwidth. It looks to be a perfect article which describe the way to<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://achorniy.wordpress.com/2013/04/12/manage-server-throughput-for-large-downloads/">Read more &#8250;</a></div><!-- end of .read-more --><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=achorniy.wordpress.com&#038;blog=8544771&#038;post=486&#038;subd=achorniy&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a href="http://nurkiewicz.blogspot.com/2011/03/tenfold-increase-in-server-throughput.html" title="Manage server throughput for large downloads">Manage server throughput for large downloads</a></p>
<p>Initially I want to explore the solutions to implement Servlet/OutputStream with limited throughput in order to limit single download to some bandwidth.</p>
<p>It looks to be a perfect article which describe the way to distribute/manage server resources for large downloads.</p>
<p><a href="http://nurkiewicz.blogspot.com/2011/03/tenfold-increase-in-server-throughput.html">http://nurkiewicz.blogspot.com/2011/03/tenfold-increase-in-server-throughput.html</a><br />It help to address a lot of issues, like:</p>
<ul>
<li>
<div>some clients might be more privileged, having bigger or no limit at all,</div>
</li>
<li>
<div>some might be black listed, resulting in connection rejection or very low throughput</div>
</li>
<li>
<div>banning IPs, requiring authentication, cookie/user agent verification, etc.</div>
</li>
<li>
<div>we might try to correlate concurrent requests coming from the same client and use the same bucket for all of them to avoid cheating by opening several connections. We might also reject subsequent connections</div>
</li>
<li>
<div>and much more&#8230;</div>
</li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/achorniy.wordpress.com/486/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/achorniy.wordpress.com/486/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=achorniy.wordpress.com&#038;blog=8544771&#038;post=486&#038;subd=achorniy&#038;ref=&#038;feed=1" width="1" height="1" /><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?a=MoLEYCqyuFw:6PHgXMy0Iww:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?a=MoLEYCqyuFw:6PHgXMy0Iww:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?i=MoLEYCqyuFw:6PHgXMy0Iww:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?a=MoLEYCqyuFw:6PHgXMy0Iww:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/achorniy/sdevelopment/~4/MoLEYCqyuFw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://achorniy.wordpress.com/2013/04/12/manage-server-throughput-for-large-downloads/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/75c2bdacfd2d62abcbfe7beda3d9c613?s=96&amp;d=identicon&amp;r=G" medium="image">
			<media:title type="html">achorniy</media:title>
		</media:content>
	<feedburner:origLink>http://achorniy.wordpress.com/2013/04/12/manage-server-throughput-for-large-downloads/</feedburner:origLink></item>
		<item>
		<title>IcePush integration to web-application</title>
		<link>http://feedproxy.google.com/~r/achorniy/sdevelopment/~3/H7mRs0w1I6E/</link>
		<comments>http://achorniy.wordpress.com/2012/02/29/icepush-integration-to-web-application/#comments</comments>
		<pubDate>Wed, 29 Feb 2012 21:57:08 +0000</pubDate>
		<dc:creator>Andrey Chorniy</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[ajax-push]]></category>
		<category><![CDATA[icepush]]></category>
		<category><![CDATA[icepush example]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[java web]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[jsf]]></category>
		<category><![CDATA[push notifications]]></category>
		<category><![CDATA[richfaces]]></category>
		<category><![CDATA[web apps]]></category>
		<category><![CDATA[web-application]]></category>

		<guid isPermaLink="false">http://achorniy.wordpress.com/?p=378</guid>
		<description><![CDATA[In one of the previous post I show an example of how a4j-push and a4j-poll were used together. It help to solve several things and optimize code/requests a bit. But in reality it was not &#8220;real&#8221; push &#8211; it just<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://achorniy.wordpress.com/2012/02/29/icepush-integration-to-web-application/">Read more &#8250;</a></div><!-- end of .read-more --><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=achorniy.wordpress.com&#038;blog=8544771&#038;post=378&#038;subd=achorniy&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><img src="http://achorniy.files.wordpress.com/2012/02/fast-running-flash.gif?w=300&#038;h=180" alt="Push notifications are fast as Running Flash" title="Push notifications are fast as Running Flash" width="300" height="180" class="alignleft size-medium wp-image-452" /><br />
In one of the <a href="http://achorniy.wordpress.com/2011/02/27/richfaces-a4j-poll-and-push-can-do-more-together/">previous post</a> I show an example of how <a href="http://achorniy.wordpress.com/2011/02/27/richfaces-a4j-poll-and-push-can-do-more-together/">a4j-push and a4j-poll were used together</a>. It help to solve several things and optimize code/requests a bit. But in reality it was not &#8220;real&#8221; push &#8211; it just execute periodic lightweight requests (ping server) and asks him &#8211; &#8220;do you have something new for me ?&#8221;. It has serious cons:</p>
<ul>
<li>number of requests to server is linearly depends on the number of browser windows opened, so more simultaneous users we have connected to the server &#8211; the higher loading it will have. So, actually server can be just &#8220;overloaded&#8221; by that simple requests</li>
<li>with regards to previous point we have to increase the period between requests (to make less impact on the server) &#8211; but it is not good for user experience, since it will see the updates with a larger delay</li>
</ul>
<p>What I expect from Push is that server itself initiate the push-notification to the client. So it does that right at the moment he have to say something new to the client. There is no need to say that such server-to-client communication open a lot of great features and possibilities to web apps.<br />
Here is the diagram from the <a href="http://wiki.icefaces.org/display/PUSH/Notification+Protocol+Overview">IcePush docs</a><br />
<a href="http://wiki.icefaces.org/display/PUSH/Notification+Protocol+Overview"><img src="http://achorniy.files.wordpress.com/2012/02/icepush-simplearch.png?w=605" alt="" title="IcePush-simpleArch"   class="alignnone size-full wp-image-442" /></a></p>
<p>It probably not that visible, but in short &#8211; &#8220;It works great&#8221;. IcePush client (javascript) send the list of subscribed topics he want to listen, server genberate the unique ID for him, after that client establish the connection with the server which listen for response from server. Server will notify the client once he will have notifications to send to him. Client call the callback function in which you may do anything (you may call any javascript function as well the a4j:jsFunction if you want to do something through JSF)<br />
<a href="http://wiki.icefaces.org/display/PUSH/Notification+Protocol+Overview"><img src="http://achorniy.files.wordpress.com/2012/02/icepush-request-sequence.png?w=605" alt="" title="icepush-request-sequence"   class="alignnone size-full wp-image-444" /></a><br />
As a result, the client browser will be notified right after the event will occur on the server. It will be immediately pushed to the client and after that client is free to do anything he want to react to the notification.</p>
<p>The good thing is that it&#8217;s fairly easy to integrate IcePush technology with existent java-web application. The requirement here is just to have a servlet container.<br />
In my case it was existent Richfaces/Seam-2/JSF application (I was afraid that IcePush may conflict with Richfaces, but it is not the case, IcePush can be integrated completely transparent to the JSF/Seam application, since it integrates on Servlet level).<br />
IcePush has a number of <a href="http://wiki.icefaces.org/display/PUSH/Integration+Bundles">ways to integrate</a>, but I&#8217;ve chooses the <a href="http://wiki.icefaces.org/display/PUSH/jQuery+Integration">jQuery Integration</a><br />
You can find all the necessary <a href="http://wiki.icefaces.org/display/PUSH/Java+EE+Integration+Basics">information about IcePush integration</a> here. I will show the example of integration of IcePush with existent web-application (Seam/Richfaces). I think the integration could be the same for GWT or any other app which is deployed in the Servlet-Container.</p>
<ol>
<li>Downloaded <a href="http://www.icesoft.org/downloads/icepush-downloads.jsf">jQuery integration package</a></li>
<li>Added the icepush.jar to the WEB-INF/lib</li>
<li>Added the following definition to web.xml
<pre class="brush: xml; title: ; notranslate">
    &lt;servlet&gt;
        &lt;servlet-name&gt;icepush&lt;/servlet-name&gt;
        &lt;servlet-class&gt;org.icepush.servlet.ICEpushServlet&lt;/servlet-class&gt;
        &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
        &lt;servlet-name&gt;icepush&lt;/servlet-name&gt;
        &lt;url-pattern&gt;*.icepush&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
</pre>
</li>
<li>on the web-page initialized the IcePush with
<pre class="brush: jscript; title: ; notranslate">
//loaded required scripts
        &lt;script type=&quot;text/javascript&quot; src=&quot;#{request.contextPath}/code.icepush&quot;&gt;&lt;/script&gt;
        &lt;script type=&quot;text/javascript&quot; src=&quot;#{request.contextPath}/js/icepush/jquery.icepush.js&quot;&gt;&lt;/script&gt;
//initialized the icepush client
    &lt;script type=&quot;text/javascript&quot;&gt;
        var myPushNotificationCallback = function(){
           //do something on push callback. 
           //it may be ajax request to the server based on jQuery-ajax or a4j:jsFunction, whatever
           //for simplicity I will just call alert
           alert(&quot;Push notification arrived&quot;);
        }
        jQuery(document).ready(function () {
            //set the uriPrefix so icepush will make requests to the correct URL
            ice.push.configuration.uriPrefix = '#{baseAppPath}/';
            //register the icepush client, based on the user-primary-key
            jQuery.push.listenToGroup(&quot;myPushGroup_UsR_#{loggedInUser.pk}&quot;, myPushNotificationCallback);
        });
    &lt;/script&gt;

</pre>
</li>
<li>On the server side call the IcePush in the places I want to send notification (as a reaction to some event)<br />
We can call method pushToUserList directly, but I wrapped it so it become asynchronous call, so it don&#8217;t slow-down the http-request processing (it may send notifications to several clients and as long it is network operation, it&#8217;s may cause a significant delay)</p>
<pre class="brush: java; title: ; notranslate">
@Name(&quot;pushAsyncExecutor&quot;)
@Scope(ScopeType.APPLICATION)
public class PushAsyncExecutor implements Serializable {

    private static Log log = Logging.getLog(PushAsyncExecutor.class);

    @Asynchronous
    @SuppressWarnings(&quot;unused&quot;)
    public QuartzTriggerHandle  pushToUserList (@Expiration Date when,
                                                String pushGroup, Collection&lt;Long&gt; userIds) {
        pushToUserList(pushGroup, userIds);
        return null;
    }

    public static void pushToUserList(String pushGroup, Collection&lt;Long&gt; userIds) {
        log.trace(&quot;Started pushToUserListImpl&quot;);
        try {
            PushContext pushContext = PushContext.getInstance(SeamComponentFactory.getServletContext());
            for (Long userId : userIds) {
                pushContext.push(getUserNotificationGroupName(pushGroup, userId));
            }
        } catch (Throwable ex){
            log.error(&quot;Failed to push updates&quot;, ex);
        }
        log.trace(&quot;Finished pushToUserListImpl&quot;);
    }

    /**
     * this method generate the push-id for the userId and &quot;pushGroup&quot;
     */
    private static String getUserNotificationGroupName(String pushGroup, Long userId) {
        return new StringBuilder(pushGroup.length() + 16).append(pushGroup).append(&quot;_UsR_&quot;).append(userId).toString();
    }
}
</pre>
</li>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/achorniy.wordpress.com/378/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/achorniy.wordpress.com/378/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=achorniy.wordpress.com&#038;blog=8544771&#038;post=378&#038;subd=achorniy&#038;ref=&#038;feed=1" width="1" height="1" /><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?a=H7mRs0w1I6E:oieVw5nlqAI:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?a=H7mRs0w1I6E:oieVw5nlqAI:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?i=H7mRs0w1I6E:oieVw5nlqAI:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?a=H7mRs0w1I6E:oieVw5nlqAI:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/achorniy/sdevelopment/~4/H7mRs0w1I6E" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://achorniy.wordpress.com/2012/02/29/icepush-integration-to-web-application/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/75c2bdacfd2d62abcbfe7beda3d9c613?s=96&amp;d=identicon&amp;r=G" medium="image">
			<media:title type="html">achorniy</media:title>
		</media:content>

		<media:content url="http://achorniy.files.wordpress.com/2012/02/fast-running-flash.gif?w=300" medium="image">
			<media:title type="html">Push notifications are fast as Running Flash</media:title>
		</media:content>

		<media:content url="http://achorniy.files.wordpress.com/2012/02/icepush-simplearch.png" medium="image">
			<media:title type="html">IcePush-simpleArch</media:title>
		</media:content>

		<media:content url="http://achorniy.files.wordpress.com/2012/02/icepush-request-sequence.png" medium="image">
			<media:title type="html">icepush-request-sequence</media:title>
		</media:content>
	<feedburner:origLink>http://achorniy.wordpress.com/2012/02/29/icepush-integration-to-web-application/</feedburner:origLink></item>
		<item>
		<title>How to avoid primary page conversation timeout on background requests in Seam. Hacking around Seam request lifecycle</title>
		<link>http://feedproxy.google.com/~r/achorniy/sdevelopment/~3/ojniiTqnR5Y/</link>
		<comments>http://achorniy.wordpress.com/2012/02/27/avoid-seam-conversation-timeout-on-background-requests/#comments</comments>
		<pubDate>Mon, 27 Feb 2012 17:55:26 +0000</pubDate>
		<dc:creator>Andrey Chorniy</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[browser windows]]></category>
		<category><![CDATA[conversation]]></category>
		<category><![CDATA[conversation timeout]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[language java]]></category>
		<category><![CDATA[request lifecycle]]></category>
		<category><![CDATA[seam]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[web-application]]></category>

		<guid isPermaLink="false">http://achorniy.wordpress.com/?p=380</guid>
		<description><![CDATA[It will be not easy to read and understand this article, so please remember that you always have a choice to not read it So,.. in our app we have few background processes on the page which are periodically ping<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://achorniy.wordpress.com/2012/02/27/avoid-seam-conversation-timeout-on-background-requests/">Read more &#8250;</a></div><!-- end of .read-more --><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=achorniy.wordpress.com&#038;blog=8544771&#038;post=380&#038;subd=achorniy&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><img class="alignleft size-medium wp-image-433" title="problem-solved" src="http://achorniy.files.wordpress.com/2012/02/problem-solved1.jpeg?w=300&#038;h=182" alt="Sometimes it's better to avoid something. Avoid can be a solution" width="300" height="182" />It will be not easy to read and understand this article, so please remember that you always have a choice to not read it <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /><br />
So,.. in our app we have few background processes on the page which are periodically ping server and update some page parts. Now I think this is not the greatest approach and we should use a real PUSH technology instead of periodic ping in every place where it is possible, but anyway. Our problem was that those requests (if they were handled by Seam Context-Filter) may cause our conversation (the page which user open in the browser) to be destroyed because of conversation timeout. And it really doesn&#8217;t work for us, since that really &#8220;secondary&#8221; requests may kill our primary conversation (especially if we have several browser windows opened)<br />
So, to summarize the problem &#8211; &#8220;periodic seam requests (ajax requests) cause the destroying of the conversation&#8221;, so, if user don&#8217;t do any activity on the page during the conversation timeout &#8211; the next his action show the &#8220;Conversation timed out&#8221; message.</p>
<p>Partial solution here could be not use Seam ContextFilter for that requests, but in that case we couldn&#8217;t use our Seam components (so it don&#8217;t work for us)<br />
The better solution (I think) &#8211; is to &#8220;Avoid timing-out the conversation in our background requests&#8221;. It is what will be described below. However the Much Better Solution would be also &#8220;Avoiding the background periodic requests by using a real push approach&#8221; &#8211; like it is shown in the <a href="http://achorniy.wordpress.com/2012/02/29/icepush-integration-to-web-application/">IcePush integration post</a>. But that not always work, but definitely preferable solution.<br />
So, the workaround for us was to establish Seam environment for the request but don&#8217;t cause the the same environment as it is done in the <a title="org.jboss.seam.web.ContextFilter" href="http://grepcode.com/file/repository.jboss.org/maven2/org.jboss.seam/jboss-seam/2.0.0.GA/org/jboss/seam/web/ContextFilter.java">org.jboss.seam.web.ContextFilter</a> but don&#8217;t call the <a href="http://grepcode.com/file/repository.jboss.org/nexus/content/repositories/releases/org.jboss.seam/jboss-seam/2.0.0.GA/org/jboss/seam/core/Manager.java#Manager.conversationTimeout%28java.util.Map%29">Manager.conversationTimeout() </a></p>
<p>Finally solution looks like 2 classes (created from Seam ContextFilter and ContextualHttpServletRequest)<br />
pretty simple ContextFilterWithoutTimeout (it just create and run ContextualHttpServletRequestWOTimeout)</p>
<pre class="brush: java; title: ; notranslate">
import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import org.jboss.seam.web.AbstractFilter;

public class ContextFilterWithoutTimeout extends AbstractFilter {
   public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain)
       throws IOException, ServletException
   {
      new ContextualHttpServletRequestWOTimeout( (HttpServletRequest) request )
      {
         @Override
         public void process() throws ServletException, IOException
         {
            chain.doFilter(request, response);
         }
      }.run();
   }
}
</pre>
<p>and the ContextualHttpServletRequestWOTimeout which is a copy of ContextualHttpServletRequest with commented call to<br />
<strong>// Manager.instance().endRequest( new ServletRequestSessionMap(request) );</strong><br />
so it doesn&#8217;t call the touchConversationStack() and Manager.instance().conversationTimeout(session);<br />
as the result our request don&#8217;t update anything in the conversation stack and don&#8217;t cause the timing-out of conversations<br />
&#8220;destroyConversation( conversationEntry.getId(), session );&#8221;<br />
it doesn&#8217;t mean that conversations will not be timed out &#8211; they will, but they will do it as a result of primary user request (or request which is working through Seam ContextFilter). So we don&#8217;t change Seam request processing completely, but create the way to make exceptions in request processing, so we can create requests which will not cause our conversations to be timed-out.</p>
<pre class="brush: java; title: ; notranslate">
   public void run() throws ServletException, IOException
   {
      log.debug(&quot;beginning request&quot;);

      // Force creation of the session
      if (request.getSession(false) == null)
      {
         request.getSession(true);
      }

      // Begin request and Seam life cycle only if it is not nested
      // ContextualHttpServletRequest
      if (getCounterValue() == 0)
      {
         ServletLifecycle.beginRequest(request);
         ServletContexts.instance().setRequest(request);
         restoreConversationId();
         Manager.instance().restoreConversation();
         ServletLifecycle.resumeConversation(request);
         handleConversationPropagation();
      }

      try
      {
         incrementCounterValue();

         process();

         decrementCounterValue();

         // End request only if it is not nested ContextualHttpServletRequest
         if (getCounterValue() == 0)
         {
//            Manager.instance().endRequest( new ServletRequestSessionMap(request)  );
            ServletLifecycle.endRequest(request);
         }
      }
      catch (IOException ioe)
      {
         removeCounter();
         Lifecycle.endRequest();
         log.debug(&quot;ended request due to exception&quot;);
         throw ioe;
      }
      catch (ServletException se)
      {
         removeCounter();
         Lifecycle.endRequest();
         log.debug(&quot;ended request due to exception&quot;);
         throw se;
      }
      catch (Exception e)
      {
         removeCounter();
         Lifecycle.endRequest();
         log.debug(&quot;ended request due to exception&quot;);
         throw new ServletException(e);
      }
      finally
      {
         log.debug(&quot;ended request&quot;);
      }
   }
</pre>
<p>in the web.xml we declare the filter and servlets which will use it. We map this filter to the servlets which make periodic background calls to the server</p>
<pre class="brush: xml; title: ; notranslate">
    &lt;filter&gt;
        &lt;filter-name&gt;No Conversation Timeout Filter&lt;/filter-name&gt;
        &lt;filter-class&gt;ContextFilterWithoutTimeout&lt;/filter-class&gt;
    &lt;/filter&gt;
    &lt;filter-mapping&gt;
        &lt;filter-name&gt;No Conversation Timeout Filter&lt;/filter-name&gt;
        &lt;servlet-name&gt;LongOperationsServlet&lt;/servlet-name&gt;
    &lt;/filter-mapping&gt;
    &lt;filter-mapping&gt;
        &lt;filter-name&gt;No Conversation Timeout Filter&lt;/filter-name&gt;
        &lt;servlet-name&gt;PollServlet&lt;/servlet-name&gt;
    &lt;/filter-mapping&gt;
</pre>
<p>As I said before &#8211; it doesn&#8217;t completely change the Seam request processing, it just let us to avoid conversation timeout for our primary page. In case user will open two pages and leave them for certain time (larger than configured conversation timeout) &#8211; only the first page he will interact with will continue conversation, because on the first interaction the other conversation 9form other page) will be timed out. But that is expected behavior of Seam conversations and we are not going to change it. What we solve here &#8211; is that our primary conversation will not be destroyed because of our background (secondary) calls and that those secondary calls will have an access to all Seam components.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/achorniy.wordpress.com/380/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/achorniy.wordpress.com/380/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=achorniy.wordpress.com&#038;blog=8544771&#038;post=380&#038;subd=achorniy&#038;ref=&#038;feed=1" width="1" height="1" /><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?a=ojniiTqnR5Y:VlsDxELjyf8:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?a=ojniiTqnR5Y:VlsDxELjyf8:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?i=ojniiTqnR5Y:VlsDxELjyf8:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?a=ojniiTqnR5Y:VlsDxELjyf8:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/achorniy/sdevelopment/~4/ojniiTqnR5Y" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://achorniy.wordpress.com/2012/02/27/avoid-seam-conversation-timeout-on-background-requests/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/75c2bdacfd2d62abcbfe7beda3d9c613?s=96&amp;d=identicon&amp;r=G" medium="image">
			<media:title type="html">achorniy</media:title>
		</media:content>

		<media:content url="http://achorniy.files.wordpress.com/2012/02/problem-solved1.jpeg?w=300" medium="image">
			<media:title type="html">problem-solved</media:title>
		</media:content>
	<feedburner:origLink>http://achorniy.wordpress.com/2012/02/27/avoid-seam-conversation-timeout-on-background-requests/</feedburner:origLink></item>
		<item>
		<title>Conditional re-rendering in JSF (Richfaces)</title>
		<link>http://feedproxy.google.com/~r/achorniy/sdevelopment/~3/uW9tKoYqPzQ/</link>
		<comments>http://achorniy.wordpress.com/2012/02/23/conditional-re-rendering-jsf-richfaces/#comments</comments>
		<pubDate>Thu, 23 Feb 2012 21:31:21 +0000</pubDate>
		<dc:creator>Andrey Chorniy</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jsf]]></category>
		<category><![CDATA[richfaces]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://achorniy.wordpress.com/?p=401</guid>
		<description><![CDATA[It happens that you want something to be re-rendered only if ajax-request is executed without errors. Or in other words &#8211; you want to be lazy if it possible and not perform &#8220;reRender&#8221; if you could. Just like that funny<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://achorniy.wordpress.com/2012/02/23/conditional-re-rendering-jsf-richfaces/">Read more &#8250;</a></div><!-- end of .read-more --><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=achorniy.wordpress.com&#038;blog=8544771&#038;post=401&#038;subd=achorniy&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><img class="alignright size-medium wp-image-414" title="I_m_Not_Lazy" src="http://achorniy.files.wordpress.com/2012/02/i_m_not_lazy2.jpeg?w=240&#038;h=200" alt="" width="240" height="200" /><br />
It happens that you want something to be re-rendered only if ajax-request is executed without errors. Or in other words &#8211; you want to be lazy if it possible and not perform &#8220;reRender&#8221; if you could. Just like that funny guy &#8211; he have to be lazy to be strong <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /><br />
For example you have a dialog which call some ajax-action and you want to re-render it only if ajaxrequest is executed without errors<br />
if yo&#8217;ll put a plain it will always reRender the &#8220;list&#8221; &#8211; even if ajax request has errors.
<pre class="brush: xml; title: ; notranslate">

&lt;a4j:commandLink action=&quot;#{actionBean.action}&quot; reRender=&quot;list&quot; value=&quot;Run&quot;
onComplete=&quot;if (!hasAjaxErrors()){closeModalPanel();}&quot;/&gt;

</pre>
<p>the workaround could be moving the reRendering to a separate a4j:jsFunction call and call it only when you want it</p>
<pre class="brush: xml; title: ; notranslate">

&lt;a4j:commandLink action=&quot;#{actionBean.action}&quot; value=&quot;Run
onComplete=&quot;if (!hasAjaxErrors()){closeModalPanel();onCompleteFunction()}&quot;/&gt;

&lt;a4j:jsFunction name=&quot;onCompleteFunction&quot; reRender=&quot;list&quot; ajaxSingle=&quot;true&quot;/&gt;

</pre>
<p>pretty easy and your &#8220;list&#8221; will be reRendered only after success call to the &#8220;#{actionBean.action}&#8221;</p>
<p>XHTML code to inject the error-severity in the input field &#8220;requestSeverity&#8221;</p>
<pre class="brush: xml; title: ; notranslate">
    &lt;a4j:outputPanel ajaxRendered=&quot;true&quot; id=&quot;severityPanel&quot;&gt;
        &lt;h:form prependId=&quot;false&quot; style=&quot;display:none&quot; &gt;
            &lt;h:inputHidden id=&quot;requestSeverity&quot;
value=&quot;#{facesContext.maximumSeverity.ordinal}&quot;/&gt;
        &lt;/h:form&gt;
    &lt;/a4j:outputPanel&gt;
</pre>
<p>Javascript function to check presence of errors (error-messages-severity)</p>
<pre class="brush: jscript; title: ; notranslate">
function hasAjaxErrors() {
    var errorSeverityElement = document.getElementById(&quot;requestSeverity&quot;);
    if (errorSeverityElement){
        return errorSeverityElement.value &gt;= 2;
    }
    return false;
}
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/achorniy.wordpress.com/401/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/achorniy.wordpress.com/401/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=achorniy.wordpress.com&#038;blog=8544771&#038;post=401&#038;subd=achorniy&#038;ref=&#038;feed=1" width="1" height="1" /><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?a=uW9tKoYqPzQ:4A3spR7ZUHs:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?a=uW9tKoYqPzQ:4A3spR7ZUHs:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?i=uW9tKoYqPzQ:4A3spR7ZUHs:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?a=uW9tKoYqPzQ:4A3spR7ZUHs:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/achorniy/sdevelopment/~4/uW9tKoYqPzQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://achorniy.wordpress.com/2012/02/23/conditional-re-rendering-jsf-richfaces/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/75c2bdacfd2d62abcbfe7beda3d9c613?s=96&amp;d=identicon&amp;r=G" medium="image">
			<media:title type="html">achorniy</media:title>
		</media:content>

		<media:content url="http://achorniy.files.wordpress.com/2012/02/i_m_not_lazy2.jpeg?w=300" medium="image">
			<media:title type="html">I_m_Not_Lazy</media:title>
		</media:content>
	<feedburner:origLink>http://achorniy.wordpress.com/2012/02/23/conditional-re-rendering-jsf-richfaces/</feedburner:origLink></item>
		<item>
		<title>Useful Eclipse navigation shortcuts for java developer</title>
		<link>http://feedproxy.google.com/~r/achorniy/sdevelopment/~3/Ajl81JxoHG8/</link>
		<comments>http://achorniy.wordpress.com/2011/06/14/eclipse_navigation_shortcuts/#comments</comments>
		<pubDate>Tue, 14 Jun 2011 15:49:59 +0000</pubDate>
		<dc:creator>Andrey Chorniy</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://achorniy.wordpress.com/?p=356</guid>
		<description><![CDATA[I find that this article (10 Eclipse Navigation Shortcuts&#8230;) is great and will save you a lot of time in development/coding if you are programming in Eclipse. I personally prefer Intellij Idea for java development, but in case of Android<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://achorniy.wordpress.com/2011/06/14/eclipse_navigation_shortcuts/">Read more &#8250;</a></div><!-- end of .read-more --><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=achorniy.wordpress.com&#038;blog=8544771&#038;post=356&#038;subd=achorniy&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I find that this <a title="10 Eclipse Navigation Shortcuts Every Java Programmer Should Know" href="http://rayfd.wordpress.com/2007/05/20/10-eclipse-navigation-shortcuts-every-java-programmer-should-know/" target="_blank">article (10 Eclipse Navigation Shortcuts&#8230;)</a> is great and will save you a lot of time in development/coding if you are programming in Eclipse. I personally prefer Intellij Idea for java development, but in case of Android &#8220;Eclipse + ADT plugin&#8221; doesn&#8217;t leave much chances to alternative IDE&#8217;s.<br />
Great shortcuts, I use part of them before and really miss &#8220;CTRL-E&#8221; <em>Go to other open editors</em></p>
<p><img class="alignnone" title="Go to other open editors" src="http://rayfd.files.wordpress.com/2007/05/ctrl_e.jpg?w=325&#038;h=271" alt="Go to other open editor" width="325" height="271" /></p>
<p>and &#8220;CTRL-O&#8221; <em>Go directly to a member (method, variable)</em></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/achorniy.wordpress.com/356/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/achorniy.wordpress.com/356/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=achorniy.wordpress.com&#038;blog=8544771&#038;post=356&#038;subd=achorniy&#038;ref=&#038;feed=1" width="1" height="1" /><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?a=Ajl81JxoHG8:e_Lij4KD7Yw:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?a=Ajl81JxoHG8:e_Lij4KD7Yw:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?i=Ajl81JxoHG8:e_Lij4KD7Yw:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?a=Ajl81JxoHG8:e_Lij4KD7Yw:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/achorniy/sdevelopment/~4/Ajl81JxoHG8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://achorniy.wordpress.com/2011/06/14/eclipse_navigation_shortcuts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/75c2bdacfd2d62abcbfe7beda3d9c613?s=96&amp;d=identicon&amp;r=G" medium="image">
			<media:title type="html">achorniy</media:title>
		</media:content>

		<media:content url="http://rayfd.files.wordpress.com/2007/05/ctrl_e.jpg" medium="image">
			<media:title type="html">Go to other open editors</media:title>
		</media:content>
	<feedburner:origLink>http://achorniy.wordpress.com/2011/06/14/eclipse_navigation_shortcuts/</feedburner:origLink></item>
		<item>
		<title>Richfaces a4j:poll and a4j:push Can Do More Together</title>
		<link>http://feedproxy.google.com/~r/achorniy/sdevelopment/~3/tRne_ox8aw4/</link>
		<comments>http://achorniy.wordpress.com/2011/02/27/richfaces-a4j-poll-and-push-can-do-more-together/#comments</comments>
		<pubDate>Sun, 27 Feb 2011 17:01:36 +0000</pubDate>
		<dc:creator>Andrey Chorniy</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[ajax-push]]></category>
		<category><![CDATA[icefaces]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jsf]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[richfaces]]></category>

		<guid isPermaLink="false">http://achorniy.wordpress.com/?p=314</guid>
		<description><![CDATA[Task: Update the content of the page if the content is changed on server-side, in other words &#8211; show the most-fleshiest content to the user. The most simple solution that comes to mind is to use &#60;a4j:poll/&#62; component which will periodically<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://achorniy.wordpress.com/2011/02/27/richfaces-a4j-poll-and-push-can-do-more-together/">Read more &#8250;</a></div><!-- end of .read-more --><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=achorniy.wordpress.com&#038;blog=8544771&#038;post=314&#038;subd=achorniy&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a href="http://achorniy.files.wordpress.com/2011/02/together-we-can-do-it.jpg"><img class="alignleft size-full wp-image-331" title="Together we can do it!" src="http://achorniy.files.wordpress.com/2011/02/together-we-can-do-it.jpg?w=605" alt=""   /></a>Task: Update the content of the page if the content is changed on server-side, in other words &#8211; show the most-fleshiest content to the user.</p>
<p>The most simple solution that comes to mind is to use <a href="http://livedemo.exadel.com/richfaces-demo/richfaces/poll.jsf">&lt;a4j:poll/&gt; component</a> which will periodically call some action which will load fresh content and re-render the content on the page. But that not very optimal since you will create the content on server-side and send it back to the client each time you execute the polling request. </p>
<p><a href="http://livedemo.exadel.com/richfaces-demo/richfaces/push.jsf">a4j:push component</a> looks like the one who was created to avoid that every-time re-rendering. Here is what demo-site says about it:</p>
<blockquote><p>The main difference between a4j:push and a4j:poll components is that a4j:push makes request to minimal code only (not to JSF tree) in order to check the presence of messages in the queue. If the message exists the complete request will be performed. The component doesn&#8217;t poll registered beans but registers EventListener which receives messages about events.</p></blockquote>
<p>Looks very promising, but in reality it&#8217;s a kind of tricky to integrate it with your real application because some code on the server side should execute something like that:</p>
<blockquote><p>
synchronized (listener) {<br />
    listener.onEvent(new EventObject(this));<br />
}
</p></blockquote>
<p>But, to do so we should have something in background which will periodically check for updates and generate the events and send them to our listener. Starting a Thread is not good option since we have to worry about the way to stop it, as well who start Thread&#8217;s in web-apps ? @Asynchronous task is better one option, but still has the same issues &#8211; we have to worry about it lifecycle and stop updates at some point (user may leave the page or close his browser) so we actually has no good way to manage the lifecycle of launched background tasks.<br />
At first I try to use a4j:push with action=&#8221;#{myActionBean.checkForUpdates}&#8221; but action is not called by a4j:push, it just checks if he has new events and only if it has such &#8211; execute action and do reRendering (all that JSF lifecycle)&nbsp;</p>
<p>But it looks like combination of a4j:poll and a4j:push could work here in that way.</p>
<ul>
<li>a4j:poll execute an action which check for updates in the data and fire an Event if they are exists</li>
<li>a4j:push periodically check for new events and re-render content on new event</li>
</ul>
<p>So, a4:poll play role of assistant, actually it&#8217;s like the managed background task on the serverside which periodically poll for the data, but it&#8217;s live on the client-side, so in case user will close his browser &#8211; server will not execute the requests to datsource anymore.</p>
<p>I call it a &#8220;conditional re-rendering&#8221;. Here is the JSF code I use to make it working.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;a4j:form id=&quot;pollForm&quot; eventsQueue=&quot;queue&quot;&gt;
    &lt;a4j:region id=&quot;pollRegion&quot; selfRendered=&quot;true&quot; renderRegionOnly=&quot;true&quot;&gt;
        &lt;a4j:poll action=&quot;#{myActionBean.checkForNewData}&quot;
            id=&quot;datasetChangedChecker&quot; interval=&quot;#{myActionBean.pollInterval}&quot;
            ajaxSingle=&quot;true&quot; limitToList=&quot;true&quot; immediate=&quot;true&quot; bypassUpdates=&quot;true&quot;&gt;
        &lt;/a4j:poll&gt;
    &lt;/a4j:region&gt;
&lt;!-- the function below execute an ajax-call to server which enable the push and re-render &lt;a4j:push /&gt; to start it --&gt;
&lt;a4j:jsFunction name=&quot;startPushUpdates&quot;
                action=&quot;#{myActionBean.startPushUpdates}&quot;
                reRender=&quot;dataSetReRendererPush&quot; ajaxSingle=&quot;true&quot;/&gt;
&lt;/a4j:form&gt;

&lt;a4j:form id=&quot;pushForm&quot; eventsQueue=&quot;queue&quot;&gt;
    &lt;a4j:push id=&quot;dataSetReRendererPush&quot; ajaxSingle=&quot;true&quot;
              eventProducer=&quot;#{myActionBean.addUpdatesListener}&quot;
              interval=&quot;#{myActionBean.pollInterval}&quot;
              reRender=&quot;contentPanel,datasetChangedChecker,dataSetReRendererPush&quot;
              enabled=&quot;#{myActionBean.pushUpdatesStarted}&quot;
     /&gt;
&lt;/a4j:form&gt;

&lt;a4j:outputPanel id=&quot;contentPanel&quot;&gt;
   &lt;!-- Updated content goes here --&gt;
&lt;/a4j:outputPanel&gt;
</pre>
<p>The only issue here is that we have to ensure that a4j:push is executed AFTER a4j:poll so action called in a4j:poll will generate the event before we will execute the a4j:push. Unfortunately we don&#8217;t have the way to manage it in JSF with attributes, but that could be done with help of postponed launching of a4j:push (with some reasonable gap which should be bigger than time required to execute check for data-updates)<br />
The postponed a4j:push execution is achieved with enabling it with &#8216;enabled=&#8221;#{myActionBean.pushUpdatesStarted}&#8221;&#8216; attribute and calling the javascript with timeout</p>
<pre class="brush: jscript; title: ; notranslate">
jQuery(document).ready(function() {
    window.setTimeout(startPushUpdates, 5000);
});
</pre>
<p>so, having all that JSF code and MyActionBean.java we have quite optimal solution<br />
I didn&#8217;t include java-code here but I believe if you read this line than you most probably got the idea and capable to implement it on your own <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><strong>Future notes</strong>: it looks that <a href="http://www.icefaces.org/main/ajax-java/ajaxpush.iface">IceFaces </a>propose their own vision of ajax-push and it&#8217;s not based on periodical polling of server from server-side.<br />
<img src="http://www.icefaces.org/main/css/images/icepush-ajaxpush.png" alt="IceFaces push model" /><br />
As well they have <a href="http://wiki.icefaces.org/display/ICE/Direct-to-DOM+Rendering">Direct-To-Dom</a> rendering which looks like much more optimal way of re-Rendering. Haven&#8217;t tried it yet, but for me it looks ajax-push at IceFaces and re-rendering is a more optimal solution.<br />
It would be nice to hear from the ones who try both <a href="http://www.tikalk.com/java/icefaces-vs-richfaces">RichFaces and IceFaces ajax push approaches</a>.<br />
BTW, just find that RichFaces team <a href="http://www.jroller.com/a4j/entry/richfaces_4_0_0_milestone1">prepare some updates to a4j:push in RF-4.0</a></p>
<blockquote><p>With this release we have added a few new components, redesigned a4j:push to use advanced Comet implementation and JMS servers</p></blockquote>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/achorniy.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/achorniy.wordpress.com/314/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=achorniy.wordpress.com&#038;blog=8544771&#038;post=314&#038;subd=achorniy&#038;ref=&#038;feed=1" width="1" height="1" /><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?a=tRne_ox8aw4:7V_dRAWoGUI:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?a=tRne_ox8aw4:7V_dRAWoGUI:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?i=tRne_ox8aw4:7V_dRAWoGUI:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?a=tRne_ox8aw4:7V_dRAWoGUI:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/achorniy/sdevelopment/~4/tRne_ox8aw4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://achorniy.wordpress.com/2011/02/27/richfaces-a4j-poll-and-push-can-do-more-together/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/75c2bdacfd2d62abcbfe7beda3d9c613?s=96&amp;d=identicon&amp;r=G" medium="image">
			<media:title type="html">achorniy</media:title>
		</media:content>

		<media:content url="http://achorniy.files.wordpress.com/2011/02/together-we-can-do-it.jpg" medium="image">
			<media:title type="html">Together we can do it!</media:title>
		</media:content>

		<media:content url="http://www.icefaces.org/main/css/images/icepush-ajaxpush.png" medium="image">
			<media:title type="html">IceFaces push model</media:title>
		</media:content>
	<feedburner:origLink>http://achorniy.wordpress.com/2011/02/27/richfaces-a4j-poll-and-push-can-do-more-together/</feedburner:origLink></item>
		<item>
		<title>Export to Excel with jXLS can be faster</title>
		<link>http://feedproxy.google.com/~r/achorniy/sdevelopment/~3/i9OrKRueavM/</link>
		<comments>http://achorniy.wordpress.com/2011/02/14/faster-excel-export-jxls/#comments</comments>
		<pubDate>Mon, 14 Feb 2011 19:05:18 +0000</pubDate>
		<dc:creator>Andrey Chorniy</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Excel]]></category>
		<category><![CDATA[export]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jxls]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://achorniy.wordpress.com/?p=306</guid>
		<description><![CDATA[I got a question about the jXLS performance, in short it was like &#8220;jXLS is a kind of slow for my big reports&#8221;. I mentioned that in my previous post (Creating Excel reports from java is easy) It&#8217;s true, especially<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://achorniy.wordpress.com/2011/02/14/faster-excel-export-jxls/">Read more &#8250;</a></div><!-- end of .read-more --><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=achorniy.wordpress.com&#038;blog=8544771&#038;post=306&#038;subd=achorniy&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a href="http://achorniy.files.wordpress.com/2011/02/say-slow.jpg"><img class="alignleft size-full wp-image-309" title="Slowness it's not happiness" src="http://achorniy.files.wordpress.com/2011/02/say-slow.jpg?w=605" alt=""   /></a>I got a question about the jXLS performance, in short it was like &#8220;jXLS is a kind of slow for my big reports&#8221;.<br />
I mentioned that in my previous post (<a href="http://achorniy.wordpress.com/2009/12/02/creating-excel-reports-from-java-is-easy/">Creating Excel reports from java is easy</a>)</p>
<p>It&#8217;s true, especially about latest jXLS, after I updated my jxls-0.9.8 to 1.0-RC1 (see <a href="http://sourceforge.net/projects/jxls/files/jxls/">downloads</a>) I noticed that report generation become <strong>MUCH SLOWER</strong>. I believe the difference is in the expression library version <a href="http://commons.apache.org/jexl/">JEXL</a>. In the 1.0-RC1 they start using JEXL-2.0.1 version and before they use JEXL-1.1<br />
Anyway, it looks downgrading it back to the jXLS 0.9.8 solves my problems, the performance is not blazing fast but much better than in jXLS 1.0. I bet jXLS 0.9.9 work faster than 1.0</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/achorniy.wordpress.com/306/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/achorniy.wordpress.com/306/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=achorniy.wordpress.com&#038;blog=8544771&#038;post=306&#038;subd=achorniy&#038;ref=&#038;feed=1" width="1" height="1" /><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?a=i9OrKRueavM:_gJeOMP-gAA:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?a=i9OrKRueavM:_gJeOMP-gAA:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?i=i9OrKRueavM:_gJeOMP-gAA:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?a=i9OrKRueavM:_gJeOMP-gAA:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/achorniy/sdevelopment/~4/i9OrKRueavM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://achorniy.wordpress.com/2011/02/14/faster-excel-export-jxls/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/75c2bdacfd2d62abcbfe7beda3d9c613?s=96&amp;d=identicon&amp;r=G" medium="image">
			<media:title type="html">achorniy</media:title>
		</media:content>

		<media:content url="http://achorniy.files.wordpress.com/2011/02/say-slow.jpg" medium="image">
			<media:title type="html">Slowness it's not happiness</media:title>
		</media:content>
	<feedburner:origLink>http://achorniy.wordpress.com/2011/02/14/faster-excel-export-jxls/</feedburner:origLink></item>
		<item>
		<title>Howto disable form submit on Enter and fix for RichFaces rich:inputNumberSpinner</title>
		<link>http://feedproxy.google.com/~r/achorniy/sdevelopment/~3/kPYBst5MZwE/</link>
		<comments>http://achorniy.wordpress.com/2010/11/06/disable-enter-form-submit-fix-inputnumberspinner/#comments</comments>
		<pubDate>Sat, 06 Nov 2010 00:37:10 +0000</pubDate>
		<dc:creator>Andrey Chorniy</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[inputNumberSpinner]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[jsf]]></category>
		<category><![CDATA[richfaces]]></category>

		<guid isPermaLink="false">http://achorniy.wordpress.com/?p=284</guid>
		<description><![CDATA[It&#8217;s quite generic problem &#8211; to disable automatic form submit on ENTER, to avoid occasional submits which could lead either to page refresh or even to redirecting to another page. The general idea is to define onkeypressed event handler for<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://achorniy.wordpress.com/2010/11/06/disable-enter-form-submit-fix-inputnumberspinner/">Read more &#8250;</a></div><!-- end of .read-more --><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=achorniy.wordpress.com&#038;blog=8544771&#038;post=284&#038;subd=achorniy&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>It&#8217;s quite generic problem &#8211; to disable automatic form submit on ENTER, to avoid occasional submits which could lead either to page refresh or even to redirecting to another page.<br />
The general idea is to define onkeypressed event handler for text input fields<br />
Here is the <a href="http://www.cs.tut.fi/~jkorpela/forms/enter.html">article</a> which describe the general approach to do it in HTML.</p>
<p>we can assign onkeypressed event handler to all fields just with few lines (with help of JQuery of course)</p>
<pre class="brush: jscript; title: ; notranslate">
function noEnter() {
    return !(window.event &amp;&amp; window.event.keyCode == ENTER_KEY_CODE);
}

jQuery(document).ready(function(){
      jQuery(:input:text).keypress(function(){
           return noEnter();
      });
});
</pre>
<p>That works fine for a lot of components, but not for  rich:inputNumberSpinner.  &#8221;onkeypressed&#8221; handler was assigned and was called, but &#8230; it still not work, after a plenty time in debug I finally ensured that it not working and start investigating the richfaces sources for that component and found that it has a javascript command that DIRECTLY perform the form submit. And there is no way to prevent this behavior using tags or javascript handlers.<br />
BTW &#8211; I really like new google-chrome developer tools, pretty good and *faster* alternative to FireBug in FF)</p>
<p>After some googling I  found that there is an RF issue exists (not resolved yet) and there is no way to prevent form submission according to the <a href="https://jira.jboss.org/browse/RF-8385">richfaces-issue</a> and actually in the <a href="http://community.jboss.org/message/548195" target="_blank">related-post</a> this issue is described in details, but it looks that solution could be only fixing the RichFaces library itself.<br />
So, let&#8217;s do it!  We will need to build it form sources, since direct update of the script in the jar-file is not working &#8211; richfaces have minified scripts and they are pretty hard to read/modify <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>You can <a href="http://www.4shared.com/file/uZcc2zFx/richfaces-ui-333Final.html" target="_blank">download patched richfaces-ui.jar</a> from here.</p>
<ol>
<li>Download <a href="http://www.jboss.org/richfaces/download/stable.html" target="_blank">RichFaces sources</a> (I prefer to use stable builds)</li>
<li>Extract them and navigate to the file in which form-submission is done &#8220;ui/inputnumber-spinner/src/main/resources/org/richfaces/renderkit/html/script/SpinnerScript.js&#8221;</li>
<li>comment out that crazy row
<pre class="brush: jscript; title: ; notranslate">
        if (e.keyCode == 13){
            if (this.spinner.required || &quot;&quot; != this.edit.value)
                this.edit.value = this.getValidValue(this.edit.value);
            if (this.edit.form) {
//                this.edit.form.submit();
            }
        }
}
</pre>
</li>
<li>Lets build the Richfaces from sources. The first problem you can met is the memory. We will need a bunch of memory, so ensure that you have 64-bit java (since you will need a lot of memory &#8211; about 1500MB &#8211; I was not able to allocate this amount on 32-bit java in Windows-XP)<br />
so, instead of redefining env variables I just copied mvn.bat to mvn64.bat and added the following lines</p>
<pre class="brush: bash; title: ; notranslate">
set JAVA_HOME=E:/Java/jdk/jdk.1.6_64
set MAVEN_OPTS=-Xms512m -Xmx2048m -XX:PermSize=256m -XX:MaxPermSize=512m
</pre>
</li>
<li>no lets rebuild richfaces-ui to do it, let&#8217;s grab few command-lines from developmentBuild.sh
<pre class="brush: bash; title: ; notranslate">
cd %PROJECT_DIR%/ui
mvn64  clean install -Dmaven.test.skip=true
cd %PROJECT_DIR%/ui/assembly
mvn64  clean install -Dmaven.test.skip=true
</pre>
</li>
<li>Let&#8217;s take a cup of tea since it will take a while&#8230;<br />
<a href="http://achorniy.files.wordpress.com/2010/11/cup-of-tea1.jpg"><img class="size-thumbnail wp-image-289 alignnone" title="cup-of-tea" src="http://achorniy.files.wordpress.com/2010/11/cup-of-tea1.jpg?w=150&#038;h=105" alt="" width="150" height="105" /></a></li>
<li>After build is done you will find the updated richfaces-ui.jar in the local maven repository.<br />
<span style="font-family:monospace;">${repository-home}/org/richfaces/ui/richfaces-ui/3.3.3.Final/richfaces-ui-3.3.3.Final.jar</span></li>
</ol>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/achorniy.wordpress.com/284/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/achorniy.wordpress.com/284/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=achorniy.wordpress.com&#038;blog=8544771&#038;post=284&#038;subd=achorniy&#038;ref=&#038;feed=1" width="1" height="1" /><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?a=kPYBst5MZwE:SfZWP0QYfQQ:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?a=kPYBst5MZwE:SfZWP0QYfQQ:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?i=kPYBst5MZwE:SfZWP0QYfQQ:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?a=kPYBst5MZwE:SfZWP0QYfQQ:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/achorniy/sdevelopment/~4/kPYBst5MZwE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://achorniy.wordpress.com/2010/11/06/disable-enter-form-submit-fix-inputnumberspinner/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/75c2bdacfd2d62abcbfe7beda3d9c613?s=96&amp;d=identicon&amp;r=G" medium="image">
			<media:title type="html">achorniy</media:title>
		</media:content>

		<media:content url="http://achorniy.files.wordpress.com/2010/11/cup-of-tea1.jpg?w=150" medium="image">
			<media:title type="html">cup-of-tea</media:title>
		</media:content>
	<feedburner:origLink>http://achorniy.wordpress.com/2010/11/06/disable-enter-form-submit-fix-inputnumberspinner/</feedburner:origLink></item>
		<item>
		<title>HierarchyViewer missed in Android SDK r07 for Windows</title>
		<link>http://feedproxy.google.com/~r/achorniy/sdevelopment/~3/UlE6EB_3PkA/</link>
		<comments>http://achorniy.wordpress.com/2010/10/29/android-hierarchyviewer-missed-sdkr07/#comments</comments>
		<pubDate>Fri, 29 Oct 2010 21:02:53 +0000</pubDate>
		<dc:creator>Andrey Chorniy</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[android layout optimization]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[sdk]]></category>

		<guid isPermaLink="false">http://achorniy.wordpress.com/?p=276</guid>
		<description><![CDATA[I just updated to Android SDK-r07 and find out that I don&#8217;t have hierarchy-viewer tool anymore, what a nice surprise I know this program is stored in hierarchyviewer.jar so just created the hv.bat in tools directory with just java -Xmx512m <span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://achorniy.wordpress.com/2010/10/29/android-hierarchyviewer-missed-sdkr07/">Read more &#8250;</a></div><!-- end of .read-more --><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=achorniy.wordpress.com&#038;blog=8544771&#038;post=276&#038;subd=achorniy&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I just updated to <a href="http://developer.android.com/sdk/index.html">Android SDK-r07 </a> and find out that I don&#8217;t have hierarchy-viewer tool anymore, what a nice surprise <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /><br />
I know this program is stored in hierarchyviewer.jar so just created the hv.bat in tools directory with just</p>
<pre>java -Xmx512m  -jar ./lib/hierarchyviewer.jar</pre>
<p>.. and it works for me.</p>
<p><a href="http://achorniy.files.wordpress.com/2010/10/hierarchy-viewer.png"><img class="alignnone size-medium wp-image-277" title="Hierarchy-Viewer" src="http://achorniy.files.wordpress.com/2010/10/hierarchy-viewer.png?w=300&#038;h=230" alt="" width="300" height="230" /></a></p>
<p>Another way &#8211; is to download <a href="http://dl.google.com/android/android-sdk_r06-windows.zip">Android-SDK-r06</a> and take hierarchyviewer.bat from it. Still don&#8217;t know how it happens that Android-SDK-r07 miss that great tool launcher</p>
<p>For those who don&#8217;t know nothing about that great tool, I recommend to take a look at <a href="http://developer.android.com/resources/articles/layout-tricks-efficiency.html">article about layout-efficiency in android</a> and <a href="http://developer.android.com/resources/articles/layout-tricks-merge.html">about layout-optimization</a> &#8211; and start using  and  in your layouts. And of course spend some time exploring your view-s in HierarchyViewer.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/achorniy.wordpress.com/276/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/achorniy.wordpress.com/276/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=achorniy.wordpress.com&#038;blog=8544771&#038;post=276&#038;subd=achorniy&#038;ref=&#038;feed=1" width="1" height="1" /><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?a=UlE6EB_3PkA:Vjgld5caxK0:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?a=UlE6EB_3PkA:Vjgld5caxK0:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?i=UlE6EB_3PkA:Vjgld5caxK0:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?a=UlE6EB_3PkA:Vjgld5caxK0:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/achorniy/sdevelopment/~4/UlE6EB_3PkA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://achorniy.wordpress.com/2010/10/29/android-hierarchyviewer-missed-sdkr07/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/75c2bdacfd2d62abcbfe7beda3d9c613?s=96&amp;d=identicon&amp;r=G" medium="image">
			<media:title type="html">achorniy</media:title>
		</media:content>

		<media:content url="http://achorniy.files.wordpress.com/2010/10/hierarchy-viewer.png?w=300" medium="image">
			<media:title type="html">Hierarchy-Viewer</media:title>
		</media:content>
	<feedburner:origLink>http://achorniy.wordpress.com/2010/10/29/android-hierarchyviewer-missed-sdkr07/</feedburner:origLink></item>
		<item>
		<title>Show dynamic progress of time-consuming process in Seam/RichFaces</title>
		<link>http://feedproxy.google.com/~r/achorniy/sdevelopment/~3/_-amRK7NKuE/</link>
		<comments>http://achorniy.wordpress.com/2010/10/22/show-dynamic-process-progress-in-seam-richfaces/#comments</comments>
		<pubDate>Fri, 22 Oct 2010 10:06:08 +0000</pubDate>
		<dc:creator>Andrey Chorniy</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[a4j]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[asynchronous]]></category>
		<category><![CDATA[asynchronous data processing]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jsf]]></category>
		<category><![CDATA[richfaces]]></category>
		<category><![CDATA[seam]]></category>
		<category><![CDATA[usability]]></category>
		<category><![CDATA[web-application]]></category>

		<guid isPermaLink="false">http://achorniy.wordpress.com/?p=248</guid>
		<description><![CDATA[Sometimes you need to start really time-consuming task on the server, but doing that with simple h:commandAction which will re-render page after it is done is not a good idea. Showing a4j:status (which could be blocking &#8211; see &#8220;avoid concurrent<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://achorniy.wordpress.com/2010/10/22/show-dynamic-process-progress-in-seam-richfaces/">Read more &#8250;</a></div><!-- end of .read-more --><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=achorniy.wordpress.com&#038;blog=8544771&#038;post=248&#038;subd=achorniy&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Sometimes you need to start really time-consuming task on the server, but doing that with simple h:commandAction which will re-render page after it is done is not a good idea. Showing a4j:status (which could be blocking &#8211; see &#8220;<a href="http://achorniy.wordpress.com/2009/07/14/avoid-concurrent-call-to-conversation/">avoid concurrent call to conversation</a>&#8220;) &#8211; is a bit better and will work for relatively short tasks (like 5 &#8211; 15 seconds, matter of taste actually) but still not good solution for really long tasks (something more than 1 minute)</p>
<p>For really long tasks I recommend to show the progress indicator (it&#8217;s also known usability fact that user will think that task with dynamic progress-bar is faster than the same task but without progress-bar)</p>
<p>There is a quite good component to do it with Richfaces &#8211; it&#8217;s <a href="http://livedemo.exadel.com/richfaces-demo/richfaces/progressBar.jsf" target="_blank">progressBar</a> component, the only problem to do it with Seam is that you should initiate progress (by calling the action) and that action should immediately return and start some background process.  It&#8217;s always bad practice to use Thread&#8217;s in the web-containers, in Seam we have alternative <a href="http://docs.jboss.org/seam/2.2.1.CR2/reference/en-US/html/jms.html#d0e21542">Asynchronous tasks</a>, but.. the problem with them is that they actually will be running in completely separate scope (they don&#8217;t know nothing about your conversation scope)</p>
<p>The trick here is to pass all the required parameters to asynchronous method and use them for returning the results too (in the conversation). That way we are not crazy about memory issues, since as long the long computation process will be ended the memory will be released (the reference to the object will be only in the initiator &#8211; the conversation scoped bean)</p>
<p>So, the solution may look like that.</p>
<ol>
<li>Define the PrgressBean.java which will hold all required initialization parameters for the process and methods to access the progress-state</li>
<li>add &#8220;progressBean&#8221; attribute (+getter) in your action-class (ConversationBean.java)</li>
<li>define methods to start process which will make a call to asynchronous method in other &#8220;LongProcess.java&#8221; and pass the progress bean to it</li>
<li>add rich:progressBar and start/stop buttons in &#8220;commandPanel&#8221; (could be done inside progressBar only), + &#8220;updatedResults&#8221; &#8211; here you can show intermediate and final results during the process (optional)</li>
</ol>
<p>In short &#8211; it is all you need to show very informative long-running process progress.</p>
<h3>Future Notes:</h3>
<p>Richfaces has few other ways to build your own progressBean &#8211; it is <a href="http://livedemo.exadel.com/richfaces-demo/richfaces/poll.jsf">a4j:poll</a> and <a href="http://livedemo.exadel.com/richfaces-demo/richfaces/push.jsf" target="_blank">a4j:push</a> components. rich:progressBean actually utilize &#8220;pooling&#8221; approach, in most cases it&#8217;s quite enough to periodically update progress/results for the user, so actually there is no much sense to write your own  approach using a4j:poll.  a4j:push maybe quite good alternative to rich:progressBar since it use much less traffic and doesn&#8217;t update JSF tree (so it&#8217;s potentially a better alternative). I think you can easily adapt described approach to use a4j:push &#8211; you just need to add few pieces  (addListener method and send events to the listener during the process)</p>
<h3>Code-Snippets</h3>
<p><strong>Java Code:</strong></p>
<pre class="brush: java; title: ; notranslate">
@Name(&quot;longProcess&quot;)
@AutoCreate
public class LongProcess {
    private ProgressBean progress
    @Asynchronous
    public void startProcess(ProgressBean progress) {
        this.progress = progress;
        this.progress.setInProgress(true);
        try {
            runProcess();
        } finally {
            this.progress.setInProgress(false);
        }
    }

   private void runProcess(){
     //perform your time-consuming operations here and periodically update the progress status
....
     progress.setPprogress(progressValue);
....
     if (progress.shouldStop()){
        //finish long process and return
     }
....
   }
}

@Name(&quot;conversationBean&quot;)
@Scope(ScopeType.CONVERSATION)
public class ConversationBean  {
    private ProgressBean progressBean = new ProgressBean();
    @In LongProcess longProcess;

    public void startProcess(){
        if (!progressBean.isInProgress()) {
           progressBean = createNewProgressBean(); //initialize it with required parameters here
           longProcess.startProcess(progressBean);
        }
    }
    public ProgressBean getProgressBean(){
        return progressBean;
    }
    public void stopProcess(){
       progressBean.stop(); //update the internal state of progress-bean so long-process will check it and stop
    }
}
</pre>
<p><strong>Richfaces/JSF code</strong></p>
<pre class="brush: xml; title: ; notranslate">
&lt;h:panelGroup id=&quot;commandPanel&quot;&gt;
&lt;a4j:commandButton action=&quot;#{conversationBean.startProcess}&quot;
        value=&quot;Start&quot; onclick=&quot;this.disabled=true;&quot;
        rendered=&quot;#{!conversationBean.progressBean.inProgress}&quot;
        reRender=&quot;commandPanel,proggressPanel,updatedResults&quot;&gt;
&lt;/a4j:commandButton&gt;
&lt;a4j:commandButton action=&quot;#{conversationBean.stopProcess}&quot;
        value=&quot;Stop&quot; onclick=&quot;this.disabled=true;&quot;
        reRender=&quot;commandPanel,proggressPanel,updatedResults&quot;
        rendered=&quot;#{suggestedEventController.progressBean.inProgress}&quot;&gt;
&lt;/a4j:commandButton&gt;
&lt;/h:panelGroup&gt;

&lt;a4j:outputPanel id=&quot;proggressPanel&quot;&gt;
&lt;rich:progressBar value=&quot;#{conversationBean.progressBean.progress}&quot;
                  label=&quot;#{conversationBean.progressBean.progress} %&quot;
                  enabled=&quot;#{conversationBean.progressBean.inProgress}&quot;
                  minValue=&quot;-1&quot; maxValue=&quot;100&quot;
                  interval=&quot;#{conversationBean.updateRate}&quot;
                  reRender=&quot;#{conversationBean.shouldUpdateTable ? 'updatedResults':'anyEmptyComponent'}&quot;
                  reRenderAfterComplete=&quot;proggressPanel, updatedResults, commandPanel&quot;&gt;
    &lt;f:facet name=&quot;initial&quot;&gt;
        &lt;h:outputText value=&quot;&amp;amp;lt; Click to start&quot;/&gt;
       &lt;!-- we also may show here button to start process as in RichFaces example (I use separate commandPanel instead) --&gt;
    &lt;/f:facet&gt;
    &lt;f:facet name=&quot;complete&quot;&gt;
        &lt;h:outputText value=&quot;Process Completed&quot;/&gt;
      &lt;!-- we also may show here button to restart process as in RichFaces example --&gt;
    &lt;/f:facet&gt;
&lt;/rich:progressBar&gt;

&lt;h:panelGroup id=&quot;updatedResults&quot;&gt;
      &lt;!-- it could be used to show results (for example list of processed or generated rows) --&gt;
     &lt;rich:dataTable value=&quot;#{conversationBean.progressBean.items}&gt;
     &lt;/rich:dataTable&gt;
&lt;/h:panelGroup&gt;
&lt;/a4j:outputPanel&gt;
</pre>
<p>Please take a notice at 2 parameters used in rich:progressBar<br />
<strong><code>interval="#{conversationBean.updateRate}" </code></strong><br />
it use a method conversationBean.updateRate to determine the update rate. I&#8217;s optional and could be just hardcoded to some value like &#8220;1000&#8243; (1 second). Can be used to dynamically set it to appropriate value, so your progress bar will not be updated to often and can be even changed during a process to fit to your real update rate</p>
<p><strong><code>reRender="#{conversationBean.shouldUpdateTable ? 'updatedResults':'anyEmptyComponent'}"</code> </strong><br />
As you see reRender here use dynamic condition, so conversationBean has a control other it and can skip heavy &#8220;updatedResults&#8221; update to save a traffic </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/achorniy.wordpress.com/248/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/achorniy.wordpress.com/248/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=achorniy.wordpress.com&#038;blog=8544771&#038;post=248&#038;subd=achorniy&#038;ref=&#038;feed=1" width="1" height="1" /><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?a=_-amRK7NKuE:5iFlxl0UNeE:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?a=_-amRK7NKuE:5iFlxl0UNeE:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?i=_-amRK7NKuE:5iFlxl0UNeE:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?a=_-amRK7NKuE:5iFlxl0UNeE:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/achorniy/sdevelopment?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/achorniy/sdevelopment/~4/_-amRK7NKuE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://achorniy.wordpress.com/2010/10/22/show-dynamic-process-progress-in-seam-richfaces/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/75c2bdacfd2d62abcbfe7beda3d9c613?s=96&amp;d=identicon&amp;r=G" medium="image">
			<media:title type="html">achorniy</media:title>
		</media:content>
	<feedburner:origLink>http://achorniy.wordpress.com/2010/10/22/show-dynamic-process-progress-in-seam-richfaces/</feedburner:origLink></item>
	</channel>
</rss>
