Nevertheless, I like the idea to get a more native Scala integration.
For example, I would really love to check out whether it would be hard
to natively support Scala's property semantics besides convetional
getters and setters.

Andreas Joseph Krogh schrieb:
> On Sunday 24 May 2009 09:36:48 pm Andreas Joseph Krogh wrote:
>> Hi all.
>> Normally this kind of post would be better posted to -users, but I'm looking 
>> for the developers comments on this.
>>
>> Anyone have any experience using Scala with Struts2? I'm especially thinking 
>> about s:iterate and scala.List.
>>
>> I've managed to use s:iterate with Scala's List like this:
>> <s:iterator value="%{getMyList().toArray().unbox(@java.lang.obj...@class)}" 
>> status="status">
>> getMyList() returns a scala.List from my Scala-object, which I convert to an 
>> JAVA-array using toArray().unbox().
>>
>> This seems very hackish and it would be cool if one could make a 
>> "struts2-scala-plugin" which registered some kind of Iterator which the 
>> IteratorComponent could use, refactoring out the call to 
>> "MakeIterator.convert(findValue(value))" to a factory of some kind which 
>> checked some kind of registry for providing a proper Iterator for the 
>> Scala-object returned by findValue(value).
>>
>> Comments?
> 
> For the curious;
> After some Googleing I "solved" this issue by defining a 
> getListAsJavaIterator() method in my Scala-object which uses "implicit 
> conversion" compiler-magic to define a new "iterator()" method on the 
> Scala-Iterable Trait:
> 
> object JavaIterableConversions {
> 
>       class JavaIterator[T](itr: Iterator[T]) extends java.util.Iterator[T] {
>               def hasNext() = itr.hasNext
>               def next() = itr.next
>               def remove() = throw new
>                               java.lang.UnsupportedOperationException("Remove 
> is not implemented in JavaIterableConversions:JavaIterator")
>       }
> 
>       class JavaIterable[T](iterable: Iterable[T]) extends 
> java.lang.Iterable[T] {
>               def iterator() = new JavaIterator[T](iterable.elements)
>       }
> 
>       implicit def implicitScalaIterableToJavaIterable[T](iterable : 
> Iterable[T]): java.lang.Iterable[T] =
>               new JavaIterable[T](iterable)
> 
> }
> 
> Usage:
> 
> import JavaIterableConversions._
> class MyScalaClass {
>       @BeanProperty
>       var items: List[Item] = _
> 
>       def getListAsJavaIterator(): java.util.Iterator[_] = {
>               items.iterator();
>       }
> }
> 
> Note: the iterator() *must* be defined in the same class as the 
> implicit-conversion implicitScalaIterableToJavaIterable is defined/imported 
> as it's the scala-compiler which does it's magic here. Trying to call 
> items.iterator() from a JAVA-class will *not* work.
> 

-- 
René Gielen
IT-Neering.net
Saarstrasse 100, 52062 Aachen, Germany
Tel: +49-(0)241-4010770
Fax: +49-(0)241-4010771
Cel: +49-(0)177-3194448
http://twitter.com/rgielen

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to