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:
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!
instruct webbrowser interpret
\npart of formatting , not of markup (as default). can use csswhite-space: prethis.style="white-space: pre;"
Comments
Post a Comment