Home
Analytics
New Line Character in Dynamic Text
Vik
<value-of>row["FIRST_NAME"]</value-of>
<value-of format="html"><br></value-of>
<value-of>row["LAST_NAME"]</value-of>
It is required to print the first name and last name within the same dynamic text but the last name should be in a newline. The above piece of code does not work.
Any suggestions how do I achieve this. I was putting the above piece of code in Expression Builder of Dynamic text.
Find more posts tagged with
Comments
mwilliams
You're using this in a text box, correct? Not in a dynamic text box? What are you getting when you put the above code in?
Vik
I am using a Dynamic text box. The above code throws syntax error.
I also tried row["FIRST_NAME"]+"/n"+row["LAST_NAME"] which works perfectly fine if we use a text box, but does not work with a dynamic text box.
mwilliams
Why not use the code in a HTML text box? The <value-of> tag is the same as using a dynamic text box.
Vik
Sure, I will try that and let you know the results.
But, could you also help me understand the problem in the above two approaches mentioned by me.
Both of them seem to be logical, they just do not work.
mwilliams
This works in a dynamic textbox:
row["FirstName"] + "<br>" + row["LastName"]
mwilliams
You don't use the <value-of> tag in the dynamic text box. I'm not sure why the \n method doesn't work, but the <br> one does, so I guess as long as something works, it's ok.
johnw
There might be some confusion on terminology used.
A Dyanmic Text Box is almost the same exact thing as a Data report item, except it does not create a binding. It will evaluate Javascript, and return a single result. Michaels example works because it is evaluating a Javascript string as a string concatenation in Javascript.
A Text Box (with the helper menu set to Dynamic Text) has little to nothing to do with a Dynamic Text box despite the similar sounding names. A Text Box will simple display what is put in as either plain, non-HTML formatted text (with type set to Plain), or HTML formatted text (with type set to HTML). Auto never seems to work, so I usually ignore it. The drop down that sets the helper menu has the types Formatting, Layout, Content, Lists, and Dynamic Text does not actually set any properties of the Text Box report item. It only displays a quick way to insert HTML tags. These are basically passed through the entire render process untouched and unmodified by the run and render process. The exception being the VALUE-OF tag, which will get rendered like a Javascript expression.
In your first example, <VALUE-OF><BR></VALUE-OF> won't do anything useful. The BR will probably be ignored. The way you want this processed is to set the type of the Text Box report item to HTML, and rewrite it like:
<value-of>row["FIRST_NAME"]</value-of>
<br>
<value-of>row["LAST_NAME"]</value-of>
Because what you are telling it is "Give me the results of FIRST_NAME, then pass through the <BR> tag unmolested by he render engine, then give the results of the LAST_NAME field".
In your second example, using row["FIRST_NAME"]+"/n"+row["LAST_NAME"] in a Dyanmic Text report item should work just fine, but the results won't work as expected. This will process the Javascript as the result of 3 concats, and will write these out to a straight stream, which is usually HTML. The newline character has no meaning in the rendered output you would see in the browser (although if you opened the source, you would see that the first name and last name were on two different lines). This wouldn't work in a Text element, or if it did, it wouldn't give the results you were expecting (it may just display the literal string row["FIRST_NAME"]+"/n"+row["LAST_NAME"] in the result depending on if the type was set to Auto, Plain, or HTML).
Does that answer your question?
Vik
Yes, it does answer my question theoretically
But none of the solutions suggested seem to work
For dynamic text box
row["FirstName"] + "<br>" + row["LastName"]
Only the firstName comes up.
Or
for text box with type=html the height of the row does not increase, so the last name is not visible.
Please, could you give me the rptdesign files in which the above two approaches, mentioned by you work.
mwilliams
Here is a report that shows it working in both a dynamic text box and a standard text box with dynamic text tags. Not sure why it's not working for you. Do you have a height set on your text box or the element the text box is in?
This report is in BIRT 2.5.2.