You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Frank Russo <fr...@FXALL.com> on 2006/04/27 18:35:43 UTC

General Converter Question

Is it possible to bind a h:selectBooleanCheckbox component to a String
field? The string field is coming out of the db as a Y or N value. This
is existing code used in a lot of places, and I can't change it. It
should have been stored in the object as a boolean or Boolean, but I
can't change that now.
 
Any ideas on how to do this? I've read about using converter's, but they
don't seem to apply here, unless I have to write my own. I'd rather use
a standard one if I can. 
 
Thanks...

Frank Russo
Senior Developer
FX Alliance, LLC
900 Third Avenue, 3rd Floor
New York, NY 10022
646.268.9949

 

Re: General Converter Question

Posted by Mike Kienenberger <mk...@gmail.com>.
On 4/27/06, Julian Ray <ju...@yahoo.com> wrote:
> If you use something like the BooleanUtils class from commons-lang, much of
> the technical aspects of conversion from strings to boolean values is done
> for you. All you need is a simple converter wrapper and a taglib.
>
> As this is such a common requirement I'm surprised that no one has pushed
> one into the Tomahawk build.

Well, the trick is not to convert from String to Boolean -- it's to
convert back to String afterward.


On 4/27/06, Matthias Wessendorf <ma...@apache.org> wrote:
http://myfaces.apache.org/sandbox/apidocs/org/apache/myfaces/custom/convertboolean/BooleanConverter.html

Yeah!  I'd say that this does what you want.   Note that it has
methods for handling the problem above:

setTrueValue(String)  and setFalseValue(String)

Re: General Converter Question

Posted by Matthias Wessendorf <ma...@apache.org>.
Frank-

perhaps [1] is useful to you

-Matthias

[1] http://myfaces.apache.org/sandbox/apidocs/org/apache/myfaces/custom/convertboolean/BooleanConverter.html

On 4/27/06, Mike Kienenberger <mk...@gmail.com> wrote:
> Yes, this should work.   I have the same issue, but I generally deal
> with it by converting the String type to a boolean type at the
> database layer level.
>
> But there's no reason you can't create a converter.   You'll need to
> manually assign it each place it is used, but that's probably what you
> want to do anyway in this case.
>
>
> On 4/27/06, Frank Russo <fr...@fxall.com> wrote:
> >
> > Is it possible to bind a h:selectBooleanCheckbox component to a String
> > field? The string field is coming out of the db as a Y or N value. This is
> > existing code used in a lot of places, and I can't change it. It should have
> > been stored in the object as a boolean or Boolean, but I can't change that
> > now.
> >
> > Any ideas on how to do this? I've read about using converter's, but they
> > don't seem to apply here, unless I have to write my own. I'd rather use a
> > standard one if I can.
> >
> > Thanks...
> >
> >
> >
> > Frank Russo
> > Senior Developer
> > FX Alliance, LLC
> > 900 Third Avenue, 3rd Floor
> > New York, NY 10022
> > 646.268.9949
> >
>


--
Matthias Wessendorf
Aechterhoek 18
48282 Emsdetten
http://jroller.com/page/mwessendorf
mwessendorf-at-gmail-dot-com

RE: General Converter Question

Posted by Julian Ray <ju...@yahoo.com>.
If you use something like the BooleanUtils class from commons-lang, much of
the technical aspects of conversion from strings to boolean values is done
for you. All you need is a simple converter wrapper and a taglib.  

As this is such a common requirement I'm surprised that no one has pushed
one into the Tomahawk build.

-----Original Message-----
From: Mike Kienenberger [mailto:mkienenb@gmail.com] 
Sent: Thursday, April 27, 2006 12:40 PM
To: MyFaces Discussion
Subject: Re: General Converter Question

Yes, this should work.   I have the same issue, but I generally deal
with it by converting the String type to a boolean type at the database
layer level.

But there's no reason you can't create a converter.   You'll need to
manually assign it each place it is used, but that's probably what you want
to do anyway in this case.


On 4/27/06, Frank Russo <fr...@fxall.com> wrote:
>
> Is it possible to bind a h:selectBooleanCheckbox component to a String 
> field? The string field is coming out of the db as a Y or N value. 
> This is existing code used in a lot of places, and I can't change it. 
> It should have been stored in the object as a boolean or Boolean, but 
> I can't change that now.
>
> Any ideas on how to do this? I've read about using converter's, but 
> they don't seem to apply here, unless I have to write my own. I'd 
> rather use a standard one if I can.
>
> Thanks...
>
>
>
> Frank Russo
> Senior Developer
> FX Alliance, LLC
> 900 Third Avenue, 3rd Floor
> New York, NY 10022
> 646.268.9949
>


Re: General Converter Question

Posted by Mike Kienenberger <mk...@gmail.com>.
Yes, this should work.   I have the same issue, but I generally deal
with it by converting the String type to a boolean type at the
database layer level.

But there's no reason you can't create a converter.   You'll need to
manually assign it each place it is used, but that's probably what you
want to do anyway in this case.


On 4/27/06, Frank Russo <fr...@fxall.com> wrote:
>
> Is it possible to bind a h:selectBooleanCheckbox component to a String
> field? The string field is coming out of the db as a Y or N value. This is
> existing code used in a lot of places, and I can't change it. It should have
> been stored in the object as a boolean or Boolean, but I can't change that
> now.
>
> Any ideas on how to do this? I've read about using converter's, but they
> don't seem to apply here, unless I have to write my own. I'd rather use a
> standard one if I can.
>
> Thanks...
>
>
>
> Frank Russo
> Senior Developer
> FX Alliance, LLC
> 900 Third Avenue, 3rd Floor
> New York, NY 10022
> 646.268.9949
>