JPublish and reverse AJAX; new demo
-application demonstrating how to monitor a text file (log, news,events, etc.) using reverse AJAX through the JPublishDWR module
For those of you interested in AJAX, especially in reverse AJAX ;) I
just committed to the SVN a very simple (and clean) JPublish demo
application demonstrating how to monitor a text file (log, news,
events, etc.) using reverse AJAX through the JPublishDWR module.
Obviously, you can easily tweak my code to monitor last n events from
a log file, or the newest transactions from a database, etc.
Also, for the impatient, I archived the complete application so you
can run it in no time. You can download it from the Downloads page:
http://code.google.com/p/jpublish/downloads/list and is called:
- simpledwr.war.zip
After you download the demo just be sure that, somewhere in a path, you
have a text file that you can edit and update, then modify the
home page of the application (content/index.html) and replace my path
with yours. See: FilePing.setFileName("/Users/flop/news.txt") ... and
replace /Users/flop/news.txt with the full path to the file you want to
monitor in your new and shiny AJAX enabled JPublish web application :)
Have fun!
StringTemplate for JPublish
A couple of weeks ago I stumbled on a few articles about the StringTemplate framework and then, digging further, I started to be attracted by the idea of using StringTemplate for rendering pages in JPublish.
I also needed to be able to learn to use StringTemplate and this is how I found few more very good blog articles at Hardlikesoftware.
In order to learn something, you need to start using it, or at least this is the principle that guides me, and this is how the StringTemplateViewRenderer was born :)
Now you can use StringTemplate to design your web site with JPublish. Is very simple, and to convince you, below are few hints to get you started.
- get JPublish (optional but good to have it handy)
- download a very simple StringTemplate based JPublish web demo application from here.
- in your jpublish.xml of the application you downloaded before you'll find the definition for the the StringTemplateViewRenderer:
<!--StringTemplate Viewer-->For integrating ST with JPublish I am using the Repository objects in JPublish which represent an abstract layer above the file system. Then for every Repository you define in jpublish.xml I am creating a new StringTemplateGroup with the name of the repository and the template root directory being that one of the Repository.
<view-renderer classname="org.jpublish.view.stringtemplate.StringTemplateViewRenderer">
<!--<lexer class="org.antlr.stringtemplate.language.AngleBracketTemplateLexer"/>-->
<lexer class="org.antlr.stringtemplate.language.DefaultTemplateLexer"/>
<!-- todo: <error-listener class=""/>-->
<refresh-interval>15</refresh-interval>
</view-renderer>
So for example, for every JPublish repositories defined, let's say you define the fs_repository like this:
<repository name="fs_repository" classname="org.jpublish.repository.filesystem.FileSystemRepository">when the StringTemplateViewRenderer is initialized, a StringTemplateGroup will be defined for every repository:
<root>content</root>
<cache>default</cache>
</repository>
...For the repository defined above, a new StringTemplateGroup called "fs_repository" will be created as having the template root to the folder 'content' in your web application and the lexer defined earlier in jpublish.xml; org.antlr.stringtemplate.language.DefaultTemplateLexer respectively.
stg = new StringTemplateGroup(repository.getName(),
repository.pathToFile(EMPTY_STRING).getAbsolutePath(), lexer);
...
Then for every page requested from JPublish, a StringTemplateGroup will be asked to return a StringTemplate instance of the page your want.
Exciting enough to get you interested in learning/using StringTemplate for web development? For me sure is, and I just started to learn ST :)
Have fun!
-florin
