/* $$ Clover has instrumented this file $$ */// Copyright 2004 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.apache.tapestry.form;
import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.tapestry.IActionListener;
import org.apache.tapestry.IBinding;
import org.apache.tapestry.IForm;
import org.apache.tapestry.IMarkupWriter;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.Tapestry;
import org.apache.tapestry.html.Body;
/**
* Implements a component that submits its enclosing form via a JavaScript link.
*
* [<a href="../../../../../ComponentReference/LinkSubmit.html">Component Reference</a>]
*
* @author Richard Lewis-Shell
*
**/
public abstract class LinkSubmit extends AbstractFormComponent
{public static com.cortexeb.tools.clover.d __CLOVER_137_0 = com.cortexeb.tools.clover.aq.getRecorder(new char[] {67,58,92,119,111,114,107,115,112,97,99,101,92,106,97,107,97,114,116,97,45,116,97,112,101,115,116,114,121,92,102,114,97,109,101,119,111,114,107,92,116,97,114,103,101,116,92,99,108,111,118,101,114,45,100,98},1096998272901L);
/**
* The name of an {@link org.apache.tapestry.IRequestCycle} attribute in which the
* current submit link is stored. LinkSubmits do not nest.
*
**/
public static final String ATTRIBUTE_NAME = "org.apache.tapestry.form.LinkSubmit";
/**
* The name of an {@link org.apache.tapestry.IRequestCycle} attribute in which the
* link submit component that generates the javascript function is stored. The
* function is only required once per page (containing a form with a non-disabled
* LinkSubmit)
*
**/
public static final String ATTRIBUTE_FUNCTION_NAME =
"org.apache.tapestry.form.LinkSubmit_function";
protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
{try { __CLOVER_137_0.M[728]++;
__CLOVER_137_0.S[3311]++;IForm form = getForm(cycle);
__CLOVER_137_0.S[3312]++;String formName = form.getName();
__CLOVER_137_0.S[3313]++;boolean rewinding = form.isRewinding();
__CLOVER_137_0.S[3314]++;String name = form.getElementId(this);
__CLOVER_137_0.S[3315]++;IMarkupWriter wrappedWriter;
__CLOVER_137_0.S[3316]++;if ((((cycle.getAttribute(ATTRIBUTE_NAME) != null) && (++__CLOVER_137_0.CT[609] != 0)) || (++__CLOVER_137_0.CF[609] == 0))){
__CLOVER_137_0.S[3317]++;throw new ApplicationRuntimeException(
Tapestry.getMessage("LinkSubmit.may-not-nest"),
this,
null,
null);}
__CLOVER_137_0.S[3318]++;cycle.setAttribute(ATTRIBUTE_NAME, this);
__CLOVER_137_0.S[3319]++;boolean disabled = isDisabled();
__CLOVER_137_0.S[3320]++;if ((((!disabled) && (++__CLOVER_137_0.CT[610] != 0)) || (++__CLOVER_137_0.CF[610] == 0))){
{
__CLOVER_137_0.S[3321]++;if ((((!rewinding) && (++__CLOVER_137_0.CT[611] != 0)) || (++__CLOVER_137_0.CF[611] == 0))){
{
__CLOVER_137_0.S[3322]++;Body body = Body.get(cycle);
__CLOVER_137_0.S[3323]++;if ((((body == null) && (++__CLOVER_137_0.CT[612] != 0)) || (++__CLOVER_137_0.CF[612] == 0))){
__CLOVER_137_0.S[3324]++;throw new ApplicationRuntimeException(
Tapestry.format("must-be-contained-by-body", "LinkSubmit"),
this,
null,
null);}
// make sure the submit function is on the page (once)
__CLOVER_137_0.S[3325]++;if ((((cycle.getAttribute(ATTRIBUTE_FUNCTION_NAME) == null) && (++__CLOVER_137_0.CT[613] != 0)) || (++__CLOVER_137_0.CF[613] == 0))){
{
__CLOVER_137_0.S[3326]++;body.addBodyScript(
"function submitLink(form, elementId) { form._linkSubmit.value = elementId; if (form.onsubmit == null || form.onsubmit()) form.submit(); }");
__CLOVER_137_0.S[3327]++;cycle.setAttribute(ATTRIBUTE_FUNCTION_NAME, this);
}}
// one hidden field per form:
__CLOVER_137_0.S[3328]++;String formHiddenFieldAttributeName = ATTRIBUTE_FUNCTION_NAME + formName;
__CLOVER_137_0.S[3329]++;if ((((cycle.getAttribute(formHiddenFieldAttributeName) == null) && (++__CLOVER_137_0.CT[614] != 0)) || (++__CLOVER_137_0.CF[614] == 0))){
{
__CLOVER_137_0.S[3330]++;writer.beginEmpty("input");
__CLOVER_137_0.S[3331]++;writer.attribute("type", "hidden");
__CLOVER_137_0.S[3332]++;writer.attribute("name", "_linkSubmit");
__CLOVER_137_0.S[3333]++;cycle.setAttribute(formHiddenFieldAttributeName, this);
}}
}}
else{
{
// How to know which Submit link was actually
// clicked? When submitted, it sets its elementId into a hidden field
__CLOVER_137_0.S[3334]++;String value = cycle.getRequestContext().getParameter("_linkSubmit");
// If the value isn't the elementId of this component, then this link wasn't
// selected.
__CLOVER_137_0.S[3335]++;if ((((value != null && value.equals(name)) && (++__CLOVER_137_0.CT[615] != 0)) || (++__CLOVER_137_0.CF[615] == 0))){
{
__CLOVER_137_0.S[3336]++;IBinding selectedBinding = getSelectedBinding();
__CLOVER_137_0.S[3337]++;if ((((selectedBinding != null) && (++__CLOVER_137_0.CT[616] != 0)) || (++__CLOVER_137_0.CF[616] == 0))){
__CLOVER_137_0.S[3338]++;selectedBinding.setObject(getTag());}
__CLOVER_137_0.S[3339]++;IActionListener listener = getListener();
__CLOVER_137_0.S[3340]++;if ((((listener != null) && (++__CLOVER_137_0.CT[617] != 0)) || (++__CLOVER_137_0.CF[617] == 0))){
__CLOVER_137_0.S[3341]++;listener.actionTriggered(this, cycle);}
}}
}}
__CLOVER_137_0.S[3342]++;writer.begin("a");
__CLOVER_137_0.S[3343]++;writer.attribute(
"href",
"javascript:submitLink(document." + formName + ",\"" + name + "\");");
// Allow the wrapped components a chance to render.
// Along the way, they may interact with this component
// and cause the name variable to get set.
__CLOVER_137_0.S[3344]++;wrappedWriter = writer.getNestedWriter();
}}
else{
__CLOVER_137_0.S[3345]++;wrappedWriter = writer;}
__CLOVER_137_0.S[3346]++;renderBody(wrappedWriter, cycle);
__CLOVER_137_0.S[3347]++;if ((((!disabled) && (++__CLOVER_137_0.CT[618] != 0)) || (++__CLOVER_137_0.CF[618] == 0))){
{
// Generate additional attributes from informal parameters.
__CLOVER_137_0.S[3348]++;renderInformalParameters(writer, cycle);
// Dump in HTML provided by wrapped components
__CLOVER_137_0.S[3349]++;wrappedWriter.close();
// Close the <a> tag
__CLOVER_137_0.S[3350]++;writer.end();
}}
__CLOVER_137_0.S[3351]++;cycle.removeAttribute(ATTRIBUTE_NAME);
} finally { }}
public abstract boolean isDisabled();
public abstract void setDisabled(boolean disabled);
public abstract IActionListener getListener();
public abstract void setListener(IActionListener listener);
public abstract Object getTag();
public abstract void setTag(Object tag);
public abstract void setSelectedBinding(IBinding value);
public abstract IBinding getSelectedBinding();
}