Java Mailing List Archive

http://www.java2.5341.com/

Home » user-java.ibatis »

Provide empty object or list for association and collection

Guy Rouillier

2009-10-08


Author LoginPost Reply
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@(protected)
For additional commands, e-mail: user-java-help@(protected)

©2008 java2.5341.com - Jax Systems, LLC, U.S.A.