|
|||||||||||||||||||||||||||||||||||||
Description
Provides a HTML form submission element <input type="submit">. The Submit component must be wrapped by a Form. This component is generally only used when the form has multiple submit buttons, and it is important for the application to know which one was pressed. You may also want to use ImageSubmit which accomplishes much the same thing, but uses a graphic image instead. In typical use, the application needs to know which Submit was the one clicked by the user. This can be accomplished in two ways:
If a listener is used, it will be invoked as the Submit component is rewound. In addition, the Form's listener be invoked if defined. Use the first method if you need to be sure that the entire form has rewound before any logic specific to the ImageSubmit is triggered. |
|||||||||||||||||||||||||||||||||||||
See Also
Button, Form, Checkbox, Hidden, ImageSubmit, ListEdit, Option, Radio, RadioGroup, Select, TextArea, TextField, ValidField |
|||||||||||||||||||||||||||||||||||||
Parameters
Body: removed |
|||||||||||||||||||||||||||||||||||||
Examples
In this login form the loginSubmit and helpSubmit components use listeners to invoke their actions. Also note how the helpSubmitAction() method redirects to another page using a PageRedirectException .
<form jwcid="@Form"> <table cellpadding="4"> <tr><td>Username:</td><td><input jwcid="@TextField" value="ognl:username" size="12"/></td> </tr> <tr><td>Password:</td><td><input jwcid="@TextField" value="ognl:password" hidden="ognl:true" size="12"/></td> </tr> <tr align="right"> <td colspan="2"> <input type="submit" jwcid="@Submit" listener="ognl:listeners.loginSubmitAction" value="Login"/> <input type="submit" jwcid="@Submit" listener="ognl:listeners.helpSubmitAction" value="Help"/> </td> </tr> </table> </form> public class LoginPage extends BasePage { private String username; private String password; public String getUsername() { return username; } public void setUsername(String value) { username = value; } public String getPassword() { return password; } public void setPassword(String value) { password = value; } public void loginSubmitAction(IRequestCycle cycle) { // Authenticate user's login attempt .. } public void helpSubmitAction(IRequestCycle cycle) throws RequestCycleException { // Redirect to Help Desk page throw new PageRedirectException("HelpDesk"); } protected void initialize() { username = null; password = null; } } | |||||||||||||||||||||||||||||||||||||
In the following example the Submit component uses the selected and
tag parameters to identify the event source in the Form's
listener method.
For more information about this example please see
PropertySelection.
<form jwcid="purchageForm"> Item: <span jwcid="selectItem"/> <p> Description: <span jwcid="insertDescription"/> <p> Label: <span jwcid="insertLabel"/> <p> Price: $<span jwcid="insertPrice"/> <p> <input jwcid="addToCartSubmit" type="Submit"value="Add to Cart"/> </form> <component id="purchaseForm" type="Form"> <binding name="listener" expression="listeners.formSubmit"/> </component> <component id="selectItem" type="PropertySelection"> <binding name="model" expression="itemSelectionModel"/> <binding name="value" expression="clothingItem"/> <binding name="submitOnChange" expression="true"/> <binding name="selected" expression="selectedComponent"/> <binding name="tag" expression='"SELECT_ITEM"'/> </component> <component id="insertDescription" type="Insert"> <binding name="value" expression="clothingItem.description"/> </component> <component id="insertLabel" type="Insert"> <binding name="value" expression="clothingItem.label"/> </component> <component id="insertPrice" type="Insert"> <binding name="value" expression="clothingItem.price"/> </component> <component id="submitAddToCart" type="Submit"> <binding name="selected" expression="selectedComponent"/> <binding name="tag" expression='"SUBMIT_ADD_TO_CHART"'/> </component> public class PurchagePage extends BasePage { private selectedComponent; private String clothingItem; private ItemSelectionModel itemSelectionModel; public String getSelectedComponent() { return selectedComponent; } public void setSelectedComponent(String value) { selectedComponent = value; } public Item getClothingItem() { return clothingItem; } public void setClothingItem(Item value) { clothingItem = value; fireObservedChange("clothingItem", value); } public ItemSelectionModel getItemSelectionModel() { return itemSelectionModel; } public ItemSelectionModel setItemSelectionModel(ItemSelectionModel value) { itemSelectionModel = value; fireObservedChange("itemSelectionModel", value); } public void detach() { selectedComponent = null; clothingItem = null; itemSelectionModel = null; super.detach(); } public void formSubmit(IRequestCycle cycle) { if (getSelectedComponent().equals("SELECT_ITEM")) { // Submit from selectItem component. // Item display will automatically update, but we will log user's // interest in the selected clothing item .. } else if (getSelectedComponent().equals("SUBMIT_ADD_TO_CHART")) { // Submit from submitAddToCart component. // Add selected item to shopping cart Item item = getClothingItem(); .. } } } public class Item implements Serializable { private Integer id; private String name; private String description; private String label; private String price; public Item(Integer id, String name, String desc, String label, String price) { this.id = id; this.name = name; this.description = desc; this.label = label; this.price = price; } public int getId() { return id; } public String getName() { return name; } public int getDescription() { return description; } public int getLabel() { return label; } public int getPrice() { return price; } } public class ItemSelectionModel implements IPropertySelectionModel, Serializable { private List itemList; public ItemPropertySelectionModel(List itemList) { this.itemList = itemList; } public int getOptionCount() { return itemList.size(); } public Object getOption(int index) { return itemList.get(index) } public String getLabel(int index) { return ((Item) itemList.get(index)).getName(); } public String getValue(int index) { Integer.toString(index); } public Object translateValue(String value) { return getOption(Integer.parseInt(value)); } } |