Vinicius Carvalho wrote:
Hello there! I know from Tapestry in Action that we can access the
first error from a ValidationDelegate class. Is it possible to access
all of em'? like:
<span jwicd="@Foreach" source="ognl:delegate.errors" value="ognl:error"> ...
</span>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Hi,
I attached a class called "MyDelegate" which extends from
ValidationDelegate (If the attachment doesn't come through let me
know). This is the class I use for my validation delegate. There is a
method inside the class called getErrors() which returns all the errors.
This is a snippet from my border component that displays all the errors:
<span jwcid="@Conditional"
condition="ognl:page.delegate.hasErrors">
<div class="AlertBad">
<b>Please correct the following errors before
continuing:</b>
<ul>
<span jwcid="@Foreach"
source="ognl:page.delegate.errors" value="ognl:page.delegate.currentError">
<li><span jwcid="@Delegator"
delegate="ognl:page.delegate.currentError.errorRenderer"/></li>
</span>
</ul>
</div>
</span>
cheers, scott.
--
Scott F. Walter Scott F. Walter
Principal Consultant
Vivare, Inc.
E: [EMAIL PROTECTED]
E: [EMAIL PROTECTED]
Visit scottwalter.com <http://scottwalter.com> --Point. Click. Explore!
/*
* YourSite License Notice
*
* The contents of this file are subject to the Scottwalter.com License
* Version 1.0 (the "License"). You may not use this file except in
* compliance with the License. A copy of the License is available at
* http://yoursite.scottwalter.com/license.html
*
* Copyright 2003-2005 Scott F. Walter. All Rights Reserved.
*
*/
package com.scottwalter.yoursite.controlcenter.tapestry;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.tapestry.IMarkupWriter;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.form.IFormComponent;
import org.apache.tapestry.valid.IFieldTracking;
import org.apache.tapestry.valid.IValidator;
import org.apache.tapestry.valid.ValidationDelegate;
public class MyDelegate extends ValidationDelegate{
private IFieldTracking _currentError;
public void writeAttributes(IMarkupWriter writer, IRequestCycle cycle,
IFormComponent component, IValidator validator) {
if(isInError()) {
writer.attribute("class", "fielderror");
}
}
public void writeLabelPrefix(IFormComponent component,
IMarkupWriter writer, IRequestCycle cycle) {
if(isInError(component)) {
writer.begin("span");
writer.attribute("class","labelerror");
}
}
public void writeLabelSuffix(IFormComponent component,
IMarkupWriter writer, IRequestCycle cycle) {
if(isInError(component)) {
writer.end();
}
}
public void writeSuffix(IMarkupWriter writer, IRequestCycle cycle,
IFormComponent component, IValidator validator) {
if(validator!=null && validator.isRequired()) {
writer.printRaw(" ");
writer.begin("span");
writer.attribute("class", "required-marker");
writer.beginEmpty("img");
writer.attribute("src","images/required.jpg");
writer.attribute("alt","required field");
writer.attribute("align","middle");
writer.end();
}
if(isInError()) {
writer.printRaw(" ");
writer.beginEmpty("img");
writer.attribute("align","middle");
writer.attribute("src","images/warning_icon.gif");
}
}
public List getErrors() {
List trackings = getFieldTracking();
List<IFieldTracking> errors = new ArrayList<IFieldTracking>();
for(Iterator<IFieldTracking> iterator =
trackings.iterator();iterator.hasNext();) {
IFieldTracking fieldTracking = iterator.next();
if(fieldTracking.isInError()) {
errors.add(fieldTracking);
}
}
return errors;
}
public void setCurrentError(IFieldTracking tracking) {
_currentError = tracking;
}
public IFieldTracking getCurrentError() {
return _currentError;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]