AjaxForm
Derivative of tapestry Form wrapped with ajax/dhtml effects.
Note
The inherited parameters of Form are purposefuly left out,
for a list of those paramters consult the documentation for Form.
Parameters
Name | Type | Direction | Required | Default | Description |
---|---|---|---|---|---|
updateComponents | List (or comma-delimited String) | in | no | List of component id strings to refresh after invoking listener. This causes the contents of any html element on the page with a matching id in this list to be replaced, if the specified element is rendered in the return response. | |
updateObject | String | in | no | If specified, the string passed in will be used to build a javascript statement which will call updateObject.ajaxUpdate(element, responseElement, elementId) / updateObject.beforeAjaxUpdate(responseElements) / updateObject.responseComplete(responseElements) | |
backLink | String | in | no | Provides ability to have the action encapsulated by the specified AjaxDirectLink used when users hit back button on browser. | |
forwardLink | String | in | no | Provides ability to have the action encapsulated by the specified AjaxDirectLink used when users hits forward button on browser AFTER hitting back button provided in backLink first. | |
effects | String | in | no | Specifies a list of effects to be applied to the returned response. Read the Effects-Popups page of the UserGuide for more details. | |
preEffects | String | in | no | The same with effects parameter, but specifies effects that should be performed on parts before triggering the ajax request. Read the Effects-Popups page of the UserGuide for more details. | |
popup | String | in | no |
If specified, the updated content will be shown in a floating pane. Read the Effects-Popups page of the UserGuide for more details. |
|
statusElement | String | in | no | If specified, the html element on your page with a matching id to this parameter will be temporarily displayed for a few seconds with status text set on the AjaxWebRequest via addStatusResponse(String). | |
clientValidationEnabled | boolean | in | no | true | Enables client-side validation on the form for standard validator logic setup on fields. The default tapestry method of displaying alert boxes has been overriden by tacos to provide some fairly nice dynamic effects. It is worth checking out before you disable it. |
delegate | IValidationDelegate | in | no | AjaxValidationDelegate | Overrides the default behaviour of the standard form delegate so that when server-side validation logic is specified for a specific form input the error message associated with that error is automatically displayed next to the fields label. |
uniqueNames | boolean | in | no | false | In complex scenarios (page containing multiple loops, each loop making use of the same custom component which in turn contains a tacos component), you might end up with duplicated names in your form elements if you refresh only parts of a form. Setting this parameter to true, will force the AjaxForm to generate names using each component's idPath - making them unique even in the above case. |
Body: rendered
Informal parameters: allowed
Reserved parameters: action, name, onsubmit, onreset, enctype
Examples
This example does a simple submit of an input field in a form.
HTML template
<span jwcid="step1@If" condition="ognl:!country" > <div class="note" > <h2>Step <i>1</i> - Choose Country</h2> <form jwcid="countryForm@tacos:AjaxForm" clientValidationEnabled="ognl:true" listener="listener:chooseCountry" updateComponents="ognl:{'wizard'}" processScripts="ognl:true" backLink="component:clearLink" > <span class="auto_complete" jwcid="autoCompleterFlag" /> <input jwcid="choose@Submit" value="Select" onClick="javascript: return postcountryFormForm(this);"/> </form> </div> </span>
Page specification
<page-specification class="net.sf.tacos.demo.pages.forms.FormEffectsExample"> <description>Example of using multiple effects/components.</description> <property name="countryValue" persist="session" /> <property name="country" persist="session" /> <property name="searchList" initial-value="ognl:new java.util.ArrayList()" /> <property name="localeList" initial-value="ognl:new java.util.ArrayList()" /> <property name="regionDate" /> <property name="regionValue" initial-value="literal:some region.." /> <component id="autoCompleterFlag" type="tacos:Autocompleter" > <binding name="displayName" value="literal:Country" /> <binding name="value" value="ognl:countryValue"/> <binding name="validators" value="validators:required,minLength=4" /> <binding name="listSource" value="ognl:localeList" /> <binding name="listener" value="listener:searchCountries" /> <binding name="listItemRenderer" value="ognl:listRenderer" /> <binding name="direct" value="ognl:true" /> </component> <component id="regionForm" type="tacos:AjaxForm" > <binding name="listener" value="listener:chooseRegion" /> <binding name="updateComponents" value="ognl:{'wizard'}" /> </component> <component id="clearLink" type="tacos:AjaxDirectLink" > <binding name="listener" value="listener:clearCountry" /> <binding name="updateComponents" value="ognl:{'wizard'}" /> </component> </page-specification>
Java sources
public abstract class FormEffects extends BasePage { /** Logger */ private static final Log log = LogFactory.getLog(FormEffects.class); /** List html renderer */ private static final ListItemRenderer FLAG_RENDERER = new CountryFlagRenderer(); public ListItemRenderer getListRenderer() { return FLAG_RENDERER; } /** * Invoked by ajax request to perform autocomplete search. * * @param search The value to search on */ public void searchCountries(String search) { //Performs country name search search = search.toUpperCase(); Locale[] locales = Locale.getAvailableLocales(); ArrayList searchList = new ArrayList(); ArrayList localeList = new ArrayList(); for (int i = 0; i < locales.length; i++) { if (locales[i].getDisplayCountry().toUpperCase().indexOf(search) > -1) { searchList.add(locales[i].getDisplayCountry()); localeList.add(locales[i]); } } setSearchList(searchList); setLocaleList(localeList); } /** * Invoked by form * @param cycle */ public void chooseCountry(IRequestCycle cycle) { String country = (String)cycle.getParameter("autoCompleterFlag"); if (country == null) return; Locale[] locales = Locale.getAvailableLocales(); for (int i = 0; i < locales.length; i++) { if (locales[i].getDisplayCountry().toUpperCase().equals(country.toUpperCase())) { setCountry(locales[i]); break; } } String submitName = (String)cycle.getParameter("choose"); if (submitName != null) { log.debug("chooseCountry() found choose button submit with value:" + submitName); } } /** * Invoked to clear the chosen country. * @param cycle */ public void clearCountry(IRequestCycle cycle) { setCountry(null); } /** * Does nothing * @param cycle */ public void chooseRegion(IRequestCycle cycle) { IValidationDelegate delegate = getDelegate(); delegate.setFormComponent((IFormComponent) getComponent("regionField")); delegate.recordFieldInputValue(getRegionValue()); delegate.record("You suck, this doesn't look right at all",ValidationConstraint.CONSISTENCY); return; //setCountry(null); } /** Set by invocation of {@link #searchCountries(String)} */ public abstract Collection getSearchList(); /** Sets the search list return */ public abstract void setSearchList(Collection values); /** Set by invocation of {@link #searchCountries(String)} */ public abstract Collection getLocaleList(); /** Sets the search list return */ public abstract void setLocaleList(Collection values); /** Sets the chosen country */ public abstract void setCountry(Locale country); /** From region form */ public abstract Date getRegionDate(); /** Validation delegate */ public abstract IValidationDelegate getDelegate(); /** Region value */ public abstract String getRegionValue(); }