Results 1 to 17 of 17
- 09-02-2010, 02:37 PM #1
Senior Member
- Join Date
- Jan 2010
- Posts
- 138
- Rep Power
- 0
- 09-02-2010, 02:45 PM #2
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 696
- Rep Power
- 6
- 09-02-2010, 02:51 PM #3
Senior Member
- Join Date
- Jan 2010
- Posts
- 138
- Rep Power
- 0
can you please give me an example ..? thanks in advance
- 09-02-2010, 03:12 PM #4
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 696
- Rep Power
- 6
You can have something like this in your Jasper template:
Java Code:java.text.NumberFormat.getInstance(java.util.Locale.US).format($F{FIELD_NAME})Website: Learn Java by Examples
- 09-02-2010, 03:28 PM #5
Senior Member
- Join Date
- Jan 2010
- Posts
- 138
- Rep Power
- 0
Hi..
my case is I want to change number format of a textField in Jasper at run-time..
ie.
I want to change textField number format to ###,##0 (default is: ###,##0.00)
please helpLast edited by newbiejava; 09-02-2010 at 04:28 PM.
- 09-03-2010, 02:10 AM #6
Senior Member
- Join Date
- Apr 2010
- Location
- Philippines
- Posts
- 580
- Rep Power
- 4
Why would you like to change the Number format at run-time. It is a report and should have fix format of output.
- 09-03-2010, 02:40 AM #7
Senior Member
- Join Date
- Jan 2010
- Posts
- 138
- Rep Power
- 0
I give user options for changing the numericformat when they want to run report..
the numeric format options are:
###,##0
###,##0.00
so, the numeric format of JTextField of the report should follow to chosen numeric format option
- 09-03-2010, 03:23 AM #8
Senior Member
- Join Date
- Apr 2010
- Location
- Philippines
- Posts
- 580
- Rep Power
- 4
use tertiary format.
SYNTAX:
Java Code:condition ? expression (true part): expression (false part)
- 09-03-2010, 03:27 AM #9
Senior Member
- Join Date
- Jan 2010
- Posts
- 138
- Rep Power
- 0
from java class.. how to change the JTextField pattern format ?
could you please give me an example?
Thanks in Advance
- 09-03-2010, 04:48 AM #10
Senior Member
- Join Date
- Apr 2010
- Location
- Philippines
- Posts
- 580
- Rep Power
- 4
Nope. you will do this at iReport. You will need to create a parameter and a variable. At variable you create place your conditional expression or simply use the parameter to format the variable..
CONDITIONAL:
* ORJava Code:$P{param_input}.equals( new java.lang.String('someInput')) ? new java.text.DecimalFormat("#,##0").format($F{YOUR_FIELD}) : new java.text.DecimalFormat("#,##0.00").format($F{YOUR_FIELD})
USE THE PARAMETER INPUT.
USER INPUT should be in "#,##0" or "#,##0.00" only
Java Code:new java.text.DecimalFormat($P{param_input}).format($F{YOUR_FIELD})
- 09-03-2010, 07:00 AM #11
Senior Member
- Join Date
- Jan 2010
- Posts
- 138
- Rep Power
- 0
I am also new to jasper, where should put the codes below:
new java.text.DecimalFormat($P{param_input}).format($F {YOUR_FIELD}) :confused:
- 09-04-2010, 01:12 AM #12
Senior Member
- Join Date
- Apr 2010
- Location
- Philippines
- Posts
- 580
- Rep Power
- 4
From the Report Inspector click the variable that you created then from its properties you will see variable expression, type the code there.
- 09-04-2010, 01:55 AM #13
Senior Member
- Join Date
- Jan 2010
- Posts
- 138
- Rep Power
- 0
Thanks,
what I have done are as follow:
I created a parameter named NUMBER_ FORMAT
and apply it on the field -> edit expression -> variables -> then put: new java.text.DecimalFormat($P{NUMBER_FORMAT}).format( $F{displaycost})
and with call it thru my java codes below:
Java Code:public void viewReport() { try { String jrxml = getJRXML(); if (cls1.isFileDirectoryExists(jrxml)) { Map params = new HashMap(); params.put("NUMBER_FORMAT", "###,##0.0000"); // just for try JasperDesign jasperDesign = JRXmlLoader.load(jrxml); JRDesignQuery query = new JRDesignQuery(); query.setText(getSQL()); jasperDesign.setQuery(query); JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign); Connection jdbcConn = connectMySQL(); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, jdbcConn); JasperViewer.viewReport(jasperPrint, false); } else { cls1.msgBox(null, jrxml + " does not exists", Class1.MESSAGE_INFO); } } catch (Exception ex) { cls1.msgBox(null, ex.toString() , Class1.MESSAGE_INFO); } }
I tried it but it gives me below exception:
net.sf.jasperreports.engine.fill.JRExpressionEvalE xception: Error evaluating expression:
Source.text: new.java.text.DecimalFormat($P{NUMBER_FORMAT}).for mat($F{displaycost})Last edited by newbiejava; 09-04-2010 at 02:03 AM.
- 09-04-2010, 02:33 AM #14
Senior Member
- Join Date
- Apr 2010
- Location
- Philippines
- Posts
- 580
- Rep Power
- 4
Did you try to preview the report using just the iReport application?
- 09-04-2010, 02:41 AM #15
Senior Member
- Join Date
- Jan 2010
- Posts
- 138
- Rep Power
- 0
strange.. it works if I try it using iReport application..
what I missed with my codes?
- 09-04-2010, 02:52 AM #16
Senior Member
- Join Date
- Apr 2010
- Location
- Philippines
- Posts
- 580
- Rep Power
- 4
Hmm... I think we are having misunderstanding here....
Did you created a parameter called NUMBER_FORMAT and paste the code in its expression editor?
Lets check if you did these steps.
1. Create a parameter name it NUMBER_FORMAT. (as I can see you have done this).
2. Create a variable called New_DisplayCost.
*From report inspector(left side of your screen) right click VARIABLES(icon is like fx)>add variables(it will create new variable called variable1)>right click variable1>rename it to New_DisplayCost.
3. On the right side of your screen there is a properties window(if you dont see it goto Window>click Properties). From properties window you will see a VARIABLE Expression, paste the code there.
- 09-04-2010, 04:03 AM #17
Senior Member
- Join Date
- Jan 2010
- Posts
- 138
- Rep Power
- 0
Similar Threads
-
how to change oracle 10g XE http port number
By sireesha in forum JDBCReplies: 4Last Post: 03-16-2012, 11:40 AM -
jasper report ,jasper report jar files and maven dependencies.
By rajuchacha007 in forum Advanced JavaReplies: 1Last Post: 04-09-2010, 08:15 AM -
how from an Access Currency field I populate a hidden field
By lse123 in forum Java ServletReplies: 4Last Post: 01-17-2010, 11:13 PM -
How to change the format of date?
By jboy in forum New To JavaReplies: 1Last Post: 09-09-2009, 01:22 PM -
Close a JDialog Programmatically
By Marcus in forum Advanced JavaReplies: 1Last Post: 07-06-2007, 04:06 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks