aetherflux Posted April 12, 2007 Share Posted April 12, 2007 I'm attempting to format a style to make text bold if a particular field (String) has "S" as a value. However, the condition new Boolean($F{myField}.equalsIgnoreCase("S")) is generating an error for some reason. I see no reason why casting a boolean as a Boolean is a problem. I'm using iReport 1.3.2. Link to comment Share on other sites More sharing options...
kaunietiss Posted April 12, 2007 Share Posted April 12, 2007 what kind of error do you get? Link to comment Share on other sites More sharing options...
aetherflux Posted April 12, 2007 Author Share Posted April 12, 2007 ...none, now. I don't know why, but now it's fine. :blink: Thanks for your concern. ^_^" Link to comment Share on other sites More sharing options...
redwine Posted April 12, 2007 Share Posted April 12, 2007 If I understand you correctly, you want to display the contents of a text field as bold if (and only if) the contents of the text field is (let's say for the sake of simplicity) "BOLD" - regardless of case... bold... bOlD...BolD... etcIn that case try this: Create a Parameter named text View > Parameters then click new Enter the following: Parameter name: text Parameter Class Type: java.lang.String Check Use as Prompt (for testing) Default value Expression: "NOT BOLD" (or any value other than our test value which is "BOLD") Just leave the parameter description empty Click OK and close the Parameter (Field & Value dialog box) Create a TEXT FIELDRight click on the text field then go to Properties > Text Field (tab)Enter the following ternary expression in the Text Field Expression box:Code:(new Boolean($P{text}.equalsIgnoreCase("BOLD")) ? '<style pdfFontName="Times-Bold">' + $P{text} + '</style>' : $P{text})Click the Font tab in the properties dialog boxCheck Is styled text (for Line 2 of the expression above to work) Explanation: By using the Java if-else (ternary) operator above, you control the conditions such that IF $P{text} is equal to "BOLD" - ignoring case (LINE 1) THEN Print the contents of $P{text} in boldface (LINE 2) ELSE Print the contents of $P{text} in normal face (LINE 3) The style tags in Line 2 are for printing in pdf. I honestly don't know how it's done in HTML or other output... well at least not yet. Maybe you could us how when you get to it :) REMEMBER to check the Is styled text option if you use the style tags above. I find the style tags good for controlling individual pieces of text in a text field or static text. Comple - Execute* For test purposes, if you don;t already have a query expression, just enter SELECT 1 as your report query. I hope this helps.Post edited by: edwin, at: 2007/04/12 14:29 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