/* $$ 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.valid;
import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.tapestry.IForm;
import org.apache.tapestry.IMarkupWriter;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.Tapestry;
import org.apache.tapestry.form.AbstractTextField;
import org.apache.tapestry.form.Form;
import org.apache.tapestry.form.IFormComponent;
import org.apache.tapestry.html.Body;
/**
*
* A {@link Form} component that creates a text field that
* allows for validation of user input and conversion between string and object
* values.
*
* [<a href="../../../../../ComponentReference/ValidField.html">Component Reference</a>]
*
* <p> A ValidatingTextField uses an {@link IValidationDelegate} to
* track errors and an {@link IValidator} to convert between strings and objects
* (as well as perform validations). The validation delegate is shared by all validating
* text fields in a form, the validator may be shared my multiple elements as desired.
*
* @author Howard Lewis Ship
*
**/
public abstract class ValidField extends AbstractTextField implements IFormComponent
{public static com.cortexeb.tools.clover.d __CLOVER_459_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);
public abstract Object getValue();
public abstract void setValue(Object value);
public abstract String getDisplayName();
/**
*
* Renders the component, which involves the {@link IValidationDelegate delegate}.
*
* <p>During a render, the <em>first</em> field rendered that is either
* in error, or required but null gets special treatment. JavaScript is added
* to select that field (such that the cursor jumps right to the field when the
* page loads).
*
**/
protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
{try { __CLOVER_459_0.M[2568]++;
__CLOVER_459_0.S[10332]++;IForm form = getForm(cycle);
__CLOVER_459_0.S[10333]++;IValidationDelegate delegate = form.getDelegate();
__CLOVER_459_0.S[10334]++;if ((((delegate == null) && (++__CLOVER_459_0.CT[1768] != 0)) || (++__CLOVER_459_0.CF[1768] == 0))){
__CLOVER_459_0.S[10335]++;throw new ApplicationRuntimeException(
Tapestry.format(
"ValidField.no-delegate",
getExtendedId(),
getForm().getExtendedId()),
this,
null,
null);}
__CLOVER_459_0.S[10336]++;IValidator validator = getValidator();
__CLOVER_459_0.S[10337]++;if ((((validator == null) && (++__CLOVER_459_0.CT[1769] != 0)) || (++__CLOVER_459_0.CF[1769] == 0))){
__CLOVER_459_0.S[10338]++;throw Tapestry.createRequiredParameterException(this, "validator");}
__CLOVER_459_0.S[10339]++;boolean rendering = !cycle.isRewinding();
__CLOVER_459_0.S[10340]++;if ((((rendering) && (++__CLOVER_459_0.CT[1770] != 0)) || (++__CLOVER_459_0.CF[1770] == 0))){
__CLOVER_459_0.S[10341]++;delegate.writePrefix(writer, cycle, this, validator);}
__CLOVER_459_0.S[10342]++;super.renderComponent(writer, cycle);
__CLOVER_459_0.S[10343]++;if ((((rendering) && (++__CLOVER_459_0.CT[1771] != 0)) || (++__CLOVER_459_0.CF[1771] == 0))){
__CLOVER_459_0.S[10344]++;delegate.writeSuffix(writer, cycle, this, validator);}
// If rendering and there's either an error in the field,
// then we may have identified the default field (which will
// automatically receive focus).
__CLOVER_459_0.S[10345]++;if ((((rendering && delegate.isInError()) && (++__CLOVER_459_0.CT[1772] != 0)) || (++__CLOVER_459_0.CF[1772] == 0))){
__CLOVER_459_0.S[10346]++;addSelect(cycle);}
// That's OK, but an ideal situation would know about non-validating
// text fields, and also be able to put the cursor in the
// first field, period (even if there are no required or error fields).
// Still, this pretty much rocks!
} finally { }}
/**
* Invokes {@link IValidationDelegate#writeAttributes(IMarkupWriter,IRequestCycle, IFormComponent,IValidator)}.
*
**/
protected void beforeCloseTag(IMarkupWriter writer, IRequestCycle cycle)
{try { __CLOVER_459_0.M[2569]++;
__CLOVER_459_0.S[10347]++;IValidator validator = getValidator();
__CLOVER_459_0.S[10348]++;validator.renderValidatorContribution(this, writer, cycle);
__CLOVER_459_0.S[10349]++;getForm().getDelegate().writeAttributes(writer, cycle, this, validator);
} finally { }}
private static final String SELECTED_ATTRIBUTE_NAME =
"org.apache.tapestry.component.html.valid.SelectedFieldSet";
/**
* Creates JavaScript to set the cursor on the first required or error
* field encountered while rendering. This only works if the text field
* is wrapped by a {@link Body} component (which is almost always true).
*
**/
protected void addSelect(IRequestCycle cycle)
{try { __CLOVER_459_0.M[2570]++;
// If some other field has taken the honors, then let it.
__CLOVER_459_0.S[10350]++;if ((((cycle.getAttribute(SELECTED_ATTRIBUTE_NAME) != null) && (++__CLOVER_459_0.CT[1773] != 0)) || (++__CLOVER_459_0.CF[1773] == 0))){
__CLOVER_459_0.S[10351]++;return;}
__CLOVER_459_0.S[10352]++;Body body = Body.get(cycle);
// If not wrapped by a Body, then do nothing.
__CLOVER_459_0.S[10353]++;if ((((body == null) && (++__CLOVER_459_0.CT[1774] != 0)) || (++__CLOVER_459_0.CF[1774] == 0))){
__CLOVER_459_0.S[10354]++;return;}
__CLOVER_459_0.S[10355]++;IForm form = Form.get(cycle);
__CLOVER_459_0.S[10356]++;String formName = form.getName();
__CLOVER_459_0.S[10357]++;String textFieldName = getName();
__CLOVER_459_0.S[10358]++;String fullName = "document." + formName + "." + textFieldName;
__CLOVER_459_0.S[10359]++;body.addInitializationScript(fullName + ".focus();");
__CLOVER_459_0.S[10360]++;body.addInitializationScript(fullName + ".select();");
// Put a marker in, indicating that the selected field is known.
__CLOVER_459_0.S[10361]++;cycle.setAttribute(SELECTED_ATTRIBUTE_NAME, Boolean.TRUE);
} finally { }}
protected String readValue()
{try { __CLOVER_459_0.M[2571]++;
__CLOVER_459_0.S[10362]++;IValidationDelegate delegate = getForm().getDelegate();
__CLOVER_459_0.S[10363]++;if ((((delegate.isInError()) && (++__CLOVER_459_0.CT[1775] != 0)) || (++__CLOVER_459_0.CF[1775] == 0))){
__CLOVER_459_0.S[10364]++;return delegate.getFieldInputValue();}
__CLOVER_459_0.S[10365]++;Object value = getValue();
__CLOVER_459_0.S[10366]++;String result = getValidator().toString(this, value);
__CLOVER_459_0.S[10367]++;if ((((Tapestry.isBlank(result) && getValidator().isRequired()) && (++__CLOVER_459_0.CT[1776] != 0)) || (++__CLOVER_459_0.CF[1776] == 0))){
__CLOVER_459_0.S[10368]++;addSelect(getPage().getRequestCycle());}
__CLOVER_459_0.S[10369]++;return result;
} finally { }}
protected void updateValue(String value)
{try { __CLOVER_459_0.M[2572]++;
__CLOVER_459_0.S[10370]++;Object objectValue = null;
__CLOVER_459_0.S[10371]++;IValidationDelegate delegate = getForm().getDelegate();
__CLOVER_459_0.S[10372]++;delegate.recordFieldInputValue(value);
__CLOVER_459_0.S[10373]++;try
{
__CLOVER_459_0.S[10374]++;objectValue = getValidator().toObject(this, value);
}
catch (ValidatorException ex)
{
__CLOVER_459_0.S[10375]++;delegate.record(ex);
__CLOVER_459_0.S[10376]++;return;
}
__CLOVER_459_0.S[10377]++;setValue(objectValue);
} finally { }}
public abstract IValidator getValidator();
}