ListView needs a model that has List<V>, so do this:
ListView<String> poems = new ListView<String>("poems", new
AbstractReadOnlyModel<List<String>>() {
public List<String> getObject() {
// here you put the code that takes the string and tokenizes it
}
}) {
@Override
protected void populateItem(ListItem<String> listItem) {
// here - don't use the model object - use the model (best practice):
listItem.add(new Label("poemLine", listItem.getModel());
}
};
--
Jeremy Thomerson
http://www.wickettraining.com
On Wed, Nov 18, 2009 at 11:24 AM, smallufo <[email protected]> wrote:
> 2009/11/19 Jeremy Thomerson <[email protected]>
>
> > http://cwiki.apache.org/WICKET/using-custom-converters.html
> >
> >
> Thanks a lot , this solves my problem...
> But , there is a more complicated situation :
>
> Old code : (works in 1.3)
>
> ListView poem = new ListView("poem" , new PropertyModel(model , "poem")
> {
> @Override
> public Object getObject()
> {
> List<String> result = new ArrayList<String>();
> String poemString = (String) super.getObject();
> StringTokenizer st = new StringTokenizer(poemString);
> while(st.hasMoreTokens())
> result.add(st.nextToken());
> return result;
> }
> })
> {
> @Override
> protected void populateItem(ListItem listItem)
> {
> listItem.add(new Label("poemLine" ,
> listItem.getDefaultModelObjectAsString()));
> }
> };
> add(poem);
>
> In the above code , it get "poem" ( a String ) from a PropertyModel , and
> convert it to List<String> ,
> and then render each String in the populateItem() method.
>
> I look into IConverter and AbstractConverter , both need to convert Object
> to String , not what I need ( List<String> )
> How should I solve this problem ?
>