Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2007

Tip: Looking for answers? Try searching our database.

Formatting a value (jsp - to thousands)

Thread view: 
compaqr4000@lycos.com - 01 Oct 2007 17:51 GMT
In my jsp form I want to format a variable from something like
235522455 to 235,522,455

I am trying to format it with DecimalFormat as follows:
DecimalFormat dfThou = new DecimalFormat("###,###");
<td class="info"><bean:write name="infoForm" property="<=%
dfThou.format(infoValue(pop).value) %>"/></td>
which obviously does not work.

Here is the line prior to my formatting attempt:
<td class="info"><bean:write name="infoForm"
property="infoValue(pop).value"/></td>

Can anyone help with the syntax?

Thanks!
Kay
Manish Pandit - 01 Oct 2007 19:07 GMT
On Oct 1, 9:51 am, compaqr4...@lycos.com wrote:
> In my jsp form I want to format a variable from something like
> 235522455 to 235,522,455
[quoted text clipped - 13 lines]
> Thanks!
> Kay

You might want to try the fmt tag library. It is a part of JSTL.

<fmt:formatNumber value="12345678" pattern="#,###,###"/> should do it.
You can play around with other options this library provides.

-cheers,
Manish
compaqr4000@lycos.com - 01 Oct 2007 19:20 GMT
> On Oct 1, 9:51 am, compaqr4...@lycos.com wrote:
>
[quoted text clipped - 23 lines]
> -cheers,
> Manish

Okay, I added the format tag:
  <%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
but how can I change the example you displayed
  <fmt:formatNumber value="12345678" pattern="#,###,###"/>
to use the jsp variable:
  <bean:write name="infoForm" property="infoValue(pop).value"/>
instead of the string "12345678"?

Thanks for your patience, I'm not very strong in jsp.

Kay
Manish Pandit - 01 Oct 2007 19:48 GMT
On Oct 1, 11:20 am, compaqr4...@lycos.com wrote:

> > On Oct 1, 9:51 am, compaqr4...@lycos.com wrote:
>
[quoted text clipped - 35 lines]
>
> Kay

Once you are comfortable with basic JSP syntax, try to learn about
avoiding scriptlets. There are alternatives like EL and tag libraries
that are way easier to use, read and code. Anyway, here is what you
can do for now:

<fmt:formatNumber value="<%= however you get this value, using plain
java %>" pattern="#,###,###"/>

In your case I am guessing it'd be something like <fmt:formatNumber
value="<%=infoValue(pop).value%>" pattern="#,###,###"/>

-cheers,
Manish
Lew - 01 Oct 2007 21:22 GMT
compaqr4...@lycos.com wrote:
>> but how can I change the example you displayed
>>    <fmt:formatNumber value="12345678" pattern="#,###,###"/>
[quoted text clipped - 3 lines]
>>
>> Thanks for your patience, I'm not very strong in jsp.

> Once you are comfortable with basic JSP syntax, try to learn about
> avoiding scriptlets. There are alternatives like EL and tag libraries
[quoted text clipped - 6 lines]
> In your case I am guessing it'd be something like
> <fmt:formatNumber value="<%=infoValue(pop).value%>" pattern="#,###,###"/>

You might need a scriptlet output expression with the accessor method
explicity invoked, similar to:

<fmt:formatNumber
    value="<%= infoValue(pop).getValue() %>"
    pattern="#,###,###"
/>

The Struts <bean:write> tag "property" attribute contains
> the name of the property to be accessed on the bean specified by name.
> This value may be a simple, indexed, or nested property reference expression.
<http://struts.apache.org/1.3.8/struts-taglib/tlddoc/bean/write.html>

I'm not accustomed to such complicated expressions in the property attribute.
 What is the corresponding element of the infoForm object?  What is the
property of it that you mean to invoke?

Signature

Lew

compaqr4000@lycos.com - 02 Oct 2007 17:08 GMT
Thanks for your help and suggestions Manish and Lew. Before I go any
further I think that I need to delve a little further into what's
happening in the code, so that I can understand it better. This is
something that someone else developed and I inherited. I thought that
a quick fix might be available, but I don't understand enough yet even
to use your suggestions. Once I have a better grasp I'll post another
question!

Thanks!

Kay

> compaqr4...@lycos.com wrote:
> >> but how can I change the example you displayed
[quoted text clipped - 34 lines]
> --
> Lew
Lew - 02 Oct 2007 22:41 GMT
Please don't top-post.

Lew wrote:
>> I'm not accustomed to such complicated expressions in
>> the property attribute.  
>> What is the corresponding element of the infoForm object?  
>> What is the property of it that you mean to invoke?

> Thanks for your help and suggestions Manish and Lew. Before I go any
> further I think that I need to delve a little further into what's
[quoted text clipped - 3 lines]
> to use your suggestions. Once I have a better grasp I'll post another
> question!

In the meantime, give some thought to answering the questions people have
asked you.

Signature

Lew



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.