Wrap Text in JSF Page - jsf

I have a JSF page with xhtml and java file.
In my xhtml page, I use this to display data:
<h:outputText style="font-weight: bold;white-space: pre" value="Failing Program:" />
<h:outputText style="" value="#{registerData.fp}" styleClass="courierFont"/>
And in my java file, I read the content from a text file and substring it as:
fp = genRegStr.substring(998,1058);
It displays the output as:
The gap between failing program and content is needed and is my css. But is there a way to erradicate the space between the
Z2S0 OBJ-z2s0sx +000011BC TRC-COA4 LOADSET-BASE
I tried the replaceAll function in java but doesnt seem to work. Any other way using css or even java? All i need is to remove extra spaces and leave only one space inbetween the content.

Use trim() with replaceAll(" +", " ") as following:
String before = "Z2S0 OBJ-z2s0sx +000011BC TRC-COA4 LOADSET-BASE";
String after = before.trim().replaceAll(" +", " ");
trim() will truncate leading and trailing spaces, while replacAll() with this expression " +" will replace multiple spaces present in the string with single space.

Use String.trim() when retrieving the string from the file:
Returns a copy of the string, with leading and trailing whitespace omitted.
Change
fp = genRegStr.substring(998,1058);
By
fp = genRegStr.substring(998,1058).trim();

Related

Python String cleanup from spaces and Unknown empty element

I got attribute from Selenium Element and it contains empty char or spaces:
When I double click the result :
In VS code:
What I tried so far :
string.replace(" ","") #didnt work
So I came with this resolution (I know its bad ):
edit1 = ticketID[:1]
ticketF = ticketID.replace(edit1,"")
edit2 = ticketF[:1]
ticketE = ticketF.replace(edit2,"")
edit3 = ticketE[:1]
ticketD = ticketE.replace(edit3,"")
What Im looking for is what is those blanks ? tabs ? new lines ?
how to make it better ?
Edit:
ticketID.replace("\n","")
ticketID.replace(" ","")
ticketID.strip()
Those are basically whitespaces, Please use .strip() for any trailing spaces.
In Python, the stripping methods are capable of removing leading and trailing spaces and specific characters. The leading and trailing spaces include blanks, tabs (\t), carriage returns (\r, \n), and the other lesser-known whitespace characters.
If you have ele as an web element.
You can use .text to get the text and then on top of that use .strip()
Probably in your code :
ticketID.text.strip()
They look like lines and not spaces to me.
string.replace("\n","")

SPLIT results with separator

I'm trying to split a string (separated with the HTML break tag), without deleting the break tag. I think it's pretty messy to add a break as string after splitting, so is there any function/possibility to keep the separator while "splitting"?
Example:
<HTML><BODY><p>some text<br/>some more text</p></BODY></HTML>
Expected result:
<HTML><BODY><p>some text<br/>
some more text</p></BODY></HTML>
As far as I know SPLIT removes the separator from the results and it doesn't seem like you can change that.
But you could create your own separator by first replacing your <br/> tag with <br/> plus an arbitrary string that is highly unlikely to ever appear in your HTML source, and then split the HTML using this arbitrary string as a separator instead.
types:
begin of t_result,
segment(2000) type c,
end of t_result.
DATA:
source type string,
separator type string,
brtag type string,
repl type string,
result_tab type standard table of t_result,
result_row TYPE t_result.
brtag = '<br/>'.
separator = '|***SEP***|'.
concatenate brtag separator into repl.
source = '<HTML><BODY><p>some text<br/>some more text</p></BODY></HTML>'.
replace all occurrences of brtag in source with repl.
split source at separator into table result_tab.
LOOP AT result_tab INTO result_row.
WRITE:
result_row-segment.
ENDLOOP.
Output of that example report:
<HTML><BODY><p>some text<br/>
some more text</p></BODY></HTML>
The caveat of this solution is that your custom separator, if not chosen with some care, might appear in your HTML source on its own. I therefore would choose an arbitrary string with a special character or two that would be encoded in HTML (like umlauts) and therefore not appear in your source.
Just use the replace command. replace <br/> with <br/>CR_LF
The CR_LF refers to the carriage return linefeed character.
In more complex cases you can use regex expressions in abap.
class ZTEST_SO definition public create public .
public section.
methods t1.
ENDCLASS.
CLASS ZTEST_SO IMPLEMENTATION.
METHOD T1.
data: my_break type string,
my_string type string
value '<HTML><BODY><p>some text<br/>some more text</p></BODY></HTML>'.
my_break = '<br/>' && CL_ABAP_CHAR_UTILITIES=>CR_LF.
replace all occurrences of '<br/>' in my_string with my_break in character mode.
"check my_string in the debugger :)
"<HTML><BODY><p>some text<br/>
"some more text</p></BODY></HTML>
ENDMETHOD.
ENDCLASS.

embedded spaces in a computed field don't show

I have some code in a computed field where I want to embed some spaces between two values:
var rtn:String = doc.getItemValue("RefNo")[0] + " " + doc.getItemValue("Company")[0];
the computed field Display Type = text and the content type is String but the display strips out all the extra spaces. Is there a function like insertSpaces(5) that would insert 5 hard spaces?
Figured it out insert "&#160" + "&#160" and display as HTML. fairly simple but really ackward.
It will print them out as whitespace in HTML output. It will not be rendered.
You can add instead (5 times in your case).
An alternative way is to set style="white-space: pre;" (works IE8+ and other browsers)

Replace numbers in a string

I Have some text file. theses texts contain a string like this(a part of text):
<abbr class="word p1"">dd</abbr>
<img src"D:\Images\1.png">
<abbr class="word p1">dd</abbr>
<img src"D:\ticket\t\1.png">
In each text file,(D:\Images\1.png) png name is different but it is always numbers(from 1 to 114)for example(1,2,3,10,...)
I want to replace this text D:\Images\[number].png with a specific text for expample:
string newtext=Replace("D:\Images\[number].png","Something");
How can i do this?
thanks.
Use a regular expression:
string newtext = Regex.Replace(text, #"(D:\\Images\\)\d+(.png)","$1Something$2");
It will replace the full match, including D:\Images\ and .png, so $1 and $2 puts back what's caught by the parentheses, so that Somthing only replaces the digits.
Use regular expressions that are represented mostly be the Regex class. See these links:
http://www.codeproject.com/Articles/93804/Using-Regular-Expressions-in-C-NET
http://msdn.microsoft.com/en-us/library/ms228595%28v=vs.80%29.aspx

Replace text inside div

I have a lot of html files that I want to add a rel="nofollow" to all the a href tags that are into a specific div.
I think c# code can do it. But how do I relate only partial code..?
Any suggestion? also I didnt realy know
Here is what I think:
Parse the HTML line by line
Look for " block start you would need to find the means look for "/div>".
Store all the content between "" into a string
check if "href=" is found and how many
Now parse this string again to search all "" and match with "href=" counter
#5 will give you an array of "href=" tag based lines
Now you can assume every "href=" tag must have ">" at the end of the "
At the last this is what you can do:
string s1 = " this is link ";
string s2 = s1.Insert(s1.IndexOf(">"), " rel=\"nofollow\"");

Resources