Displaying one data field in two textfields without blank lines

I need to display data that is coming in from one field in two different text fields, depending on an attribute of that data. The result should be two columns, similar to what you would get in a table.

My data comes in XML formatted like this:

<color> blue <type>dark</type></color>

<color>red<type>light</type></color>

<color> green <type>dark</type></color>

<color>yellow<type>light</type></color>

What I want the output to be is:

Dark Light
blue red
green yellow

I put these onto my report with two textfields and a print when expression. Each field displays "color" but the one on the left displays when type=dark, and the one on the right prints when type=light

Unfortunately, this results in a output like this:

Dark Light
blue  
  red
green  
  yellow

Is there another way I can do this that will let me sort my two types of data from a single field into two table-like columns?

 

jbenway's picture
182
Joined: Sep 10 2014 - 1:02pm
Last seen: 8 years 2 hours ago

2 Answers:

Another way od doing this would be to use the List Component.

Drag 2 list components, one for Dark and seconf for Light. Set the datasources of these two lists to ur XML.

Set the Print order property of the Lists to be Vertical

Place the Lists Sided by Side

 

Add one text field to each List. Set the first text field PrintWhen expression to  type =Dark and the second one PrintWhen expressin to type =Light.

This should solve your problem. Hope tis helps

 

 

 

AnnMary.Thomas's picture
Joined: Jun 18 2014 - 4:41am
Last seen: 1 year 9 months ago

Thank you! This worked, with a fair amount of tweaking. I really appreciate it.

The keys were a) to start with this tutorial on lists, which are more complex that other stuff I've done so far:
http://community.jaspersoft.com/wiki/lists-jaspersoft-studio

Also, I had a lot of trouble mapping the "type" field properly for use with a PrintWhen expression. What I ended up doing instead was to create two separate fields in the dataset that I created (based on the tutorial), one for ColorDark and the other for ColorLight. To define ColorDark in the dataset, I used color[../type="dark"]

Then I created two separate lists as you suggested, each with a textfield mapped to their own field, and set it to Blank when Null and Remove Line When Blank

jbenway - 8 years 8 months ago

If my answer has helped you please check this as answered :)

AnnMary.Thomas - 8 years 8 months ago

For each text field set Remove Line when Blank to true. And also set each text field Position Type to Float.

AnnMary.Thomas's picture
Joined: Jun 18 2014 - 4:41am
Last seen: 1 year 9 months ago

Thank you so much for the response! Unfortunately, making these changes doesn't seem to help. I think it might be because the, as the hover text for remove line when blank says, it collapses the band if the element is not printing AND no other element is occupying the same horizontal space.

I'm guessing that "green" in my example above is not moving up next to "red" because red is occupying horizontal space.

As an experiment, I tried lining my two fields up vertically:
$F{color}
$F{color}

and in this case the setting you recommend does close up those blank lines. However, I need the two fields to be alongside each other.

jbenway - 8 years 8 months ago
Feedback