0

I have 2 spaces in the itemValue "03 R MAIN1". While doing ajax submit, panel is getting reRendered, at that time i could see 2 space has been replaced with one space, because of this values are matching which is selected and the one is in the dropdown. so i am even geting "Validation Error: Value is not valid". Please see the code below:

<a4j:form>
    <a4j:outputPanel ajaxRendered="true" id="TEST">
        <h:messages  layout="table" errorClass="errormsg noticeMsg" fatalClass="errormsg noticeMsg" 
             infoClass="infomsg noticeMsg" styleClass="table-center dont-capitalize" id="err_succ_message" />
        <h:outputText value="Display DropDown Values" />
        <h:selectOneMenu value="#{nonLocationSpecificBackingBean.testing}">
            <f:selectItem itemValue="03 R  MAIN1"/>
        </h:selectOneMenu>
        <a4j:commandButton value="Save" action="#{nonLocationSpecificBackingBean.test}" reRender="err_succ_message,TEST"></a4j:commandButton>
        <a4j:commandButton value="Test"  reRender="TEST"></a4j:commandButton>
    </a4j:outputPanel>
</a4j:form>

Please help on this. Thanks

Andreas Fester
  • 36,091
  • 7
  • 95
  • 123
  • This could be related to how multiple spaces in html are rendered - see http://stackoverflow.com/questions/4503001/multiple-spaces-between-words-in-html-without-nbsp – Andreas Fester Apr 19 '13 at 10:17

1 Answers1

0

It is related to how multiple spaces are treated in HTML. However in your case, I don't think a css trick is the answer (as suggested in the linked question).

I think a good solution would be to use HTML encoded values in the form, and decode them in your server component.

Update: Likely implementation in a converter will look like this (Added code here instead of the comment, because of formatting issues :))

public Object getAsObject(FacesContext arg0, UIComponent arg1, String newValue) {
    return (Object) newValue.replaceAll("&nbsp;", " ");
}

public String getAsString(FacesContext arg0, UIComponent arg1, Object value) { 
    return value.toString().replaceAll(" ", "&nbsp;"); 
}
Akshay
  • 3,158
  • 24
  • 28
  • Thanks Akshay. I tried with decoding and encoding using converter. Please see the code below: – Radhamani Muthusamy Apr 22 '13 at 09:43
  • Converter code FacesConverter("SpaceConverter") public class SpaceConverter implements Converter{ Override public Object getAsObject(FacesContext arg0, UIComponent arg1, String newValue) { return (Object)newValue.replace(" ", "_");} Override public String getAsString(FacesContext arg0, UIComponent arg1, Object value) { return value.toString().replace(" ", "_"); } } xhtml code: – Radhamani Muthusamy Apr 22 '13 at 09:48
  • Please take a look at the code added to the answer, hope this helps. I couldn't test it because I don't have a suitable project configured right now. – Akshay Apr 22 '13 at 10:14