A model is only in a link as a convenience for YOU to use. It's not used by default - what about a link needs a model? Rather, it's for something like:
new Link("deleteUser", modelContainingUser) { onClick() { userDAO.delete(getModelObject()); } } It's for YOU to use. For instance, let's make a simpler example supposing that you were changing the state of a label (rather than an image) with your link. You could do something like this: Model<String> model = new Model<String>("default value"); Link link = new Link("link", model) { public void onClick() { System.out.println("clicked"); setModelObject("I've been clicked"); } } link.add(new Label("label", model)); item.add(link); The Label calls getObject() on its model because it needs data to print. Since you share the model between the two, changing it in the link will change it in the label. Now, back to your image example - images use image resources, not models, and I don't think this will work like you have it drawn. You need to experiment with image resources for that. Hopefully this gives you a better understanding of models, though. -- Jeremy Thomerson http://www.wickettraining.com On Wed, Nov 19, 2008 at 6:57 AM, Leucht, Axel <[EMAIL PROTECTED]> wrote: > Nope, doesn't work either. > > I've created a new class MySquare implementing IModel but the getObject() > never get called either. > > I'm stumped. > > In populateItem I do: > for (int col=0; col<10; col++) { > MySquare mySquare = new MySquare(); > Link link = new Link("cols"+col, mySquare) { > public void onClick() { > System.out.println("clicked"); > } > }; > link.add(new Image("icon"+col,Square.emptyResource)); > item.add(link); > > /Axel > > > >>-----Ursprüngliche Nachricht----- > >>Von: Michael Sparer [mailto:[EMAIL PROTECTED] > >>Gesendet: Mittwoch, 19. November 2008 12:37 > >>An: users@wicket.apache.org > >>Betreff: Re: Model never called > >> > >> > >> > >>you should rather add an IModel to the link e.g. new > >>Link("foobar", myModel); > >>than letting a component implement IModel. the way you did > >>it, the model is > >>never recognised as a model, as it wasn't set as a model of a > >>component. > >>hope that makes sense > >> > >>regards, > >>Michael > >> > >> > >>Leucht, Axel wrote: > >>> > >>> Hi, > >>> > >>> I do have a link class which should render different icons > >>when clicked. > >>> > >>> So I decided to implement IModel and return different icons > >>depending on > >>> the state of the object. But to my surprise getObject() > >>never get called! > >>> > >>> Does anyone give me a clue where to look next or give me a > >>hint as to how > >>> to render the object with a different icon? > >>> > >>> The object is used in a 10x10 board game where a player can > >>"shoot" at > >>> different squares which are rendered as links in the > >>output. The board is > >>> constructed as: > >>> ListView listview = new ListView("rows", list) { > >>> private static final long serialVersionUID = 1L; > >>> > >>> protected void populateItem(ListItem item) { > >>> Row row = (Row) item.getModelObject(); > >>> final Square[] squares = new Square[10]; > >>> for (int col=0; col<10; col++) { > >>> squares[col] = > >>row.getCells(col); > >>> } > >>> Square square = row.getCells(0); > >>> item.add(new Label("row",new > >>Model(square.getRow()))); > >>> for (int col=0; col<10; col++) { > >>> final Square aSquare = > >>row.getCells(col); > >>> item.add(aSquare); > >>> } > >>> } > >>> }; > >>> And the Square-Object is: > >>> public class Square extends Link implements IModel { > >>> @Override > >>> public void onClick() { > >>> System.out.println("Click:" + ident); > >>> } > >>> > >>> @Override > >>> public Object getObject() { > >>> System.out.println("GetObject"); > >>> if (someState) > >>> return icon1; > >>> return icon2; > >>> > >>> } > >>> } > >>> > >>> /Axel > >>> > >>> > >>--------------------------------------------------------------------- > >>> To unsubscribe, e-mail: [EMAIL PROTECTED] > >>> For additional commands, e-mail: [EMAIL PROTECTED] > >>> > >>> > >>> > >> > >> > >>----- > >>Michael Sparer > >>http://talk-on-tech.blogspot.com > >>-- > >>View this message in context: > http://www.nabble.com/Model-never-called-tp20577931p20578051.html > Sent from the Wicket - User mailing list archive at Nabble.com. > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > >