Ajax and JavaScript Recipes

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0
This documentation refers to version 2.1 which has not been released yet.
Warning
2.1
titleDojo plugin is deprecated

The Dojo plugin will be deprecated on Struts 2.1

Table of Contents
indent20px
stylenone
minLevel3

...

Code Block
HTML
<script type="text/javascript">
  dojo.event.topic.subscribe("/value", function(textEnteredtext, date, widget){
      alert('value changed');
      //textEntered: String eneteredentered in the textbox
      //date: JavaScript Date object with the value selected
      //widetwidget: widget that published the topic 
  });
</script> 

<sx:datetimepicker label="Order Date" valueNotifyTopics="/value"/>
Use other locales.
Warning

Locales must be specified in the sx:head tag.

Code Block
HTML
<sx:head extraLocales="en-us,nl-nl,de-de" />

<sx:datetimepicker label="In German" name="dddp7" value="%{'2006-06-28'}" language="de-de" />
<sx:datetimepicker label="In Dutch"  name="dddp8" value="%{'2006-06-28'}" language="nl-nl" />

...

Code Block
HTML
<sx:autocompleter list="{'apple','banana','grape','pear'}" value="apple" />
Force valid option (restore option when focus is lost)

...

Code Block
Java
titleAutocompleterExample.java
public class AutocompleterExample extends ActionSupport {

   public Map<String, String> getOptions() {
      Map<String,String> options = new HashMap<String,String>();
      options.put("FLFlorida", "FloridaFL");
      options.put("ALAlabama", "AlabamaAL");

      return options;
   }
}

The mapping:

...

Code Block
HTML
<s:form id="form">
  <sx:autocompleter name="options" label="Options" />
</s:form>
Set initial key and value
Code Block
HTML
1JSP page

<s:url id="optionsUrl" namespace="/autocompleter" action="getStates" />

<sx:autocompleter href="%{#optionsUrl}" value="Florida" keyValue="FL"/>
Change default key name

The action:

...