|
Project Information
Members
Featured
Downloads
Wiki pages
Links
|
Struts2 jQuery PluginThe struts2-jquery-plugin is a plugin providing first-class support for AJAX to struts2.The plugin uses the jQuery javascript library and a very lightweight publish/subscribe framework built on jQuery to implement a set of tags and tag widgets that enable asynchronous loading of UI components and de-coupled interaction between UI components in a simple, standard way.- Check out the project Showcase - Check out the new Chart component - Latest version uses (jquery 1.4.2 and final jQuery-ui.1.8.1) Contents
Basic UsageTo use the struts2-jquery tags
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sj" uri="/struts2-jquery-tags" %>
<html>
<head>
<sj:head compressed="false"/>
<title><s:text name="application.title"/></title>
</head>
<body>
<sj:div id="header" src="header.action"/>
<sj:div id="content" src="content.action"/>
<sj:div id="footer" src="footer.action"/>
</body>
</html>
TagsThe following tags/widgets are implemented (click on each for more details and usage): Basic Usage
Components
Widgets
FeaturesThe tags have a lot of attributes which provide dynamic functionality and provide relevant event/event-handling hooks using the publish/subscribe framework to interact with each other or with custom client code. The easiest way to summarize the functionality provided by the tags is to list the features that the various 'types' of tags provide: Loading Remote Content (anchor, dialog, div, submit)
'Input' Components (select,textfield,textarea,datepicker)
'Interactive' Components (div,select,submit,textfield,tab,dialog,datepicker)
General Features (all components)
Publish/Subscribe FrameworkThe plugin uses a very lightweight but powerful publish/subscribe framework which allows for fully decoupled interaction between component events. The framework comes with out-of-the box hooks for common component events (clickTopics) and event handlers (such as onClickTopics) which allow the components on the page to interact very flexibly yet simply with each other. For example, to make one div load when another is finished loading or show a dialog if there's a loading error is as easy as follows: <%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sj" uri="/struts2-jquery-tags" %>
<html>
<head>
<sj:head compressed="false"/>
<title><s:text name="application.title"/></title>
</head>
<body>
<sj:div id="firstDiv" onSuccessTopics="loadSuccess" onErrorTopics="loadError" src="first.action"/>
<sj:div id="dependentDiv" showTopics="loadSuccess" src="second.action" cssStyle="display:none"/>
<sj:dialog id="errorDialog" showTopics="loadError" src="error.action"/>
</body>
</html>Another example, to update the contents of a second select box when the value in a first one changes is as easy as follows: <%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sj" uri="/struts2-jquery-tags" %>
<html>
<head>
<sj:head compressed="false"/>
<title><s:text name="application.title"/></title>
</head>
<body>
First Select: <sj:select id="firstSelect" name="firstSelect" onChangeTopics="firstSelectChanged" src="firstSelect.action"/>
Second Select: <sj:select id="secondSelect" reloadTopics="firstSelectChanged" src="secondSelect.action" elementIds="firstSelect"/>
</body>
</html>The publish/subscribe framework is fully exposed, so users can also implement custom handlers for any topics and can publish and subscribe to any topics using custom code as follows: <%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sj" uri="/struts2-jquery-tags" %>
<html>
<head>
<sj:head compressed="false"/>
<title><s:text name="application.title"/></title>
<script type="text/javascript" >
$.subscribe('loadSuccess', function(event,element) {
alert('Successfully loaded first div');
$.publish('loadSuccessConfirm');
});
</script>
</head>
<body>
<sj:div id="firstDiv" onSuccessTopics="loadSuccess" src="first.action"/>
<sj:dialog id="successDialog" showTopics="loadSuccessConfirm" src="error.action"/>
</body>
</html>The above example will:
For additional information on using the integrates publish/subscribe framework, see the jquery.subscribe.js source document included with the plugin or visit the jquery subscribe/publish plugin site at http://plugins.jquery.com/project/jQuerySubscribe. Extending the FrameworkThe framework provides four explicit extension points:
See Customizations / Extensions for more... |