<?xml version="1.0"?>
<rss version="2.0">
<channel>
  <title>Spikes Of Nothingness - simple tag</title>
  <link>http://weblog.flop.ca/tags/simple/</link>
  <description>Florin T.PATRASCU&#039;s blog</description>
  <language>en</language>
  <copyright>Florin T.PATRASCU</copyright>
  <lastBuildDate>Sat, 12 May 2012 02:12:08 GMT</lastBuildDate>
  <generator>Pebble (http://pebble.sourceforge.net)</generator>
  <docs>http://backend.userland.com/rss</docs>
  
  
  <item>
    <title>Executing JPublish Actions from DWR? What else can be simpler? :)</title>
    <link>http://weblog.flop.ca/2007/10/27/1193531279888.html</link>
    
      
        <description>
          &lt;p&gt;  &lt;/p&gt;
I was always envying the ability of Webwork to execute Actions via DWR and it was clear that any JPublish user will need something similar. However, I wanted a simpler implementation.&lt;br /&gt;
&lt;br /&gt;
As promised, now you have it:) If you&#039;ll update your &lt;a href=&#034;http://jpublish.googlecode.com/svn/&#034;&gt;JPublish framework from SVN&lt;/a&gt;, including the &lt;a href=&#034;http://jpublish.googlecode.com/svn/trunk/modules/dwr/&#034;&gt;DWR module&lt;/a&gt;, you&#039;ll see what I am talking about . Yup, you can execute any JPublish action (BSH, JS, JRUBY, GROOVY or Java compiled code) making remote calls via DWR. In the SVN there is also a demo showing you how to do this: &lt;a href=&#034;http://jpublish.googlecode.com/svn/trunk/samples/simpledwr/&#034;&gt;SimpleDWR&lt;/a&gt; &lt;br /&gt;
&lt;br /&gt;
In the small explanation below I presume you&#039;re already familiar with how JPublish and DWR work together.&lt;br /&gt;
&lt;br /&gt;
This is what you need to remotely execute a JPublish Action:&lt;br /&gt;
- first modify the dwr.xml file and define the Action you want to publish through the DWR.&lt;br /&gt;
&lt;blockquote&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;init&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;creator id=&amp;quot;jpublish&amp;quot; class=&amp;quot;ca.flop.jpublish.dwr.JPublishCreator&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;/init&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;...&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;create creator=&amp;quot;jpublish&amp;quot; javascript=&amp;quot;InfoAction&amp;quot; scope=&amp;quot;application&amp;quot;&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;param name=&amp;quot;class&amp;quot; value=&amp;quot;ca.flop.jpublish.dwr.DWRJPublishActionManager&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;param name=&amp;quot;actionName&amp;quot; value=&amp;quot;InfoAction.bsh&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;/create&amp;gt;&lt;br /&gt;
&lt;/blockquote&gt;&lt;br /&gt;
- then define the InfoAction.bsh. Here is the code from our &lt;a href=&#034;http://jpublish.googlecode.com/svn/trunk/samples/simpledwr/web/actions/InfoAction.bsh&#034;&gt;SVN example&lt;/a&gt;:&lt;br /&gt;
&lt;blockquote&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;String infoMsg = &amp;quot;Hi, this is JPublish 4&amp;quot;;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;context.put(&amp;quot;infoMsg&amp;quot;, infoMsg);&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;context.put(&amp;quot;serverDate&amp;quot;, new Date());&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;print( infoMsg);&lt;br /&gt;
&lt;/blockquote&gt;&lt;br /&gt;
- now let&#039;s call the InfoAction in an AJAXified HTML page and display the &lt;strong&gt;infoMsg&lt;/strong&gt; and the &lt;strong&gt;serverDate&lt;/strong&gt; values returned by the InfoAction script,&amp;nbsp; a server side BSH script executed by JPublish. Would that be hard? What do you think? Here is the code:&lt;br /&gt;
&lt;blockquote&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;..&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;script type=&#039;text/javascript&#039; src=&#039;$request.ContextPath/dwr/interface/InfoAction.js&#039;/&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;...&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;Below is a simple demonstration of the ability to invoke JPublish Actions via DWR:&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;input type=&amp;quot;button&amp;quot; value=&amp;quot;Info&amp;quot; onclick=&#039;InfoAction.execute( params, function(response) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dwr.util.setValue(&amp;quot;serverDate&amp;quot;, response.serverDate);&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dwr.util.setValue(&amp;quot;info&amp;quot;, response.infoMsg);&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; });&#039;/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;Messages received from server:&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;div class=&amp;quot;dateField&amp;quot; id=&amp;quot;serverDate&amp;quot;&amp;gt;-server date-&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;div class=&amp;quot;salute&amp;quot; id=&amp;quot;info&amp;quot;&amp;gt;JPublish Salute...&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;/blockquote&gt;&lt;br /&gt;
Guess what? Uhhh..... that&#039;s all :)&lt;br /&gt;
&lt;br /&gt;
Have fun!&lt;br /&gt;
-florin&lt;br /&gt;
&amp;nbsp;
        </description>
      
      
    
    
    
    <category>Java</category>
    
    <category>projects</category>
    
    <comments>http://weblog.flop.ca/2007/10/27/1193531279888.html#comments</comments>
    <guid isPermaLink="true">http://weblog.flop.ca/2007/10/27/1193531279888.html</guid>
    <pubDate>Sun, 28 Oct 2007 00:27:59 GMT</pubDate>
  </item>
  
  </channel>
</rss>

