internet explorer - JSF converter is not displaying converted value -


i using internet-explorer 8 , jsf. made custom converter add "\n" after 2 white spaces (to break long strings). converter being invoked , return correct value(i check debugger) unfortunately correct value not being shown on page. xhtml code:

<h:commandlink action="#{bean.sort(property)}"                     style="margin-left:0.01px;margin-right:0.01px;white-space:nowrap;">                     <h:outputtext value="#{header}">                       <f:converter converterid="headerconverter" />                     </h:outputtext> </h:commandlink> 

converter code:

public class headerconverter implements converter {  public headerconverter() { }  public object getasobject(facescontext context, uicomponent component, string value) {     /* converter tylko wyƛwietlania */     throw new runtimeexception("headerconverter - display only"); }  public string getasstring(facescontext context, uicomponent component, object value) {     if (value instanceof string) {          int = 0;         int spaceiter = 0;         string header = (string) value;         string afterchange = header;          (char c : header.tochararray()) {             if (character.iswhitespace(c)) {                spaceiter++;                if(spaceiter == 2) {                    afterchange = "" + header.substring(0, i) + "\n" + header.substring(i+1);                }             }             i++;         }         return afterchange;     }     return null; } 

} of course have vonfigured on faces-config.xml in advance effort.

jsf in context of question merely html code generator. in html, newlines represented <br> element, not \n character.

if rightclick page in webbrowser , view source, you'll see \n made generated html output, not participating in html presentation/formatting.

so, have 2 options:

  1. use <br> instead of \n.

    ... + "<br/>" + ... 

    you need turn off xml escaping.

    <h:outputtext ... escape="false" /> 

    beware of potential xss attack holes when you're redisplaying user-controlled input!

  2. instruct webbrowser interpret \n part of formatting , not of markup (as default). can use css white-space: pre this.

    style="white-space: pre;"  

Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -