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

Username:
Password:

<form jwcid="form">
 <table cellpadding="4">
   <tr><td>Username:</td><td><input jwcid="usernameTextField" size="12"/></td>
  </tr>
   <tr><td>Password:</td><td><input jwcid="passwordTextField" size="12"/></td>
  </tr>
  <tr align="right">
   <td colspan="2">
    <input type="submit" jwcid="loginSubmit" value="Login"/>
    <input type="submit" jwcid="helpSubmit" value="Help"/>
   </td>
  </tr>
 </table>
</form>


<component id="form" type="Form"/>

<component id="usernameTextField" type="TextField">
   <binding name="value" expression="username"/>
</component>

<component id="passwordTextField" type="TextField">
   <binding name="value" expression="password"/>
   <binding name="hidden" expression="true"/>
</component>

<component id="loginSubmit" type="Submit">
   <binding name="listener" expression="listeners.loginSubmitAction"/>
</component>

<component id="helpSubmit" type="Submit">
   <binding name="listener" expression="listeners.helpSubmitAction"/>
</component>


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");
    }
    
    public void detach() {
        username = null;
        password = null;
        super.detach();
    }
}

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.


Item:

Description: Cotton full length Summer dress

Label: CountryClub

Price: $89.95

<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));
    }
}

Shell Component Index TextArea