I'd prefer option 1. IMO this would be consistent with (the simple) Model.

It could look like:

public Object getObject()
{
if ((getExpression() == null) || (getExpression().trim().length() == 0))
{
// No expression will cause OGNL to throw an exception. The OGNL
// expression to return the current object is "#this". Instead
// of throwing that exception, we'll provide a meaningfull
// return value
return model.getObject();
}
IModel theModel = getModel();
if(theModel == null)
{
return null;
}
Object modelObject = theModel.getObject();
if(modelObject == null)
{
return null;
}
try
{
Object raw = Ognl.getValue(getExpression(), getContext(), modelObject);
if (applyFormatting)
{
return converterRegistry.getFormattingUtils().getObjectFormatted(
raw, getLocale(), getFormatPattern(), getFormatPattern());
}
else
{
return raw;
}
}
catch (OgnlException e)
{
throw new RuntimeException(e);
}
}


which is a bit more efficient (only does getModelObject once, and tests the expression first) than the current implementation.

Regards,

  Eelco

Johan Compagner wrote:

I have a form with some textfields
But sometimes that form doesn't have to do anything because there is no Object in the model
So i call
form.setVisible(false)


but still i get this:

java.lang.NullPointerException: Model and model object must not be null
at com.voicetribe.wicket.PropertyModel.getObject(PropertyModel.java:190)
at com.voicetribe.wicket.Component.getModelObjectAsString(Component.java:317)


at com.voicetribe.wicket.markup.html.form.TextField.handleComponentTag(TextField.java:131)



even setting all the child components to non visible doesn't have a desired effect.
Do we need to go through the render fase even when it is not visible?


i think so because we do this:

handleRender(visible ? cycle : cycle.nullResponse());

in the Component.render()

so what options do we have to support an null object in such an example?
If we have to go through the render fase with a null response then i see 2 options:


1> PropertyModel shouldn't throw a null pointer.
2> Component.getModelObject and Component.getModelObjectAsString() should be able to handle this gracefully.
(If it sees that the object of its model == null and it is not visible then there is no error)


I think i prefer option 2 but there is one problem with it. Normally i just would call setVisible(false) on the parent (the form object)
not all its child components. So how does a child component know that he is also not visible. I think setVisible of component should
be overriden by Container and that one should call setVisible on all its components.


other idea's?

johan




-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. http://productguide.itmanagersjournal.com/
_______________________________________________
Wicket-develop mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/wicket-develop




-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. http://productguide.itmanagersjournal.com/
_______________________________________________
Wicket-develop mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/wicket-develop

Reply via email to