You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Guy Rouillier <gu...@burntmail.com> on 2009/10/08 21:22:05 UTC
Provide empty object or list for association and collection
We are using (for the first time) facelets for our newest web
application. To present data in a facelet, you reference a bean
property, e.g., location.state.stateNm. Under the covers, the facelet
viewer translates this to location.getState().getStateNm(). This
translation is done by the expression language (EL) engine.
I have an association as in the example above from a location table to a
state table via a state_id. Everything works well using the association
record in the result map. However, sometimes no state_id is provided.
In that case, iBatis sets the state property within location to null,
and the above expression produces a NullPointerException.
Is there a way I can instruct iBatis that if the state_id column within
location is null, set the state property within the location object to a
new empty instance of the state object? i.e, location.setState(new
State()). All the properties of the state object would obviously be
null, but the EL engine can deal with that.
Two existing solutions I can see are
(1) after doing a selectLocation, check the state property and if null,
set it to an empty instance myself
(2) write a type handler to achieve (1)
But it would be handy to have a nullValue option on the <association>
tag. If nullValue="new" and the column value is null, then
automatically create an instance of the specified javaType.
--
Guy Rouillier
---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org