Jump to content

Java: cannot cast boolean to Boolean


aetherflux

Recommended Posts

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

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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... etc

In 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 FIELD

Right 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 box

Check 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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...