voyent
<ice:outputText id="output"  XML
Forum Index -> Components
Author Message
icelearner

Joined: 23/Jan/2008 00:00:00
Messages: 6
Offline


Hi,

I want to display a couple of lines as the output in my browser when the user clikcs the submit button. I built my output string like I want it but when I try to display it, it removes the new line characters.
Can any one explanin why it is doing this.
My xhtml page has the following
Code:
<ice:outputText id="output" 
                           value="#{reclass.outData}"


and this is how I am building the outData string.
Code:
	outData = "test";
                 strData.append(outData);
 	strData.append("\r\n");
 	strData.append("ip " + re.getIp());
 	outData = strData.toString();


Thanks.
mark.collette


Joined: 07/Feb/2005 00:00:00
Messages: 1692
Offline


Web pages don't render whitespace like it would in a plain text file. If you need things to show on a new line, then you can use the <br/> tag. Otherwise you can wrap your text in <pre></pre> tags, or <code></code> tags.
[Email]
icelearner

Joined: 23/Jan/2008 00:00:00
Messages: 6
Offline


Adding these tags also does not make any difference.
Here is my code.
Code:
       StringBuffer contents = new StringBuffer();
         BufferedReader input = null;
 
         try {
           input = new BufferedReader( new FileReader("c:\\temp\\OutPut.txt") );
           String line = null; 
           
          // contents.append("<pre>");
           while (( line = input.readLine()) != null){
             contents.append(line);
             contents.append("<BR>");
             contents.append(System.getProperty("line.separator"));
           }
          // contents.append("</pre>");
         }
         catch (FileNotFoundException ex) {
           ex.printStackTrace();
         }
         catch (IOException ex){
           ex.printStackTrace();
         }
         finally {
           try {
             if (input!= null) {
               //flush and close both "input" and its underlying FileReader
               input.close();
             }
           }
           catch (IOException ex) {
             ex.printStackTrace();
           }
         }
 
 outData is the variable I use to display the contents on the webpage. 
   [code]   <ice:outputText id="output" 
                           value="#{rateenginesetup.outData}"


The output is displayed as one single string instead of sepearate lines.
Like "Balance is $100Item is SnickersOrderConfirmed" instead of
"Balance is $100
Item is Snickers
OrderConfirmed"

Any help with this?
thewolf


Joined: 04/Jan/2008 00:00:00
Messages: 128
Offline


<br> and <br/> are different things! Try the last one as only this is valid XML und AFAIK ICEfaces drops some non-XML compliant tags...
icelearner

Joined: 23/Jan/2008 00:00:00
Messages: 6
Offline


That did not work either. It just displays the <br/> in the output like

"Initial Balance is $4<br/> Socket : createSocket: creating engine socket<br/>"

I made this change in the code as you suggested.
Code:
 // contents.append("<pre>");
           while (( line = input.readLine()) != null){
             contents.append(line);
             contents.append("<br/>");
             contents.append(System.getProperty("line.separator"));
           }
          // contents.append("</pre>");
thienp

Joined: 15/Aug/2007 00:00:00
Messages: 17
Offline


You need to use the escape attribute of the outputText:

<ice:outputText value="blah" escape="false"... />
icelearner

Joined: 23/Jan/2008 00:00:00
Messages: 6
Offline


That worked fine with adding the new line but I have to output some XML data also in my browser and that is messed up now. It does not show the XML tags it only shows the xml data which does not make any sense to the user.

Any suggestions on how I can display the XML data as it is in my log and still add the new lines.

Thanks for your help.
thienp

Joined: 15/Aug/2007 00:00:00
Messages: 17
Offline


You will need to write a utility routine that converts XML entity characters such as "<", ">", etc. into the form of "<", ">" accordingly. Be sure NOT to encode your "<br/>" string. Hope that helps.
thienp

Joined: 15/Aug/2007 00:00:00
Messages: 17
Offline


Sorry, the browser does not display my previous message correctly. Basically, all XML entities need to be in the form of "AMPERSAND"xxx"COLON". Replace "AMPERSAND" and "COLON" with the actual characters.
thienp

Joined: 15/Aug/2007 00:00:00
Messages: 17
Offline


I messed up again. I meant "SEMICOLON", not "COLON".
icelearner

Joined: 23/Jan/2008 00:00:00
Messages: 6
Offline


That worked. Thanks so much for you help.
Here is the code snipet if it helps anyone.

Code:
     while (( line = input.readLine()) != null){
            
             line = line.replaceAll("<", "<");
             line = line.replaceAll(">", ">");
             contents.append(line);
             contents.append("<br/>");
           }


Thanks.
thewolf


Joined: 04/Jan/2008 00:00:00
Messages: 128
Offline


line.replaceAll("<", "<"); 

has to be
Code:
line.replaceAll("<", "&lt;");

and
line.replaceAll(">", ">"); 

has to be
Code:
line.replaceAll(">", "&gt;");
 
Forum Index -> Components
Go to:   
Powered by JForum 2.1.7ice © JForum Team