|
|
|
|
|
|
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:
- Use the listener to perform an operation directly
- Use the selected and tag parameters to identify the button.
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
Name |
Type |
Direction |
Required |
Default |
Description |
label |
String |
in |
no |
|
The label put on the button (this becomes the HTML value attribute).
|
disabled
| boolean |
in |
no |
false |
If set to true, the button will be disabled (will not respond to
the mouse); the browser should provide a "greyed out" appearance.
|
selected |
Object |
out |
no |
|
This parameter is bound to a property that is updated when the submit
button is clicked by the user. The property is updated to match the tag
parameter.
|
tag |
Object |
in |
no |
|
Tag used with the selected parameter to indicate which Submit button
on a form was clicked.
|
listener |
IActionListener
|
in |
no |
|
If specified, the listener is notified. This notification occurs as the
component is rewinded, i.e., prior to the Form's
listener. In addition, the selected property (if bound) will be updated
before the listener is notified.
|
Body: removed
Informal parameters: allowed
Reserved parameters: "name", "type"
|
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>
<property-specification name="username" type="java.lang.String"/> <property-specification name="password" type="java.lang.String"/>
public abstract class LoginPage extends BasePage {
public abstract String getUsername();
public abstract void setUsername(String value);
public abstract String getPassword();
public abstract void setPassword(String 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");
}
}
| |
|
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="@Form" listener="ognl: listeners.formSubmit">
Item: <span jwcid="selectItem"/>
<p>
Description: <span jwcid="@Insert" value="ognl: clothingItem.description">100% Egyptian Cotton</span>
<p>
Label: <span jwcid="@Insert" value="ognl: clothingItem.label">Jersey Bed Sheet</span>
<p>
Price: $<span jwcid="@Insert" value="ognl: clothingItem.price">$150.00</span>
<p>
<input jwcid="addToCartSubmit" type="Submit" value="Add to Cart"/>
</form>
<property-specification name="itemSelectionModel" type="ItemSelectionModel" persistent="yes"/> <property-specification name="clothingItem" type="Item" persistent="yes"/> <property-specification name="selectedComponent" type="java.lang.String"/>
<component id="selectItem" type="PropertySelection">
<binding name="model" expression="itemSelectionModel"/>
<binding name="value" expression="clothingItem"/>
<binding name="submitOnChange" expression="true"/>
</component>
<component id="submitAddToCart" type="Submit">
<binding name="selected" expression="selectedComponent"/>
<binding name="tag" expression='"SUBMIT_ADD_TO_CHART"'/>
</component>
public abstract class PurchagePage extends BasePage {
public abstract String getSelectedComponent();
public abstract void setSelectedComponent(String value);
public abstract Item getClothingItem();
public abstract void setClothingItem(Item value);
public abstract ItemSelectionModel getItemSelectionModel();
public abstract ItemSelectionModel setItemSelectionModel(ItemSelectionModel value);
public void formSubmit(IRequestCycle cycle) {
if (getSelectedComponent().equals("SUBMIT_ADD_TO_CHART")) {
// Submit from submitAddToCart component.
// Add selected item to shopping cart
Item item = getClothingItem();
..
} else {
// Submit from selectItem component.
// Item display will automatically update, but we will log user's
// interest in the selected clothing item
..
}
}
}
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));
}
}
|