Shell Component Index TextArea

Submit
net.sf.tapestry.form.Submit
 
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 selected and tag parameters to identify the button.
  • Use the listener to perform an operation directly

If a listener is used, it will be invoked as the Submit component is rewound. In addition, the Form's listener will always be invoked.

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
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

The following example shows a standard, simple submit button. This example shows both a form, and a single Submit component. The component is setup to call a method on the page implementation when it is clicked.

Keep in mind that it is of course possible to bind the label name to a dynamic property (e.g: the page, or some property of the visit object). This is not done here, purely for simplicity.

<form jwcid="form">
 <input type="submit" jwcid="simpleSubmit" value="Submit"/>
</form>


<component id="form" type="Form">
    <binding name="listener" expression="listeners.formSubmit"/>
</component>
    
<component id="simpleSubmit" type="Submit">
    <binding name="listener" expression="listeners.submitButtonClick"/>
</component>


public class Submit extends BasePage {
    public void formSubmit(IRequestCycle requestCycle) {
        System.out.println("The form was submitted");
    }

    public void submitButtonClick(IRequestCycle requestCycle) {
        System.out.println("The submit button was clicked");
    }
}

The following example shows how you can setup a form that allows you to experiment with a Submit button. It simply excercises some standard properties of the component. If you have the container (J2EE/Servlet) showing then you will be able to see some simple logging when you click the submit buttons, showing you that the right handler is being called at the right time.

Button Name
Disabled?
Dynamic Submit Button
 

<form jwcid="form">
 <table border="0">
  <tr>
   <td>Button Name</td>
   <td><input jwcid="buttonName"/></td>
  </tr>
  <tr>
   <td>Disabled?</td>
   <td><input jwcid="buttonDisabled"/></td>
  </tr>
  <tr>
   <td>Dynamic Submit Button</td>
   <td><input jwcid="complexSubmit"/></td>
  </tr>
  <tr>
   <td>&nbsp;</td>
   <td><input type="submit" value="Make Changes!"/></td>
  </tr>
 </table>
</form>	

  
<bean name="validationDelegate" class="net.sf.tapestry.valid.ValidationDelegate" lifecycle="request"/>
    
<component id="form" type="Form">
    <binding name="delegate" expression="beans.validationDelegate"/>
    <binding name="listener" expression="listeners.formSubmit"/>
</component>

<component id="complexSubmit" type="Submit">
    <binding name="value" expression="buttonName"/>
    <binding name="disabled" expression="buttonDisabled"/>
    <binding name="listener" expression="listeners.complexFormSubmit"/>
</component>
    
<component id="buttonName" type="TextField">
    <binding name="value" expression="buttonName"/>
    <static-binding name="displayWidth">35</static-binding>
</component>
	
<component id="buttonDisabled" type="Checkbox">
    <binding name="selected" expression="buttonDisabled"/>
</component>


public class ComplexSubmit extends BasePage {
    private static String BUTTON_NAME = "Submit";
    private String buttonName = BUTTON_NAME;
    boolean buttonDisabled = true;

    public void detach() {
        buttonName = BUTTON_NAME;
        buttonDisabled = true;
        super.detach();
    }

    public void formSubmit(IRequestCycle requestCycle) {
        System.out.println("Standard form submit was called");
    }

    public void complexFormSubmit(IRequestCycle requestCycle) {
        System.out.println("Complex form submit was called");
    }

    public String getButtonName() { return buttonName; }

	  public void setButtonName(String value) {
        buttonName = value;
        fireObservedChange("buttonName", value);
    }

    public boolean getButtonDisabled() { return buttonDisabled; }

    public void setButtonDisabled(boolean value) {
        buttonDisabled = value;
        fireObservedChange("buttonDisabled", value);
    }
}

Shell Component Index TextArea