org.apache.click.extras.control
Class SubmitLink

java.lang.Object
  extended by org.apache.click.control.AbstractControl
      extended by org.apache.click.control.AbstractLink
          extended by org.apache.click.control.ActionLink
              extended by org.apache.click.extras.control.SubmitLink
All Implemented Interfaces:
Serializable, Control, Stateful

public class SubmitLink
extends ActionLink

Provides a Submit Link control,   <a href=""></a>, that can submit a Form.

SubmitLink can be added to a Form and it will submit the Form when clicked. All SubmitLink parameters will be submitted to the server as hidden fields.

Please note: SubmitLink uses a JavaScript function to submit the Form. This JavaScript function also creates hidden fields for each SubmitLink parameter, to ensure the link's parameters are submitted. See getSubmitScript(java.lang.String) for more details on the JavaScript used to submit the Form.

Also note: if SubmitLink is not added to a Form, it behaves like an ActionLink control.

Here is an example:

 public class MyPage extends Page {

     public void onInit() {

         // Create a Form control
         Form form = new Form("form");
         addControl(form);

         // Add a SubmitLink to the Form
         SubmitLink link = new SubmitLink("link");
         form.add(link);
     }
 } 

Custom Popup Message

The SubmitLink uses the "onclick" event handler to submit the Form.

If you would like to customize the "onclick" event handler, for example to show a confirmation popup message, you can retrieve the link's submit script through the getSubmitScript(java.lang.String) method.

Here is an example of providing a confirmation popup message before submitting the Form:

 public MyPage extends Page {

     public void onInit() {
         Form form = new Form("form");
         SubmitLink link = new SubmitLink("link", "Delete");
         form.add(link);

         // Get the submit script for the given form id
         String submitScript = submitLink.getSubmitScript(form.getId());

         // Add a confirmation popup message
         scriptLink.setOnClick("var confirm = window.confirm('Are you sure?'); if (confirm) "
             + submitScript + " else return false;");
     }
 } 

CSS and JavaScript resources

When SubmitLink is added to a Form it makes use of the following resources (which Click automatically deploys to the application directory, /click):

See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.apache.click.control.ActionLink
ACTION_LINK, clicked, VALUE
 
Fields inherited from class org.apache.click.control.AbstractLink
disabled, imageSrc, label, parameters, renderLabelAndImage, tabindex, title
 
Fields inherited from class org.apache.click.control.AbstractControl
actionListener, attributes, behaviors, headElements, listener, listenerMethod, messages, name, parent, styles
 
Fields inherited from interface org.apache.click.Control
CONTROL_MESSAGES
 
Constructor Summary
SubmitLink()
          Create an SubmitLink with no name defined.
SubmitLink(Object listener, String method)
          Create an SubmitLink for the given listener object and listener method.
SubmitLink(String name)
          Create an SubmitLink for the given name.
SubmitLink(String name, Object listener, String method)
          Create an SubmitLink for the given name, listener object and listener method.
SubmitLink(String name, String label)
          Create an SubmitLink for the given name and label.
SubmitLink(String name, String label, Object listener, String method)
          Create an SubmitLink for the given name, label, listener object and listener method.
 
Method Summary
 void bindRequestValue()
          This method binds the submitted request value to the SubmitLink's value.
 Form getForm()
          Return the parent Form or null if no Form is available.
 List<Element> getHeadElements()
          Return the list of HEAD elements to be included in the page.
 String getHref(Object value)
          Return the SubmitLink anchor <a> tag href attribute for the given value.
 String getOnClick()
          Returns the button onclick attribute value, or null if not defined.
 String getParameterPrefix()
          Return the parameter prefix that is applied to the SubmitLink parameters.
 String getSubmitScript(String formId)
          Return the JavaScript that submits the Form with the given formId.
 boolean hasParentForm()
          Return true if SubmitLink has a parent Form control, false otherwise.
 void render(HtmlStringBuffer buffer)
          Render the HTML representation of the SubmitLink.
 void setForm(Form form)
          Set the SubmitLink Form.
 void setOnClick(String value)
          Sets the button onclick attribute value.
 void setParameterPrefix(String prefix)
          Set the parameter prefix that is applied to the SubmitLink parameters.
 
Methods inherited from class org.apache.click.control.ActionLink
getHref, getValue, getValueDouble, getValueInteger, getValueLong, isClicked, onProcess, setName, setParent, setValue, setValueObject
 
Methods inherited from class org.apache.click.control.AbstractLink
bindRequestParameters, defineParameter, getId, getImageSrc, getLabel, getParameter, getParameters, getParameterValues, getState, getTabIndex, getTag, getTitle, hasParameters, isAjaxTarget, isDisabled, isRenderLabelAndImage, removeState, renderImgTag, renderParameters, restoreState, saveState, setDisabled, setImageSrc, setLabel, setParameter, setParameters, setParameterValues, setRenderLabelAndImage, setState, setTabIndex, setTitle
 
Methods inherited from class org.apache.click.control.AbstractControl
addBehavior, addStyleClass, appendAttributes, dispatchActionEvent, getActionListener, getAttribute, getAttributes, getBehaviors, getContext, getControlSizeEst, getHtmlImports, getMessage, getMessage, getMessages, getName, getPage, getParent, getStyle, getStyles, hasAttribute, hasAttributes, hasBehaviors, hasStyles, onDeploy, onDestroy, onInit, onRender, removeBehavior, removeStyleClass, renderTagBegin, renderTagEnd, setActionListener, setAttribute, setId, setListener, setStyle, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SubmitLink

public SubmitLink(String name)
Create an SubmitLink for the given name.

Please note the name 'actionLink' is reserved as a control request parameter name and cannot be used as the name of the control.

Parameters:
name - the action link name
Throws:
IllegalArgumentException - if the name is null

SubmitLink

public SubmitLink(String name,
                  String label)
Create an SubmitLink for the given name and label.

Please note the name 'actionLink' is reserved as a control request parameter name and cannot be used as the name of the control.

Parameters:
name - the action link name
label - the action link label
Throws:
IllegalArgumentException - if the name is null

SubmitLink

public SubmitLink(Object listener,
                  String method)
Create an SubmitLink for the given listener object and listener method.

Parameters:
listener - the listener target object
method - the listener method to call
Throws:
IllegalArgumentException - if the name, listener or method is null or if the method is blank

SubmitLink

public SubmitLink(String name,
                  Object listener,
                  String method)
Create an SubmitLink for the given name, listener object and listener method.

Please note the name 'actionLink' is reserved as a control request parameter name and cannot be used as the name of the control.

Parameters:
name - the action link name
listener - the listener target object
method - the listener method to call
Throws:
IllegalArgumentException - if the name, listener or method is null or if the method is blank

SubmitLink

public SubmitLink(String name,
                  String label,
                  Object listener,
                  String method)
Create an SubmitLink for the given name, label, listener object and listener method.

Please note the name 'actionLink' is reserved as a control request parameter name and cannot be used as the name of the control.

Parameters:
name - the action link name
label - the action link label
listener - the listener target object
method - the listener method to call
Throws:
IllegalArgumentException - if the name, listener or method is null or if the method is blank

SubmitLink

public SubmitLink()
Create an SubmitLink with no name defined. Please note the control's name must be defined before it is valid.

Method Detail

getForm

public Form getForm()
Return the parent Form or null if no Form is available.

Returns:
the parent Form or null if no Form is available

setForm

public void setForm(Form form)
Set the SubmitLink Form.

Parameters:
form - the SubmitLink Form

getOnClick

public String getOnClick()
Returns the button onclick attribute value, or null if not defined.

Returns:
the button onclick attribute value, or null if not defined.

setOnClick

public void setOnClick(String value)
Sets the button onclick attribute value.

Parameters:
value - the onclick attribute value.

setParameterPrefix

public void setParameterPrefix(String prefix)
Set the parameter prefix that is applied to the SubmitLink parameters.

Parameters:
prefix - the parameter prefix

getParameterPrefix

public String getParameterPrefix()
Return the parameter prefix that is applied to the SubmitLink parameters.

Returns:
the parameter prefix that is applied to the SubmitLink parameters.

hasParentForm

public boolean hasParentForm()
Return true if SubmitLink has a parent Form control, false otherwise.

Returns:
true if SubmitLink has a parent Form control, false otherwise.

getSubmitScript

public String getSubmitScript(String formId)
Return the JavaScript that submits the Form with the given formId.

The script returned by this method is:

 "return Click.submitLinkAction(this, 'formId');" 
The Click.submitLinkAction function takes as parameters a reference to the SubmitLink and the id of the Form to submit. (The Click.submitLinkAction is defined in /click/extras-control.js)

Parameters:
formId - the id of the Form to submit
Returns:
the JavaScript that submits the Form with the given formId
Throws:
IllegalStateException - if the form id is null

getHref

public String getHref(Object value)
Return the SubmitLink anchor <a> tag href attribute for the given value. This method will encode the URL with the session ID if required using HttpServletResponse.encodeURL().

Overrides:
getHref in class ActionLink
Parameters:
value - the SubmitLink value parameter
Returns:
the SubmitLink HTML href attribute

bindRequestValue

public void bindRequestValue()
This method binds the submitted request value to the SubmitLink's value.

Overrides:
bindRequestValue in class ActionLink

getHeadElements

public List<Element> getHeadElements()
Return the list of HEAD elements to be included in the page. The list of resources are:

Specified by:
getHeadElements in interface Control
Overrides:
getHeadElements in class AbstractControl
Returns:
the list of HEAD elements to be included in the page

render

public void render(HtmlStringBuffer buffer)
Render the HTML representation of the SubmitLink.

Specified by:
render in interface Control
Overrides:
render in class AbstractLink
Parameters:
buffer - the specified buffer to render the control's output to