I have implemented a solution that is a bit of a hack, but I can't see how else to proceed.
 
I have altered the Counter bean to implement a new interface..

public interface ReadOnlyIterator
{
    public boolean hasNext();
    public Object next();
}

This has the advantage that it is not "wrapped" by OGNL and therefore properties such as 'first' and 'last' can be set without errors.  I have modified the Iterator tag to recognise this new Interface...

private Iterator getIterator() {
...
    } else if (o instanceof ReadOnlyIterator) {
       
return new ReadOnlyIteratorWrapper((ReadOnlyIterator) o);
    }
...
}

The class ReadOnlyIteratorWrapper delagates to the ReadOnlyIterator.

I have also fixed some bugs in the Counter class itself so that a call to getNext() followed by getCurrent() return the same value.

This all seems to work well.  Should I upload it into Jira?

John.

----- Original Message -----
To: Webwork
Sent: Friday, October 03, 2003 11:19 AM
Subject: [OS-webwork] OGNL wrapping iterators?

I have just tried to use the Counter bean class (which implements Iterator) from WW1 like so:

<ww:bean name="com.myorg.myapp.util.Counter">

<ww:param name="first" value="'1'"/>

<ww:param name="last" value="'9'"/>

<ww:iterator value="that">

<option  value="<ww:property value="current"/>"><ww:property value="current"/></option>

</ww:iterator>

</ww:bean>

I get this error:

"org.apache.jasper.JasperException: can't set property first on Iterator"

which I have traced to being thrown from OGNL during the set operation.  When I remove the Iterator interface from the Counter bean and recompile OGNL sets the property fine.  It appears that OGNL does not allow you to set properties on objects that implement Iterator.  Maybe OGNL wraps Iterators in order to give them extra functionality but in the process hides the original obejct.

John.

Reply via email to