All Implemented Interfaces:
Serializable, Iterable<Component>, IEventSink, IEventSource, IFeedbackContributor, IConverterLocator, IMetadataContext<Serializable,Component>, IFormSubmitter, IFormSubmittingComponent, IHeaderContributor, IRequestableComponent, IHierarchical<Component>, IClusterable

public class SubmitLink extends AbstractSubmitLink
A link which can be used exactly like a Button to submit a Form. The onclick of the link will use JavaScript to submit the form.

You can use this class 2 ways. First with the constructor without a Form object then this Link must be inside a Form so that it knows what form to submit to. Second way is to use the Form constructor then that form will be used to submit to.

 Form f = new Form("linkForm", new CompoundPropertyModel(mod));
     f.add(new TextField("value1"));
     f.add(new SubmitLink("link1") {
         protected void onSubmit() {
             System.out.println("Link1 was clicked, value1 is: "
                                 + mod.getValue1());
         };
      });
      add(new SubmitLink("link2",f) {
          protected void onSubmit() {
              System.out.println("Link2 was clicked, value1 is: "
                                 + mod.getValue1());
           };
      });
 
      <form wicket:id="linkForm" >
          <input wicket:id="value1" type="text" size="30"/>
          <a wicket:id="link1">Press link1 to submit</a>
          <input type="submit" value="Send"/>
      </form>
      <a wicket:id="link2">Press link 2 to submit</a>
 

If this link is not placed in a form or given a form to cooperate with, it will fall back to a normal link behavior, meaning that onSubmit() will be called without any other consequences.

To customize the JavaScript code used to submit the form we must override getTriggerJavaScript(). This can be helpful to implement additional client side behaviors like disabling the link during form submission.

Author:
chris, jcompagner, Igor Vaynberg (ivaynberg), Eelco Hillenius
See Also:
  • Constructor Details

    • SubmitLink

      public SubmitLink(String id)
      With this constructor the SubmitLink must be inside a Form.
      Parameters:
      id - The id of the submitlink.
    • SubmitLink

      public SubmitLink(String id, Form<?> form)
      With this constructor the SubmitLink will submit the Form that is given when the link is clicked on. The SubmitLink doesn't have to be inside the Form. But currently if it is outside the Form and the SubmitLink is rendered first, then the Form will have a generated javascript/css id. The markup javascript/css id that can exist will be overridden.
      Parameters:
      id - The id of the submitlink.
      form - The form which this submitlink must submit.
    • SubmitLink

      public SubmitLink(String id, IModel<?> model)
      With this constructor the SubmitLink must be inside a Form.
      Parameters:
      id - The id of the submitlink.
      model - The model for this submitlink, It won't be used by the submit link itself, but it can be used for keeping state
    • SubmitLink

      public SubmitLink(String id, IModel<?> model, Form<?> form)
      With this constructor the SubmitLink will submit the Form that is given when the link is clicked on. The SubmitLink doesn't have to be in inside the Form. But currently if it is outside the Form and the SubmitLink will be rendered first. Then the Form will have a generated javascript/css id. The markup javascript/css id that can exist will be overridden.
      Parameters:
      id - The id of the submitlink.
      model - The model for this submitlink, It won't be used by the submit link itself, but it can be used for keeping state
      form - The form which this submitlink must submit.
  • Method Details

    • onLinkClicked

      public final void onLinkClicked()
      This method is here as a means to fall back on normal link behavior when this link is not nested in a form. Not intended to be called by clients directly.
      See Also:
    • onComponentTag

      protected void onComponentTag(ComponentTag tag)
      Description copied from class: Component
      Processes the component tag. Overrides of this method most likely should call the super implementation.
      Overrides:
      onComponentTag in class Component
      Parameters:
      tag - Tag to modify
    • renderHead

      public void renderHead(IHeaderResponse response)
      Description copied from class: Component
      Render to the web response whatever the component wants to contribute to the head section.
      Specified by:
      renderHead in interface IHeaderContributor
      Overrides:
      renderHead in class Component
      Parameters:
      response - Response object
    • shouldTriggerJavaScriptSubmitEvent

      Controls whether or not clicking on this link will trigger a javascript submit event, firing any submit handler added to the form. True by default.
      Returns:
      true if form's javascript submit handlers should be invoked, false otherwise
    • getTriggerJavaScript

      The JavaScript which triggers this link. Method is non-final so that subclasses can decorate the provided script by wrapping their own JS around a call to super.getTriggerJavaScript().
      Returns:
      The JavaScript to be executed when the link is clicked.
    • onError

      public void onError()
      Description copied from interface: IFormSubmitter
      Method that is invoked when form processing fails; for example, when there are validation errors.
    • onAfterSubmit

      public void onAfterSubmit()
      Override this method to provide special submit handling in a multi-button form. This method will be called after the form's onSubmit method.
    • onSubmit

      public void onSubmit()
      Override this method to provide special submit handling in a multi-button form. This method will be called before the form's onSubmit method.