blob: c0f558a34917adf7924849c24d8be9565720c780 [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- $Id$ -->
<html>
<head>
<title>Submit</title>
<link rel="stylesheet" type="text/css" href="Tapestry.css" title="style">
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left"><A href="Shell.html"><IMG alt=Shell src="common-images/prev.png"></A></td>
<td align="middle"><A href="index.html"><IMG alt="Component Index" src="common-images/home.png" ></A></td>
<td align="right"><A href="TextArea.html"><IMG alt=TextArea src="common-images/next.png"></A></td>
<tr>
<tr>
<td colspan="3"><hr></td>
</tr>
<tr>
<td colspan="3">
<table border="0" cellpadding="4" cellspacing="4" width="100%">
<tr valign="top">
<td>
<table>
<tr>
<td><font size="+2"><b>Submit</b></font></td>
</tr>
<tr>
<td>
<A href="../api/org/apache/tapestry/form/Submit.html">
org.apache.tapestry.form.Submit</A>
</td>
</tr>
</table>
</td>
<td>
<table align="right" valign="middle" bgcolor="#c0c0c0" cellspacing="8">
<tr>
<td><input type="submit" value="Submit"></td>
</tr>
</table>
</td>
</table></td>
</tr>
<tr valign="center">
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td colspan="2">
<b>Description</b>
<br>
Provides a HTML form submission element &lt;input type="submit"&gt;.
The Submit component must be wrapped by a <A href="Form.html">Form</A>.
<p>
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
<A href="ImageSubmit.html">ImageSubmit</A>
which accomplishes much the same thing, but uses a graphic image instead.
<P>
In typical use, the application needs to know which Submit was
the one clicked by the user. This can be accomplished in two ways:
<UL>
<LI>Use the <B>listener</B> to perform an operation directly</LI>
<LI>Use the <B>selected</B> and <B>tag</B> parameters to identify the button.</LI>
</UL>
<P>
If a listener is used, it will be invoked as the Submit component is rewound.
In addition, the <A href="Form.html">Form</A>'s listener be invoked if defined.
<P>
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.
</P>
</td>
</tr>
<tr>
<td colspan="2">
<b>See Also</b>
<br>
<A href="Button.html">Button</A>,
<A href="Form.html">Form</A>,
<A href="Checkbox.html">Checkbox</A>,
<A href="Hidden.html">Hidden</A>,
<A href="ImageSubmit.html">ImageSubmit</A>,
<A href="ListEdit.html">ListEdit</A>,
<A href="Option.html">Option</A>,
<A href="Radio.html">Radio</A>,
<A href="RadioGroup.html">RadioGroup</A>,
<A href="Select.html">Select</A>,
<a href="TextArea.html">TextArea</a>,
<A href="TextField.html">TextField</A>,
<A href="ValidField.html">ValidField</A>
</td>
</tr>
<tr>
<td colspan="2">
<b>Parameters</b>
<br>
<table border="1" cellpadding="4" cellspacing="4" class="parameters">
<tr>
<th>Name</th>
<th>Type</th>
<th>Direction</th>
<th>Required</th>
<th>Default</th>
<th>Description</th>
</tr>
<tr>
<td>label</td>
<td>String</td>
<td>in</td>
<td>no</td>
<td>&nbsp;</td>
<td>The label put on the button (this becomes the HTML value attribute).
</td>
</tr>
<tr>
<td>disabled
<td>boolean</td>
<td>in</td>
<td>no</td>
<td>false</td>
<td>
If set to true, the button will be disabled (will not respond to
the mouse); the browser should provide a "greyed out" appearance.
</td>
</tr>
<tr>
<td>selected</td>
<td>Object</td>
<td>out</td>
<td>no</td>
<td>&nbsp;</td>
<td>
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.
</td>
</tr>
<tr>
<td>tag</td>
<td>Object</td>
<td>in</td>
<td>no</td>
<td>&nbsp;</td>
<td>
Tag used with the selected parameter to indicate which Submit button
on a form was clicked.
</td>
</tr>
<tr>
<td>listener</td>
<td>
<A href="../api/org/apache/tapestry/IActionListener.html"><tt>IActionListener</tt></A>
</td>
<td>in</td>
<td>no</td>
<td>&nbsp;</td>
<td>
If specified, the listener is notified. This notification occurs as the
component is rewinded, i.e., prior to the <A href="Form.html">Form</A>'s
listener. In addition, the selected property (if bound) will be updated
<u>before</u> the listener is notified.
</td>
</tr>
</table>
<P>
Body: <STRONG>removed</STRONG><BR>
Informal parameters: <STRONG>allowed</STRONG><br>
Reserved parameters: "name", "type"
</P>
</td>
</tr>
<tr>
<td colspan="2">
<b>Examples</b>
<p>
In this login form the <b>loginSubmit</b> and <b>helpSubmit</b> components use
<A href="../api/org/apache/tapestry/IActionListener.html">listener</A>s
to invoke their actions. Also note how the helpSubmitAction() method
redirects to another page using a
<A href="../api/org/apache/tapestry/PageRedirectException.html"><tt>PageRedirectException</tt></A>
.
<p>
<table class="examples" cellpadding="4">
<form>
<tr>
<td>Username:</td><td><input size="12"></td>
</tr>
<tr>
<td>Password:</td><td><input type="password" size="12"></td>
</tr>
<tr align="right">
<td colspan="2">
<input type="submit" value="Login">
<input type="submit" value="Help">
</td>
</tr>
</form>
</table>
<pre>
&lt;form jwcid="@<a href="Form.html">Form</a>"&gt;
&lt;table cellpadding="4"&gt;
&lt;tr&gt;&lt;td&gt;Username:&lt;/td&gt;&lt;td&gt;&lt;input jwcid="@<a href="TextField.html">TextField</a>" value=&quot;ognl:username&quot; size="12"/&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Password:&lt;/td&gt;&lt;td&gt;&lt;input jwcid="@<a href="TextField.html">TextField</a>" value=&quot;ognl:password&quot; hidden=&quot;ognl:true&quot; size="12"/&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr align="right"&gt;
&lt;td colspan="2"&gt;
&lt;input type="submit" jwcid="<span class="jwcid">@</span><a href="Submit.html">Submit</a>" listener="ognl:listeners.loginSubmitAction" value="Login"/&gt;
&lt;input type="submit" jwcid="<span class="jwcid">@</span><a href="Submit.html">Submit</a>" listener="ognl:listeners.helpSubmitAction" value="Help"/&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/form&gt;
&lt;property-specification name=&quot;username&quot; type=&quot;java.lang.String&quot;/&gt;<br>&lt;property-specification name=&quot;password&quot; type=&quot;java.lang.String&quot;/&gt;<br>
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");
}
}
</pre>
<td></td>
<tr>
<td colspan="2"><hr></td>
</tr>
<tr>
<td colspan="2">
In the following example the Submit component uses the <b>selected</b> and
<b>tag</b> parameters to identify the event source in the Form's
<A href="../api/org/apache/tapestry/IActionListener.html">listener</A> method.
For more information about this example please see
<A href="PropertySelection.html">PropertySelection</a>.
<p>
<table class="examples" valign="middle" cellspacing="8">
<tr>
<td>
<form>
<br>
Item:
<select>
<option selected>Dress</option>
<option>Jacket</option>
<option>Pants</option>
<option>Shirt</option>
<option>Skirt</option>
</select>
<p>
Description: Cotton full length Summer dress
<p>
Label: CountryClub
<p>
Price: $89.95
<p>
<input type="Submit" value="Add to Cart"/>
</form>
</td>
</tr>
</table>
<pre>
&lt;form jwcid="@<A href="Form.html">Form</a>" listener="ognl: listeners.formSubmit"&gt;
Item: &lt;span jwcid="selectItem"/&gt;
&lt;p&gt;
Description: &lt;span jwcid="@<A href="Insert.html">Insert</a>" value="ognl: clothingItem.description"&gt;100% Egyptian Cotton&lt;/span&gt;
&lt;p&gt;
Label: &lt;span jwcid="@<A href="Insert.html">Insert</a>" value="ognl: clothingItem.label"&gt;Jersey Bed Sheet&lt;/span&gt;
&lt;p&gt;
Price: $&lt;span jwcid="@<A href="Insert.html">Insert</a>" value="ognl: clothingItem.price"&gt;$150.00&lt;/span&gt;
&lt;p&gt;
&lt;input jwcid="<span class="jwcid">addToCartSubmit</span>" type="Submit" value="Add to Cart"/&gt;
&lt;/form&gt;
&lt;property-specification name=&quot;itemSelectionModel&quot; type=&quot;ItemSelectionModel&quot; persistent=&quot;yes&quot;/&gt;<br>&lt;property-specification name=&quot;clothingItem&quot; type=&quot;Item&quot; persistent=&quot;yes&quot;/&gt;<br>&lt;property-specification name=&quot;selectedComponent&quot; type=&quot;java.lang.String&quot;/&gt;<br>
&lt;component id="selectItem" type="<A href="PropertySelection.html">PropertySelection</a>"&gt;
&lt;binding name="model" expression="itemSelectionModel"/&gt;
&lt;binding name="value" expression="clothingItem"/&gt;
&lt;binding name="submitOnChange" expression="true"/&gt;
&lt;/component&gt;
&lt;component id="<span class="jwcid">submitAddToCart</span>" type="<A href="Submit.html">Submit</a>"&gt;
&lt;binding name="selected" expression="selectedComponent"/&gt;
&lt;binding name="tag" expression='"SUBMIT_ADD_TO_CHART"'/&gt;
&lt;/component&gt;
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 <A href="../api/org/apache/tapestry/form/IPropertySelectionModel.html">IPropertySelectionModel</a>, 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));
}
}
</pre>
</td>
</tr></table>
<tr>
<td colspan="3"><hr></td>
</tr>
<tr>
<td align="left"><A href="Shell.html"><IMG alt=Shell src="common-images/prev.png"></A></td>
<td align="middle"><A href="index.html"><IMG alt="Component Index" src="common-images/home.png" ></A></td>
<td align="right"><A href="TextArea.html"><IMG alt=TextArea src="common-images/next.png"></A></td>
</tr>
</body>
</html>