You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by RogerV <ro...@googlemail.com> on 2010/01/29 13:48:04 UTC

Boolean Type Conversion

Hi

I have a collection of objects, each one contains a boolean flag, and I'm
displaying these via a JSP as a list via an interator. Struts is converting
the boolean fields into the strings "true" and "false", I'd like to be able
to 

1) display them as "Y" and "N"
2) convert back to "true" and "false" when the list is returned
3) and do it via annotation if possible.

Having read http://struts.apache.org/2.0.11.1/docs/type-conversion.html it
looks that a custom TypeConvertor is the way to proceed.

Is it possible to create a TypeConvertor that extends the existing Boolean
convertor to return "Y","N" instead of "true", "false"? Where do I find the
convertor or is it a "built-in" function? Is it possible to do the override
via annotation so that I can execute the override where I need it and
default to the standard convertor where I don't.

Regards
-- 
View this message in context: http://old.nabble.com/Boolean-Type-Conversion-tp27371490p27371490.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Boolean Type Conversion

Posted by Roger <ro...@googlemail.com>.
On Friday 29 January 2010 22:30:34 Wes Wannemacher wrote:
> I don't know if I'd go too far creating a TypeConverter... Can you
> just do something like this -
> 
> <s:if test="%{your.boolean.property}">Y</s:if><s:else>N</s:else>
> 
> Really, you could probably create a .tag file out of it and reuse it
> easier than creating a Type Converter.
> 
> -Wes
> 
I can see that working to display, but when the user switches a field from "Y" 
to "N" how do I get "false" automagically returned in the relevant list entry?

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Boolean Type Conversion

Posted by Wes Wannemacher <we...@wantii.com>.
I don't know if I'd go too far creating a TypeConverter... Can you
just do something like this -

<s:if test="%{your.boolean.property}">Y</s:if><s:else>N</s:else>

Really, you could probably create a .tag file out of it and reuse it
easier than creating a Type Converter.

-Wes

On Fri, Jan 29, 2010 at 7:48 AM, RogerV <ro...@googlemail.com> wrote:
>
> Hi
>
> I have a collection of objects, each one contains a boolean flag, and I'm
> displaying these via a JSP as a list via an interator. Struts is converting
> the boolean fields into the strings "true" and "false", I'd like to be able
> to
>
> 1) display them as "Y" and "N"
> 2) convert back to "true" and "false" when the list is returned
> 3) and do it via annotation if possible.
>
> Having read http://struts.apache.org/2.0.11.1/docs/type-conversion.html it
> looks that a custom TypeConvertor is the way to proceed.
>
> Is it possible to create a TypeConvertor that extends the existing Boolean
> convertor to return "Y","N" instead of "true", "false"? Where do I find the
> convertor or is it a "built-in" function? Is it possible to do the override
> via annotation so that I can execute the override where I need it and
> default to the standard convertor where I don't.
>
> Regards
> --
> View this message in context: http://old.nabble.com/Boolean-Type-Conversion-tp27371490p27371490.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>



-- 
Wes Wannemacher

Head Engineer, WanTii, Inc.
Need Training? Struts, Spring, Maven, Tomcat...
Ask me for a quote!

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org