Line break or new paragraph inside foreach jsp - spring

I got a small problem i want to add for example i have some values in my foreach which i recive from my database how can i add a br or a p because now its just in one value
<c:forEach var="vac" items="${loc}">
<div class="featurette">
<p class="vactextl">
${vac.description}
</p>
</c:forEach>
I get now a text from database but i want to add a new line or break.
what i want the text is coming from a database its very long discription text i want to add breaks or paragraph in it but now i cant when i print it out there is no paragraph or anything just text is the are way to do this?
In my database is stored like this http://puu.sh/q73rp/b26d8f7014.png
But when i show it on html i get this http://puu.sh/q73uY/4026d4dc62.png
Is there a way to replace \n \r with br this would be fix the problem

Its obviously wrong way to do it like below but for now you can do it
<c:forEach var="vac" items="${loc}">
<div class="featurette">
<p class="vactextl">
${vac.description}
<%out.println("<br>")%>
</p>
</d>
</c:forEach>
Note: out is jsp's implicit object

You're going to have to split your string if you want to output it with line breaks from the database. You can then try putting the split strings in an arraylist then output them in your forEach loop.
<c:forEach var="vac" items="${loc}">
<div class="featurette">
<c:out value="${vac.description}" /><br/>
</c:forEach>

Related

Extract text and ignore next node

From this:
<span class="postbody">
<span style="color: #8e2fb6">
<span style="font-weight: bold">nickname</span>
</span>
<br>
Example text
<br>
Example text
<br>
<p class="signature">THIS IS WHAT I DO NOT WANT</p>
</span>
I want to extract:
<br>
Example text
<br>
Example text
<br>
I tried: span/text()[1] but it seems not to work. I always get unwanted p class. Is it even possible to do?
First you need to load your Html string into a HtmlDocument or HtmlNode (Using .load() function).
ChildNodes collection contains every children of your current node (Basically every nodes under span.postbody).
After that what you need to do is pretty obvious, just grab #text and br nodes (keep in mind that you will receive some #text nodes that have just whitespace characters. You may want to filter it out in the result.
//load html to HtmlNode
node.ChildNodes.Where(n => n.Name.Equals("#text") || n.Name.Equals("br")) //It will return collection of HtmlNode
You can use the jQuery selector for postbody, then the .text method which should ignore the HTML. This will also ignore the .
$('.postbody').text();
An alternative would be to iterate through the children of the $('.postbody').text();
'//text()[preceding-sibling::br and normalize-space()]'

Smarty Conditionals strings

I need to create a single string in SMARTY from two as below
{$value.b64id} = ?type=1&id=aWQ9
this is what I have got so far, cant seem to get anywhere. I think the quote marks are messing me up!!
{assign var='controls' value='<a style="color: red;" href="http://example.com'|cat:{$value.b64id}|cat:'">click Me</a>'}
so what I want from the end of it
{$controls} = <a style="color: red;" href="http://example.com?type=1&id=aWQ9">click Me</a>
Many Thanks
First of all, you only need to use delimiters for variables if you want to display them in the template. When you're using variables inside a smarty function that's not necessary, so
|cat:{$value.b64id}
should be
|cat:$value.b64id
However, if you need to compose a string to reuse it several times, it's probably better to use {capture}
{capture "controls"}
<a style="color: red;" href="http://example.com{$value.b64id}">click Me</a>
{/capture}
and then just use {$controls}

How to take XPath of element that is between br tags with <strong> in account

My code is like this,
<div>
<strong> Text1: </strong>
1234
<br>
<strong> Text2: </strong>
5678
<br>
</div>
where numbers, 1234 and 5678 are generated dynamically. When I take XPath of Text2 : 5678, it gives me like /html/body/div[7]/div/div[2]/div/div[2]/div[2]/br[2]. This does not work for me. I need to take XPath of only "Text2 : 5678". any help will be appreciated. (I am using selenium webdriver and C# to code my test script)
I second #Anil's comment above. The text "Text2:" is retrievable as it is within "strong" element. But, "5678" comes under div and is not the innerHTML for either "strong" or "br".
Hence, to retrieve the text "Text 2: 5678", you'll have to retrieve the innerHTML/text of "div" and modify it accordingly to get the required text.
Below is a Java code snippet to retrieve the text:-
WebElement ele = driver.findElement(By.xpath("//div"));
System.out.print(ele.getText().split("\n")[1]; //Splitting using newline as the split string.
I hope you can formulate the above in C#.

C# htmlagilitypack XPath except containt html tag

<div id="Dossuuu11Plus" style="display: block; ">
Text need
<br/>
Not need
<a class="bot_link" href="http://abc.com" target="_self">http://abc.com</a>
<br/>
</div>
This is html code. I use: //td[#class='textdetaildrgI
but it get all content in , I just need "Text need". Please help me. Thanks
You could use
//div[#id='Dossuuu11Plus']/text()[1][normalize-space()]
Explanation:
It will select the first text node found for DIV which in this case is Text need and normalize-space() will trim leading and trailing whitespaces if any.

how to access this element

I am using Watir to write some tests for a web application. I need to get the text 'Bishop' from the HTML below but can't figure out how to do it.
<div id="dnn_ctr353_Main_ctl00_ctl00_ctl00_ctl07_Field_048b9dfa-bc64-42e4-8bd5-b45385e5f45b_view" style="display: block;">
<div class="workprolabel wpFieldLabel">
<span title="Please select a courtesy title from the list.">Title</span> <span class="validationIndicator wpValidationText"></span>
</div>
<span class="wpFieldViewContent" id="dnn_ctr353_Main_ctl00_ctl00_ctl00_ctl07_Field_048b9dfa-bc64-42e4-8bd5-b45385e5f45b_view_value"><p class="wpFieldValue ">Bishop</p></span>
</div>
Firebug tells me the xpath is:
html/body/form/div[5]/div[6]/div[2]/div[2]/div/div/span/span/div[2]/div[4]/div[1]/span[1]/div[2]/span/p/text()
but I cant format the element_by_xpath to pick it up.
You should be able to access the paragraph right away if it's unique:
my_p = browser.p(:class, "wpFieldValue ")
my_text = my_p.text
See HTML Elements Supported by Watir
Try
//span[#id='dnn_ctr353_Main_ctl00_ctl00_ctl00_ctl07_Field_048b9dfa-bc64-42e4-8bd5b45385e5f45b_view_value']//text()
EDIT:
Maybe this will work
path = "//span[#id='dnn_ctr353_Main_ctl00_ctl00_ctl00_ctl07_Field_048b9dfa-bc64-42e4-8bd5b45385e5f45b_view_value']/p";
ie.element_by_xpath(path).text
And check if the span's id is constant
Maybe you have an extra space in the end of the name?
<p class="wpFieldValue ">
Try one of these (worked for me, please notice trailing space after wpFieldValue in the first example):
browser.p(:class => "wpFieldValue ").text
#=> "Bishop"
browser.span(:id => "dnn_ctr353_Main_ctl00_ctl00_ctl00_ctl07_Field_048b9dfa-bc64-42e4-8bd5-b45385e5f45b_view_value").text
#=> "Bishop"
It seems in run time THE DIV style changing NONE to BLOCK.
So in this case we need to collect the text (Entire source or DIV Source) and will collect the value from the text
For Example :
text=ie.text
particular_div=text.scan(%r{div id="dnn_ctr353_Main_ctl00_ctl00_ctl00_ctl07_Field_048b9dfa-bc64-42e4-8bd5-b45385e5f45b_view" style="display: block;(.*)</span></div>}im).flatten.to_s
particular_div.scan(%r{ <p class="wpFieldValue ">(.*)</p> }im).flatten.to_s
The above code is the sample one will solve your problem.

Resources