Thank you , I solve most of questions , except this :

In the MyPage extends WebPage :

//fieldX returns an Integer[] array
MyPanel myPanel = new MyPanel("myPanel" , new PropertyModel(model ,
"fieldX")
{
  @Override
  public Object getObject()
  {
    Integer[] ints = (Integer[]) super.getObject();
    return getMyObjectFromInts(ints);
  }
});
add(myPanel);

............................................

And in the MyPanel :

public MyPanel(String id, final IModel model)
{
  super(id , model);

  Link myLink = new Link("myLink")
  {
    @Override
    public void onClick()
    {
      Map<String , Object> parameterMap = new HashMap<String , Object>();
      parameterMap.put("index" ,  new PropertyModel(model ,
"index").getObject().toString()); // OK
      parameterMap.put("locale" , getSession().getLocale());
      PageParameters pps = new PageParameters(parameterMap);
      setResponsePage(HexagramPage.class , pps);
    }

    @Override
    protected void onBeforeRender()
    {
      super.onBeforeRender();
      add(new SimpleAttributeModifier("title" , new PropertyModel(model ,
"name").getObject().toString())); // , OK
    }
  };

  //draw an Icon depending on index value
  myLink.add(new Image("hexagramImage" , new
ResourceReference(MyObject.class , "icons/byIndex/"+ new
PropertyModel(model,"index").getObject().toString()+".gif")));  //FAILED

Here ! it goes problem!
It will throw a NPE :
java.lang.NullPointerException
  at ....
  at MyPage$2.getObject(MyPage.java:119)  <-------- the
getMyObjectFromInts() line
  at
org.apache.wicket.model.AbstractPropertyModel.getTarget(AbstractPropertyModel.java:187)
  at
org.apache.wicket.model.AbstractPropertyModel.getObject(AbstractPropertyModel.java:110)
  at MyPanel.<init>(MyPanel.java:49) <-------- the ResourceReference line


As MyPage shows , I use getMyObjectFromInts() to transform fieldX's return
value to my custom object....
And in MyPanel , I can successfully get myObject's index , name values , but
it fails at the last line!
It constructs a ResourceReference object by initializing a String , which
takes myObject's "index" value.
I use the same "new PropertyModel(model,"index").getObject().toString() " ,
successes first but fails second , why ?
How to solve this ?



2008/5/3 Per Newgro <[EMAIL PROTECTED]>:

> Hello smallufo:
>
> > public class MyPanel extends Panel
> > {
> >   private MyObj myObj;
> >
> >   public MyPanel(String id , IModel model)
> >   {
> >     super(id);
> >     this.myObj = (MyObj) model.getObject();
> >
> >     add(new Label("xxx" , myObj.getFieldX.toString()));
> >     add(new Label("yyy" , myObj.getFieldY.toString()));
> >
> >   }
> > }
>
> This is the problem. Don't store the instance in the panel. Use the
> provided
> model. The Labels can get their data by a PropertyModel related to that
> model.
>  public class MyPanel extends Panel
>  {
>   // removed while not required private MyObj myObj;
>
>   public MyPanel(String id , IModel model)
>   {
>      super(id, model); <-- use this constructor
>     // removed while not required this.myObj = (MyObj) model.getObject();
>
>     // instead add(new Label("xxx" , myObj.getFieldX.toString()));
>     add(new Label("xxx" , new PropertyModel(model, "fieldX")));
>     // instead add(new Label("yyy" , myObj.getFieldY.toString()));
>     add(new Label("yyy" , new PropertyModel(model, "fieldY")));
>   }
>  }
>
> You simply wire the models together. So a model related to view can't be
> null
> (instanciated in panel self). That's what i mean if i always say "path to
> data". It's a description which properties have to be used to get the
> data.
> So the underlying business object can be null. The behavior if a null will
> be
> return will be determined by the component. A label for instance is
> displaying simply a blank. Textfield to.
>
> HTH
> Per
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

Reply via email to