On 7/9/07, Tauren Mills <[EMAIL PROTECTED]> wrote:
Thanks Igor, putting it getObject makes total sense! However, now I'm
confused on how to access the property I want within getObject:
public Object getObject(final Component component) {
int size = choices.size();
int index = choices.indexOf(component.getModelObject());
int width = (index + 1)*100/size;
return "width: "+width+"%";
}
That doesn't work. I'm trying to access a parent CompoundPropertyModel
that contains a RatingsModel and want the "facility" property within
it. But I can't hardcode "facility" as this same method should be
used for many other properties.
Not sure what this is doing, but it isn't right:
int index = choices.indexOf(component.getModelObject());
This creates an infinite loop:
int index = choices.indexOf(this.getObject(component));
So what is the correct way to access that property?
StarDisplay.this.getModelObject()
-igor
Thanks again,
Tauren
On 7/9/07, Igor Vaynberg <[EMAIL PROTECTED]> wrote:
>
> On 7/9/07, Tauren Mills <[EMAIL PROTECTED]> wrote:
> > Component.initModel() calls getParent() and it returns null. I guess
> > that makes sense because the child hasn't been added to the parent
> > yet. That happens after the child constructor has finished.
>
> that makes sense
>
> > So how would I do this?
>
> you have to delay the code that needs index until rendertime. move the
code
> that calculates the index into the same code that uses it - inside
> model.getobject() used inside that attribute modifier.
>
> -igor
>
>
>
> > Tauren
> >
> >
> >
> > On 7/9/07, Igor Vaynberg <[EMAIL PROTECTED]> wrote:
> > > On 7/9/07, Tauren Mills <[EMAIL PROTECTED]> wrote:
> > >
> > > > I'm confused on how to access a CompoundPropertyModel from within
a
> > > > child Panel. I set a CompountPropertyModel in a parent panel. But
> > > > doing a getModel() in the child panel returns null. I thought
that
> > > > wicket would hunt back up the component tree to find an
appropriate
> > > > CompountPropertyModel. How should I do this?
> > > >
> > > > Here is the parent, where I set the CPM:
> > > >
> > > > public class RatingDisplayPanel extends Panel {
> > > > public RatingDisplayPanel(String id, RatingsModel ratings)
{
> > > > super(id);
> > > > setModel(new
> > > CompoundPropertyModel(ratings));
> > > > add(new StarDisplay("facility", RatingBean.STARS
));
> > > > }
> > > > }
> > > >
> > > > Here is the child, where I do a getModel() and it returns null:
> > > >
> > > > public class StarDisplay extends Panel {
> > > >
> > > > private int width = 0;
> > > >
> > > > public StarDisplay(String id, List choices) {
> > > > super(id);
> > > > int size = 0;
> > > > if (choices != null) {
> > > > size = choices.size();
> > > > if (getModel() != null) {
> > > > index =
> > > choices.indexOf(getModel().getObject(this));
> > > > }
> > > > this.width = (index + 1)*100/size;
> > > > WebMarkupContainer on = new
> > > WebMarkupContainer("on");
> > > > on.add(new AttributeModifier("style",
true,
> new
> > > Model() {
> > > > public Object
> > > getObject(final Component component) {
> > > > return
> "width:
> > > "+width+"%";
> > > > }
> > > > }));
> > > > add(on);
> > > > }
> > > > }
> > > > }
> > > >
> > > > I have it working right now by passing the model like this, but I
want
> > > > to simplify the code in my parent panel:
> > > >
> > > > add(new StarDisplay("facility", new PropertyModel(ratings,
> > > > "facility"), RatingBean.STARS));
> > > >
> > > > I thought perhaps I should use getNestedModel(), but it doesn't
exist
> > > > in a panel. Any help is appreciated!
> > >
> > >
> > > seems like it should work, can you walk the code and see why
getmodel()
> > > returns null?
> > >
> > > -igor
> > >
> > >
> > > > Tauren
> > > >
> > > >
> > >
>
-------------------------------------------------------------------------
> > > > This SF.net email is sponsored by DB2 Express
> > > > Download DB2 Express C - the FREE version of DB2 express and take
> > > > control of your XML. No limits. Just data. Click to get it now.
> > > > http://sourceforge.net/powerbar/db2/
> > > > _______________________________________________
> > > > Wicket-user mailing list
> > > > Wicket-user@lists.sourceforge.net
> > > >
> https://lists.sourceforge.net/lists/listinfo/wicket-user
> > > >
> > >
> > >
> > >
>
-------------------------------------------------------------------------
> > > This SF.net email is sponsored by DB2 Express
> > > Download DB2 Express C - the FREE version of DB2 express and take
> > > control of your XML. No limits. Just data. Click to get it now.
> > > http://sourceforge.net/powerbar/db2/
> > > _______________________________________________
> > > Wicket-user mailing list
> > > Wicket-user@lists.sourceforge.net
> > >
> https://lists.sourceforge.net/lists/listinfo/wicket-user
> > >
> > >
> >
> >
>
-------------------------------------------------------------------------
> > This SF.net email is sponsored by DB2 Express
> > Download DB2 Express C - the FREE version of DB2 express and take
> > control of your XML. No limits. Just data. Click to get it now.
> > http://sourceforge.net/powerbar/db2/
> > _______________________________________________
> > Wicket-user mailing list
> > Wicket-user@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/wicket-user
> >
>
>
>
-------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> _______________________________________________
> Wicket-user mailing list
> Wicket-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/wicket-user
>
>
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user