• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

fmt & html tags together??

 
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I may be going down the wrong road in trying mix the struts-html & format tags, but here goes...

In a JSP, I'm formatting a double from my bean into currency. This works fine when I'm just displaying the data in a table, but now I want to pre-populate a text field with the formatted data, using the <html:text...> tags, & it's not working.

Here's my JSP excerpt...






Here's my error...



Has anyone used these two together (successfully) before??

Thanks!
 
Ranch Hand
Posts: 751
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I haven't used this tag before. But with you saying


In a JSP, I'm formatting a double from my bean into currency. This works fine when I'm just displaying the data in a table, but now I want to pre-populate a text field with the formatted data, using the <html:text...> tags, & it's not working.



My answers are...
- I'm assuming that it should be getting a String type
- Since you're using bean... Shouldn't there be a property mentioned in your EL like ${fee.value}? Or unless you set the bean's property to a request/session attribute.

I'm thinking maybe you should do it like this...



tell me how my suggestion went.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I haven't tried this approach, and I'm not sure it will work.

The authors of the Struts documentation recommend using Strings to represent numbers in an ActionForm. Part of this has to do with validation, and part with formatting.

What I normally do in this situation is create a second pair of accessors on the ActionForm: getFormattedFee() and setFormattedFee(). The getFormattedFee() method returns a string with the fee formatted in the desired format. The setFormattedFee{} method takes a String argument and checks to make sure it's a valid number before storing the value in the numeric fee property.
[ January 24, 2006: Message edited by: Merrill Higginson ]
 
Gail Schlentz
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wow - thanks for the quick responses!

Timothy - I'm not clear on what you mean by

"Shouldn't there be a property mentioned in your EL like ${fee.value}? "


Sorry - I did short-hand in my example - it should be


Merrill - I had kept the String idea in the back of my head, hoping to not have to use it, but it looks like I'll just have to bite the bullet. It will probably make a lot of things easier, anyways!

Thanks, guys!!
[ January 24, 2006: Message edited by: Elaine Micheals ]
 
Timothy Sam
Ranch Hand
Posts: 751
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmmmm... When I was still being trained with Servlets and JSP I was advised to "always use Strings" or as much as possible, keep your members as type String. This would save you a lot of headache, trust me.
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I was had a String in the value but still, the formatting is not happening I am getting an error.

<fmt:formatNumber pattern='$0.00'>
<html:text size="7" property="escrowBalance" value="213.0">
</fmt:formatNumber>

Error:
javax.servlet.jsp.JspException: Can't insert page '/WEB-INF/pages/escrowEntry.jsp'. Check if it exists.
For input string: "<input type="text" name="escrowBalance" value="213.0">"
at org.apache.struts.taglib.tiles.InsertTag$InsertHandler.doEndTag(InsertTag.java:910)
at org.apache.struts.taglib.tiles.InsertTag.doEndTag(InsertTag.java:462)
at jsp_servlet._web_45_inf._layout.__layout._jspService(__layout.java:282)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:33)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1006)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:419)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:315)
at weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:322)

Thanks in advance for help!
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The solution as mentioned above is to do the formatting via the action form and have just:
<html:text size="7" property="formattedEscrowBalance">
and have the get/set formattedEscrowBalance convert to and from a String

The other thing to point out is that the formatNumber tag is expecting a NUMBER. It is not expecting a textfield with a value in it.
Instead what you should be saying is "This is a textfield, and its value is this formatted number"
ie



That will deal with displaying the number correctly on screen.
You will of course still have to handle it on the ActionForm set method.
 
reply
    Bookmark Topic Watch Topic
  • New Topic