I have a JSF form that allows the user to publish a formatted message to other users.
Assuming that the user decides to include tabs (\t) to format the message but then the input fails validation (for eg. too many characters), when the textarea is re-rendered all the tabs have been replaced by spaces.
I can keep the message looking the same by using style="white-space: pre;"
but the tabs are still replaced with spaces and this simply breaks the maximum number of spaces even futher!
Is there a way that I can keep the tabs in the text in the textArea when it is re-rendered? Experimentation has shown that this happens for inputText as well.
XHTML Page:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html" xmlns:t="http://myfaces.apache.org/tomahawk" xmlns:f="http://java.sun.com/jsf/core">
<h:form id="testTabsForm">
<t:panelGrid columns="2">
<t:outputLabel for="textInput" id="textInput_label" value="Text :"/>
<t:inputTextarea id="textInput" cols="100" rows="40" value="#{testTabsBean.text}" required="true" style="white-space: pre;"/>
</t:panelGrid>
<t:commandButton value="Submit" action="#{testTabsBean.submit}"/>
</h:form>
Backing Bean:
public class TestTabsBean implements Serializable {
private String text;
public String submit() {
// cause page validation to fail
return null;
}
public String getText() {
return text;
}
public void setText(final String text) {
this.text = text;
}
}