I have a question about the behavior of the getNumber tag in the dbtags tag
library.  We want to use this tag's number formatting feature, and wonder if
it makes sense to give the tag the ability to also parse and format numbers
stored in string columns.  A bit of background, our ResultSet is not
actually coming from a relational database, but is a ResultSet wrapper of a
business object that is representing some of its data as strings.  So in the
example below, when the Price column contains an empty string which it
sometimes can do in our business object:

    <sql:resultSet id="rset1">
                <sql:getNumber colName="Price" format="CURRENCY"
locale="en_US"/>
    </sql:resultSet>

The following exception is thrown in our page:

    javax.servlet.ServletException: Column is not a recognized number type 

So my question is, can this be handled more gracefully by the tag?  If an
empty string is fed to the formatter, can it just output an empty string
(that would be our desired action anyway).  Or if a string containing a
number (like "100.00") is fed to the tag, it attempts to parse the string
into a double and performs the formatting as it currently does.  Of course
if the parse fails, an exception  needs to be thrown.

Of course we can do a work-around, but it gets a little ugly:

1) do a try catch around it, get the column into a pageContext variable with
the to="" parameter and handle the formatting ourself perhaps by writing our
own tag or using something from i18n.
    <% try { %>
        <sql:getNumber colName="Price" format="CURRENCY" locale="en_US"/>
    <% } catch (ServletException se) { %>
        <sql:getColumn colName="Price" to="priceToFormat"/>
    <% 
       ...get priceToFormat from pageContext, parse it into a double, and
format it manually
    } %>

Thanks.

Reply via email to