org.apache.tapestry.corelib.components.Submit

Corresponds to input type="submit", a client-side element that can force the enclosing form to submit. The submit responsible for the form submission will post a notification that allows the application to know that it was the responsible entity. The notification is named "selected" and has no context.

[JavaDoc]

Component Inheritance

Component Parameters

NameTypeFlagsDefaultDefault PrefixDescription
clientIdStringprop:componentResources.idliteralThe id used to generate a page-unique client-side identifier for the component. If a component renders multiple times, a suffix will be appended to the to id to ensure uniqueness. The uniqued value may be accessed via the clientId property.
deferbooleanpropIf true (the default), then any notification sent by the component will be deferred until the end of the form submission (this is usually desirable).
disabledbooleanfalsepropIf true, then the field will render out with a disabled attribute (to turn off client-side behavior). Further, a disabled field ignores any value in the request when the form is submitted.
labelStringliteralThe user presentable label for the field. If not provided, a reasonable label is generated from the component's id, first by looking for a message key named "id-label" (substituting the component's actual id), then by converting the actual id to a presentable string (for example, "userId" to "User Id").

Examples

The thing to remember is that the Submit component will trigger its "selected" event in the middle of the form submission, before the form triggers its "validate", "success" (or "failure") and "submit" events. Thus the best thing to do is to store in a temporary field what should be done inside the "success" event handler.

EditUser.tml

<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
    <body>

        <h1>Edit User</h1>

        <t:form>

            <t:errors/>

            <t:beaneditor t:id="user"/>

            <p>
                <input type="submit" value="Update User"/>
                <t:submit t:id="delete" value="Delete User"/>
            </p>

        </t:form>
</html>

EditUser.java

public class EditUser
{
    @Inject
    private UserDAO _userDAO;

    @Persist
    private User _user;

    private boolean _deleteUser;

    void onSelectedFromDelete() { _deleteUser = true; }

    Object onSuccess()
    {
        if (_deleteUser)
            _userDAO.delete(user.getId());
        else
            _userDAO.update(user);

        return UserList.class;
    }

    public void setUser(User user) { _user = user; }

    public User getUser() { return _user; }
}

Back to index