You can nest models and use a model as the value for a PropertyModel. A PropertyModel knows how to cope with null values as it will return a null. Components and the label component in particular will render an empty string when the model value was found to be null.
So nest or chain your model inside PropertyModels: add(new Label("xxx", new PropertyModel(model, "fieldX"))); add(new Label("yyy", new PropertyModel(model, "fieldY"))); Read the model documentation on the wiki [1]. Try to understand it and commit it to your brain. Print the page, and put it under your pillow at night. Read it while on the toilet, pin it to the side of your monitor, stick it to your rear view mirror, print it on transparent foil and stick it to the inside of your glasses. Martijn [1] http://cwiki.apache.org/WICKET/working-with-wicket-models.html#WorkingwithWicketmodels-Chainingmodels On 5/2/08, smallufo <[EMAIL PROTECTED]> wrote: > Yes . > > In the WebPage , I add MyPanel like this : > > myPanel = new MyPanel("myPanel" , new PropertyModel(this , "myobj")); > > myPanel.setVisible(false); > myPanel.setOutputMarkupPlaceholderTag(true); > add(myPanel); > > > And in the MyPanel : > > 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())); > > } > } > > Because myObj passed to MyPanel is initially null , > In the MyPanel construction time , myObj.getFieldX , myObj.getFieldY will > throw NPEs here... > > I don't know how to solve it ..... > > > > 2008/5/2 Per Newgro <[EMAIL PROTECTED]>: > > > > The code you provided should work. The NPEs comes from within the Panel? > > So > > can you give us an example how you access the model in the panel (with an > > NPE > > throwing component)? > > > > Cheers > > Per > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > -- Buy Wicket in Action: http://manning.com/dashorst Apache Wicket 1.3.3 is released Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.3 --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]