...
Code Block |
---|
|
<s:url id="optionsUrl" namespace="/autocompleter" action="getStates" />
<sx:autocompleter href="%{#optionsUrl}" />
|
Example action
When a form containing an autocompleter is submitted, two values will be submitted for each autocompleter, one for the selected value, and one for its associated key.
The action:
Code Block |
---|
| java |
---|
| java |
---|
title | MyAction.java |
---|
|
public MyAction extends ActionSupport {
private String optionsKey;
private String options;
...
}
|
The JSP:
Code Block |
---|
|
<s:form id="form">
<sx:autocompleter name="options" label="Options" />
</s:form>
|
Change default key name
The action:
Code Block |
---|
| java |
---|
| java |
---|
title | MyAction.java |
---|
|
public MyAction extends ActionSupport {
private String superKey;
private String options;
...
}
|
The JSP:
Code Block |
---|
|
<s:form id="form">
<sx:autocompleter keyName="superKey" name="options" label="Options" />
</s:form>
|
JSON accepted
for this autocompleter:
Code Block |
---|
|
<s:form id="form">
<sx:autocompleter name="state" />
</s:form>
|
The following JSON will be accepted:
Code Block |
---|
| javascript |
---|
| javascript |
---|
title | Map(recommended as it is the easiest one to generate) |
---|
|
{
"Alabama" : "AL",
"Alaska" : "AK"
}
|
Code Block |
---|
| javascript |
---|
| javascript |
---|
title | Array of arrays |
---|
|
[
["Alabama", "AL"],
["Florida", "FL"]
]
|
Code Block |
---|
| javascript |
---|
| javascript |
---|
title | Array inside object, same name as field |
---|
|
{
"state" : [
["Alabama","AL"],
["Alaska","AK"]
]
}
|
Code Block |
---|
| javascript |
---|
| javascript |
---|
title | Map inside object, same name as field |
---|
|
{
"state" : {
"Alabama" : "AL",
"Alaska" : "AK"
}
}
|
Code Block |
---|
| javascript |
---|
| javascript |
---|
title | Array inside object, field in response starts with the name of the autocompleter("state" in this example) |
---|
|
{
"states" : {
"Alabama" : "AL",
"Alaska" : "AK"
}
}
|
Code Block |
---|
| javascript |
---|
| javascript |
---|
title | No name match, use first array found, and hope for the best |
---|
|
{
"Australopithecus" : [
["Alabama","AL"],
["Alaska","AK"]
]
}
|
Load characters while user types (when text size >= 3)
...