2 Replies Latest reply on Sep 19, 2011 10:21 AM by cdesserich

    Label Whitespace Disapears on Re-render

    cdesserich

      For some reason, h:outputLabel's (and s:label's) render the text with a leading space. Unfortunately on an AJAX re-render, the space is stripped. I understand why the space is be stripped, but I'm not sure why it is there in the first place. This makes for a very annoying label-move when the re-render completes. Does anyone have any advice about how to fix this or how to work around it? I have tried using JQuery to add the space back in the oncomplete method, but there is still a delayed flash when doing that. Below is sample code you can use to observe the behavior (watch the label text move left on re-render). I've tried wrapping an h:outputText inside the label tag as well, but it seams that it still adds the leading space. The first-time rendered html is still


      <label id="form:decorate:label" for="form:decorate:checkbox"> label</label>


      and is still re-rendered as


      <label id="form:decorate:label" for="form:decorate:checkbox">label</label>.


      (Seam 2.1.2, JBoss AS 5)


      <html xmlns="http://www.w3.org/1999/xhtml"
            xmlns:ui="http://java.sun.com/jsf/facelets"
            xmlns:h="http://java.sun.com/jsf/html"
            xmlns:f="http://java.sun.com/jsf/core"
            xmlns:s="http://jboss.com/products/seam/taglib"
            xmlns:rich="http://richfaces.org/rich"
            xmlns:a="http://richfaces.org/a4j">
            
           <head>
               <title>WhitespaceTest</title>
           </head>
           
           <body>
                <h:form id="form">
                     <s:decorate id="decorate">
                          <h:selectBooleanCheckbox id="checkbox" value="true" />
                          <h:outputLabel id="label" for="checkbox" value="label" />
                     </s:decorate>
                     
                     <a:commandLink id="commandLink" value="commandLink" reRender="decorate" />
                </h:form>
           </body>
      </html>



        • 1. Re: Label Whitespace Disapears on Re-render
          kragoth

          Every example for s:decorate I have seen uses a template. So...that's what I did and it seems to work.


          Try doing this. NOTE carefully how the label is defined now


          <html xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:s="http://jboss.com/products/seam/taglib"
                xmlns:rich="http://richfaces.org/rich"
                xmlns:a="http://richfaces.org/a4j">
                
               <head>
                   <title>WhitespaceTest</title>
               </head>
               
               <body>
                    <h:form id="form">
                         <s:decorate id="decorate" template="edit.xhtml">
                              <h:selectBooleanCheckbox id="checkbox" value="#{true}" />
                              <ui:define name="label">label</ui:define>
                         </s:decorate>
                         
                         <a:commandLink id="commandLink" value="commandLink" reRender="decorate" />
                    </h:form>
               </body>
          </html>
          



          And use this template file.


          <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                    xmlns:ui="http://java.sun.com/jsf/facelets"
                    xmlns:h="http://java.sun.com/jsf/html"
                    xmlns:f="http://java.sun.com/jsf/core"
                    xmlns:s="http://jboss.com/products/seam/taglib">
               <div>
                    <span>
                         <ui:insert/>
                    </span>
                    <s:label>
                         <ui:insert name="label"/>
                    </s:label>
               </div>
          </ui:composition>
          



          Ultimately I have no idea why it behaves the way it does. But....this should do. :)

          • 2. Re: Label Whitespace Disapears on Re-render
            cdesserich

            Sorry it took me this long to respond. The team I'm working on is coming up to a deadline so I haven't had a chance to try the workaround out. I did read something about how facelets alters the component tree (possibly in unwanted ways) somewhere, but I can't remember where and I'm not sure I would have understood anyway. It's just a thought that if facelets was maybe generating markup that JSF wasn't altering, that that may be why this works, but of course I don't know that for sure...


            Anyway thanks for the workaround. I will try and see if it will work to make my project more consistent, I just can't get to it at this point. If and when I do, I'll try and post again with my success/failure.