Jump to content
Changes to the Jaspersoft community edition download ×

Displaying one data field in two textfields without blank lines


jbenway
Go to solution Solved by AnnMary.Thomas,

Recommended Posts

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:

DarkLight
bluered
greenyellow

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:

DarkLight
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?

 

Link to comment
Share on other sites

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

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.

Link to comment
Share on other sites

  • Solution

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

 

 

 

Link to comment
Share on other sites

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

 

 

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