Hi,

Thank you. I implements the iterator interface, and now it is working.

public class SearchResults implements Iterator<SearchResult> {

        private Set<String> keySet = null;
        private Iterator<String> iterator = null;

        private Set<String> keySet() {

                if (this.keySet == null) {
                        this.keySet = this.results.keySet();
                }
                return this.keySet;
        }

        private Iterator<String> iterator() {
                
                if (this.iterator == null){
                        this.iterator = this.keySet().iterator();
                }
                return this.iterator;
        }

        public SearchResult get(String key) {
                return this.results.get(key);
        }

        @Override
        public boolean hasNext() {
                return this.iterator().hasNext();
        }

        @Override
        public SearchResult next() {
                String next = this.iterator().next();
                return this.get(next);
        }
}


Calls (hasNext() and next()) are done in org.apache.struts2.components. 
IteratorComponent


Thanks

Matthieu MARC


-----Message d'origine-----
De : Steven Yang [mailto:kenshin...@gmail.com] 
Envoyé : mardi 10 mai 2011 15:16
À : Struts Users Mailing List
Objet : Re: Tag iterator and my object container

you need to implement the Iterator interface

On Tue, May 10, 2011 at 4:14 PM, <matthieu.m...@ensam.eu> wrote:

> Hi everybody,
>
> I have a container object SearchResults which contains a treeMap of 
> simple object SearchResult.
>
> I want to iterate over SearchResults in order to display properties of 
> all SearchResult object
>
>        Class SearchResult {
>                //getter and setter
>                getDescription();
>        }
>
>        Class SearchResults {
>              treeMap<String, SearchResult>  resultats;
>
>                public Set<String> keyset();
>                public Iterator<String> iterator();
>                public SearchResult get(String key);
>        }
>
> My Action class have this getter :
>
>        getResultats(){ return (SearchResults)object; };
>
> And my JSP look like :
>
>        <s:iterator value="resultats">
>                <s:property value="description" />
>        </s:iterator>
>
>
> But it is not working, s:iterator tag is not iterating over my 
> SearchResults object using the iterator() method (not called).
>
> How must I construct my SearchResults object in order to make the 
> s:iterator tag iterate over it ?
>
> Thanks.
>
> Matthieu MARC
>
> ---
> Matthieu MARC
> Responsable du Service Informatique du Centre d'Angers Arts et Métiers 
> ParisTech Tél : 02 41 20 73 61
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
> For additional commands, e-mail: user-h...@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to