Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Warning
2.1
2.1

This documentation refers to version 2.1 which has not been released yet.

Common

All examples on this page assume the following JSP fragment is on the same page as the example.

Code Block
HTML
HTML
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sx" uri="/struts-dojo-tags" %>

<head>
    <sx:head />
</head>

<s:url id="url" value="/MyAction.action" />

Requests

Request is triggered by a topic
Code Block
HTML
HTML
<s:submit value="Make Request" onclick="dojo.event.topic.publish('/request')" />
<sx:bind listenTopics="/request" href="%{#url}" />
Attached to an event
Code Block
HTML
HTML
<s:submit value="Make Request" id="submit" />
<sx:bind sources="submit" events="onclick" href="%{#url}" />
Attached to an event on multiple sources
Code Block
HTML
HTML
<s:submit value="Make Request" id="submit0" />
<s:submit value="Make Request" id="submit1" />
<sx:bind sources="submit0,submit1" events="onclick" href="%{#url}" />
Attached to multiple events on multiple sources
Code Block
HTML
HTML
<s:textarea id="area0" />
<s:textarea id="area1" />
<sx:bind sources="area0,area1" events="onfocus,onchange" href="%{#url}" />
Update target element with content returned from url
Code Block
HTML
HTML

<s:div id="div" />
<s:submit value="Make Request" id="submit" />
<sx:bind targets="div" sources="submit" events="onclick" href="%{#url}" />
Update multiple target elements with content returned from url
Code Block
HTML
HTML

<s:div id="div0" />
<s:div id="div1" />
<s:submit value="Make Request" id="submit" />
<sx:bind targets="div0,div1" sources="submit" events="onclick" href="%{#url}" />
Show indicator while request is in progress
Code Block
HTML
HTML

<img id="indicator" src="${pageContext.request.contextPath}/images/indicator.gif" style="display:none" />
<s:submit value="Make Request" id="submit" />
<sx:bind sources="submit" events="onclick" href="%{#url}" />
Highlight content of target with blue color, for 2 seconds
Code Block
HTML
HTML

<s:div id="div" />
<s:submit value="Make Request" id="submit" />
<sx:bind highlightColor="blue" highlightDuration="2000" targets="div" sources="submit" events="onclick" href="%{#url}" />
Publish a topic before the request
Code Block
HTML
HTML

<script type="text/javascript">
dojo.event.topic.subscribe("/before", function(event, widget){
   alert('inside a topic event. before request');
   //event: event object
   //widget: widget that published the topic
});
</script>

<s:submit value="Make Request" onclick="dojo.event.topic.publish('/request')" />
<sx:bind beforeNotifyTopics="/before" listenTopics="/request" href="%{#url}" />
Publish a topic before the request
Code Block
HTML
HTML

<script type="text/javascript">
dojo.event.topic.subscribe("/after", function(data, request, widget){
   alert('inside a topic event. after request');
   //data : text returned from request
   //request: XMLHttpRequest object
   //widget: widget that published the topic
});
</script>

<s:submit value="Make Request" onclick="dojo.event.topic.publish('/request')" />
<sx:bind afterNotifyTopics="/after" listenTopics="/request" href="%{#url}" />
Prevent a request
Code Block
HTML
HTML

<script type="text/javascript">
dojo.event.topic.subscribe("/before", function(event, widget){
   alert('I will stop this request');
   event.cancel = true;
});
</script>

<s:submit value="Make Request" onclick="dojo.event.topic.publish('/request')" />
<sx:bind beforeNotifyTopics="/before" listenTopics="/request" href="%{#url}" />