ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Lieven De Keyzer" <lieven_dekey...@hotmail.com>
Subject Re: Re: struts vs ibatis - Integer type
Date Fri, 06 May 2005 17:17:29 GMT

>From: Brandon Goodin <brandon.goodin@gmail.com>
>Reply-To: Brandon Goodin <brandon.goodin@gmail.com>
>To: ibatis-user-java@incubator.apache.org
>Subject: Re: Re: struts vs ibatis - Integer type
>Date: Fri, 6 May 2005 10:06:36 -0600
>Your problem is not ibatis. Your problem is how BeanUtils within
>Struts translates an empty request parameter into an Integer property
>on your bean. I would handle this issue on the Struts layer. You can
>handle it either in your action form with a setter that receives a
>string and sets the value into your bean or you can write a custom
>Converter for BeanUtils.

But as far is I see, when a Bean is constructed, an int property will always 
be 0, when not specified. So when I perform an insert through iBatis 
SQLmaps, this beanproperty will always be an integer? Where exactly are the 
commons classes needed and created ?
Perhaps I'm not really understanding the purpose of the ConvertUtils and 
It's just that this is my first real project in Java and I find the apidocs 
of this kind of projects a little bit overwhelming. So a bit OT then, could 
you point me to a good resource about this topic?

I recommend that you post this question to
>the Struts list.
>On 5/6/05, Lieven De Keyzer <lieven_dekeyzer@hotmail.com> wrote:
> > >The only way to make that "clean" is to push the translation effort
> > >into your ActionForm and nest your real beans in the ActionForm. you
> > >would then have a String value that you convert and set into your
> > >nested bean. The other option is to write a different BeanUtils
> > >Converter implementation for numerics and register it
> > 
> >(http://jakarta.apache.org/commons/beanutils/api/org/apache/commons/beanutils/ConvertUtils.html#register(org.apache.commons.beanutils.Converter,%20java.lang.Class).
> >
> > I like this second approach because I presume that in this case, all 
> > columns will be set to NULL if no value is provided. I just don't see 
>why an
> > empty INTEGER column should be 0.
> > But how would I approach this problem? First rewrite the Jakarata 
> > converter, and then recompile the iBatis classes with these commons 
> >
> > >
> > >I would personally avoid cluttering up your domain bean with faux
> > >setters and getters.
> > >
> > >Brandon
> > >
> > >On 5/2/05, Darek Dober <[EMAIL PROTECTED]> wrote:
> > >>  Hi,   I hava a table  'users' with column dept_id (id of department 
> > >>departments
> > >>table)   This column is optional. That means the operator doesn't have 
> > >>assign
> > >>inserted user to any department.   If I have bean:   public class 
> > >>{     Integer departmentId;       .... }   struts will make automatic
> > >>conversion of type. So departmentId will be set
> > >>to 0, if I don't set any of department. That's a cheat, because,  I 
> > >>want to to have a department with id equals to 0, it should be NULL.   
> > >>the other hand, when I implement departmentId as String, struts act
> > >>correctly. But while inserting record to the database, I get an error 
> > >>like this: database column dept_id is type of bigint, inserted value 
> > >>type of
> > >varchar.
> > >>   I have the solution: departmentId is type of String, but for ibatis 
> > >>have
> > >>the other metod getDepartmentIdAsInteger which return Integer or null 
> > >>value is empty. It works, but i don't like this.   Is there any 
> > >>solution for this. I looked into jpetstore, but there
> > >>were columns of type varchar. Rest of them was mendatory. I cannot use
> > >>columns of type varchar as foreign keys.   Usage: .... VALUES(
> > >>      #departmentId:INTEGER#,
> > >>....   doesn't help if departmentId is String   Any ideas?   Darek
> >
> >

View raw message