3 Replies Latest reply on Jun 27, 2007 6:03 PM by davidfed

    Decorating with a fileUpload tag

    davidfed

      --Seam 1.2.1 standard setup--

      I have this page source:

      <s:decorate id="uploadDecor_#{idx}" template="/WEB-INF/template/edit.txml">
       <ui:define name="label">
       #{messages.attachFileLabelFile}
       </ui:define>
       <ui:define name="guidance">
       #{messages.attachFileGuidanceFile}
       </ui:define>
       <s:fileUpload id="upload_#{idx}" data="#{doc.fileData}"
       fileName="#{doc.fileName}"
       contentType="#{doc.contentType}"/>
      </s:decorate>
      


      with this template:

      <s:div styleClass="prop #{invalid?'errors':''}">
       <s:label styleClass="name">
       <ui:insert name="label"/>
       </s:label>
      
       <s:span styleClass="value">
       <ui:insert/>
       </s:span>
      
       <s:message styleClass="error errors"/>
      
       <s:span styleClass="guidance">
       <s:fragment rendered="#{invalid}">
       <s:message/>
       <br/>
       </s:fragment>
       <ui:insert name="guidance"/>
       </s:span>
      </s:div>
      


      And I get these complaints in the console:

      18:59:50,935 WARN [HtmlLabelRenderer] Attribute 'for' of label component with id attachFile:_id75 is not defined
      18:59:51,935 ERROR [HtmlMessageRendererBase] Attribute 'for' of UIMessage must not be null
      


      When I break into HtmlMessageDecoration.getInputId() I see that it walks through the subtree of the decorate tag looking for an EditableValueHolder subclass to get the id to insert in the 'for' tag. It doesn't think the fileUpload qualifies and doesn't set a 'for' attribute. HtmlLabelDecoration has the same problem.

      The result is that clicking on the label doesn't focus the input field and the field specific error messages don't show up.

      Is there an easy way to solve this?

        • 1. Re: Decorating with a fileUpload tag
          utiba_davidr

          Hey,

          You need to set the "for" parameter to the id of the field that the label is for. In this case it's "upload_#{idx}". You should be able to pass this to the template your decorating via a parameter (see the facelets documentation). I am not entirely sure whether decorate can take parameters, if it cannot - you may be better using a composition / insert combination.



          Cheers,

          David

          • 2. Re: Decorating with a fileUpload tag
            pmuir

            Most id parameters in JSF can't take EL.

            • 3. Re: Decorating with a fileUpload tag
              davidfed

              I should have mentioned that I do not get any complaints from equivalent decorate structures that have inputText and selectOneMenu as the editable value. The "for" attributes are set correctly. And I saw in another topic that this problem is fixed in seam 2.0 as fileUpload has been made an EditableValueHolder and thus the id will be set. So when I'm allowed to move to Seam 2.0 this won't be a problem.

              The EL works fine. I'm setting #{idx} with:

              <ui:param name="idx" value="0"/>
              


              I had to unroll a loop and this simplifies the copy/paste when I adjust something.