Title: how to safely access a nested bean property that may be null

Hi:

If you have in your request a bean B, and bean B has within it a bean B',
which has a property P that you would like to access using a
<bean:write name="B" property="B'.P"/>

Now, you know that B' may be null. How can you protect the reference from failing?

I thought that I could use logic:present as follows:
<logic:present name="B" property="B'">
  <logic:present name="B" property="B'.P">
    <bean:write name="B" property="B'.P"/>
  </logic:present>
</logic:present>

But this fails to work. The second logic:present gets evaluated anyway, and thus
a null pointer is dereferenced.

Any tips appreciated. Apologies for the HTML-this client is configured to send text,
but apparently exchange is converting mail for me.

Thanks,
S-

Reply via email to