7rouz Posted June 8, 2007 Share Posted June 8, 2007 hi all, i ceated a report using ireport.while running, sometimes when i have no data in a field i have the value "null" in it. but i like to change it to "-". thanks for the help Link to comment Share on other sites More sharing options...
cris_tyna Posted June 8, 2007 Share Posted June 8, 2007 Hi,You can use Text Field Expression to print whatever you want to print, whenever you want to print.I hope it helps. Tyna Link to comment Share on other sites More sharing options...
7rouz Posted June 8, 2007 Author Share Posted June 8, 2007 thanks cris_tyna for help, but i am new in ireport can you explain more how to do. thanks again Link to comment Share on other sites More sharing options...
cris_tyna Posted June 8, 2007 Share Posted June 8, 2007 In Text Field Expression for your field , type ($F{fieldname}==null)? "-":$F{fieldname} Tyna Link to comment Share on other sites More sharing options...
megotronx Posted June 11, 2007 Share Posted June 11, 2007 i wrote this ($F{C24} == null ? "0" : $F{C24}) for my report but i see blank field where is null.what to do?p.s blank when null checkbox is uncheked Link to comment Share on other sites More sharing options...
megotronx Posted June 11, 2007 Share Posted June 11, 2007 i wrote this ($F{C24} == null ? "0" : $F{C24}) for my report but i see blank field where is null.what to do?p.s blank when null checkbox is uncheked Link to comment Share on other sites More sharing options...
Case1182 Posted June 13, 2007 Share Posted June 13, 2007 == "null" doesn't work in I reports, however != "null" does, so I would do something like thing Code:new java.lang.String($F{fieldname} != "null" ? $F{fieldname} : "-"«») if the field u are using is not a string already then it needs to go like this Code:[code]new java.lang.String($F{fieldname}.toString() != "null" ? $F{fieldname}.toString() : "-"«») Link to comment Share on other sites More sharing options...
7rouz Posted June 13, 2007 Author Share Posted June 13, 2007 thanks Case1182 for your reply.my field is a string field.but when i use you r solution i have this error message. net.sf.jasperreports.engine.JRException:ÂErrorsÂwereÂencounteredÂwhenÂcompilingÂreportÂexpressionsÂclassÂfile: 1.ÂCannotÂcastÂfromÂStringÂtoÂBoolean ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂvalueÂ=Â(java.lang.Boolean)(newÂjava.lang.String(((java.lang.String)field_ENSEIGNANT_NOM_ENS.getValue())Â!=Â"null"Â?Â((java.lang.String)field_ENSEIGNANT_NOM_ENS.getValue())Â:Â"-"));/*$JR_EXPR_ID=15$*/ ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ<--------------------------------------------------------------------------------------------------------------------------------------------------------------------------> 2.ÂCannotÂcastÂfromÂStringÂtoÂBoolean ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂvalueÂ=Â(java.lang.Boolean)(newÂjava.lang.String(((java.lang.String)field_ENSEIGNANT_NOM_ENS.getOldValue())Â!=Â"null"Â?Â((java.lang.String)field_ENSEIGNANT_NOM_ENS.getOldValue())Â:Â"-"));/*$JR_EXPR_ID=15$*/ ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ<--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------> 3.ÂCannotÂcastÂfromÂStringÂtoÂBoolean ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂvalueÂ=Â(java.lang.Boolean)(newÂjava.lang.String(((java.lang.String)field_ENSEIGNANT_NOM_ENS.getValue())Â!=Â"null"Â?Â((java.lang.String)field_ENSEIGNANT_NOM_ENS.getValue())Â:Â"-"));/*$JR_EXPR_ID=15$*/ ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ<--------------------------------------------------------------------------------------------------------------------------------------------------------------------------> 3Âerrors ÂÂÂÂatÂnet.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:193) ÂÂÂÂatÂit.businesslogic.ireport.IReportCompiler.run(IReportCompiler.java:578) ÂÂÂÂatÂjava.lang.Thread.run(UnknownÂSource) Link to comment Share on other sites More sharing options...
Case1182 Posted June 13, 2007 Share Posted June 13, 2007 the field u put it in is Boolean, field can not be boolean for what you are trying to do, because "-" is not boolean, change field to String and it should work Link to comment Share on other sites More sharing options...
7rouz Posted June 13, 2007 Author Share Posted June 13, 2007 Tanks Case1182 but my field isn't a boolean field.it is a String field. Link to comment Share on other sites More sharing options...
megotronx Posted June 13, 2007 Share Posted June 13, 2007 Thanks but i see just blank field in place where i need to see "0".it doesn`t solved my problem.what`s an idea? new java.lang.String($F{C24} != null ? $F{C24} : "0") Link to comment Share on other sites More sharing options...
Case1182 Posted June 13, 2007 Share Posted June 13, 2007 megan ur code need to look like this:Code:new java.lang.String($F{C24} != "null" ? $F{C24} : "0"«») and double check to make sure uncheck the "blank when null" box 7rouzI can tell it is boolean by ur errorCode:[code]Cannot cast from String to Boolean value = (java.lang.Boolean)you are trying to cast the string we are making into a Boolean field, either you are doing that or your iReports is bad, its the one telling you this not me. Link to comment Share on other sites More sharing options...
megotronx Posted June 14, 2007 Share Posted June 14, 2007 i wrote your code, checked n+1 times if the blank when null uncheked but i see the blank anyway.have no idea :S moreover, I tried this on other string fields.No one field changed it`s value...and i found out that this field C24 in my example is not nullable.may be it meansif i enter to the code empty string "" that don`t helpso?any ideas?Post edited by: megotronx, at: 2007/06/14 12:01 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now