You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by "Leucht, Axel" <Ax...@prodv.de> on 2008/11/19 12:28:08 UTC
Model never called
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: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Model never called
Posted by Michael Sparer <mi...@gmx.at>.
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: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
>
-----
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: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org