6 Replies Latest reply on Jan 25, 2013 5:34 AM by Thomas Jodes

    Facelets a4j:mediaOutput error

    nksaran Newbie

      I am using the code from the demosite. I have add fileupload code to a facelets component so that I can use the file uploader in multiple places. If I declare FileUploaderBean as Array or List in my bean (AdminBean which is in Session scope), then a4j:mediaOutput throws follwing error after upload is done successfuly and when its time to call the paint method to show the uploaded file. If I dont declare FileUploadBean as Array or List, then everthing works fine.

       

      javax.el.PropertyNotFoundException: /WEB-INF/facelets/components/fileUploadMini.xhtml @27,88 createContent="#{fu.paint}": Target Unreachable, identifier 'fu' resolved to null

          at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:107)

          at org.richfaces.resource.MediaOutputResource.encode(MediaOutputResource.java:62)

          at org.richfaces.resource.UserResourceWrapperImpl.encode(UserResourceWrapperImpl.java:188)

          at org.richfaces.resource.ResourceHandlerImpl.handleResourceRequest(ResourceHandlerImpl.java:222)

          at javax.faces.application.ResourceHandlerWrapper.handleResourceRequest(ResourceHandlerWrapper.java:125)

          at org.apache.myfaces.custom.captcha.CAPTCHAResourceHandlerWrapper.handleResourceRequest(CAPTCHAResourceHandlerWrapper.java:208)

          at javax.faces.application.ResourceHandlerWrapper.handleResourceRequest(ResourceHandlerWrapper.java:125)

          at javax.faces.webapp.FacesServlet.service(FacesServlet.java:310)

          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)

          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

          at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:112)

          at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)

          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

          at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)

          at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)

          at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)

          at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

          at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

          at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)

          at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)

          at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)

          at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)

          at java.lang.Thread.run(Thread.java:662)

       

      Here is the Fie Upload Facelets Component (fileUploadMini.xhtml):

       

      <ui:composition>

      <a4j:region>

           <h:panelGrid id="#{idPrefix}fileUploadPG" cellpadding="0" cellspacing="0">

                  <rich:fileUpload fileUploadListener="#{fu.addListener}" autoclear="true" maxFilesQuantity="#{fu.uploadsAvailable}" immediateUpload="#{fu.autoUpload}" acceptedTypes="jpg, gif, png, bmp" allowFlash="#{fu.useFlash}" noDuplicate="true"                       addLabel="Add Image">

                      <a4j:ajax event="uploadcomplete" render="#{idPrefix}info" />

                  </rich:fileUpload>

                  <h:panelGroup id="#{idPrefix}info">

                          <h:outputText value="No files currently uploaded" rendered="#{fu.size==0 and showNoFileUploadedText}" />

                          <rich:dataGrid value="#{fu.files}"  var="file" rowKeyVar="row">

                                  <h:panelGrid styleClass="alignCenter" columns="2" cellpadding="0" cellspacing="0">

                                      <a4j:mediaOutput element="img" mimeType="#{file.mime}" createContent="#{fu.paint}" value="#{row}" style="width:50px; height:50px;" cacheable="false">

                                          <f:param value="#{fu.timeStamp}" name="time"/> 

                                       </a4j:mediaOutput><br/>

                                       <a4j:commandLink value="Delete Image" action="#{fu.removeListener}" render="#{idPrefix}fileUploadPG">

                                              <f:param value="#{row}" name="fileToBeRemovedRowNo"></f:param>

                                          </a4j:commandLink>

                                </h:panelGrid>

                          </rich:dataGrid>

              </h:panelGroup>

          </h:panelGrid>

      </a4j:region>

      </ui:composition>

       

       

      If it helps following are the versions I am using:

       

      JDK1.6.0_23-b05

      richfaces-4.1.0.Final

       

      Can someone please help?

        • 1. Re: Facelets a4j:mediaOutput error
          nksaran Newbie

          Ok, created simplified page and bean to test this scenario and following are the code and details:

           

          Java Bean:

          package com.test.bean;

           

          import java.util.ArrayList;

          import java.util.List;

          import javax.faces.bean.ManagedBean;

          import javax.faces.bean.SessionScoped;

          import com.test.fileupload.FileUploader;

           

          @ManagedBean(name = "TestBean")

          @SessionScoped

          public class TestBean {

              private List<FileUploader> fileUploaders;

              public TestBean(){

                  fileUploaders = new ArrayList<FileUploader>();

                  fileUploaders.add(new FileUploader());

                  fileUploaders.add(new FileUploader());

                  fileUploaders.add(new FileUploader());

                  fileUploaders.add(new FileUploader());

              }

             

              public List<FileUploader> getFileUploaders() {

                  return fileUploaders;

              }

             

              public void setFileUploaders(List<FileUploader> fileUploaders) {

                  this.fileUploaders = fileUploaders;

              }

             

          }

           

          home1.xhtml page which iterates all the fileuploader in the page:

          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

          <html xmlns="http://www.w3.org/1999/xhtml"

              xmlns:h="http://java.sun.com/jsf/html"

              xmlns:f="http://java.sun.com/jsf/core"

              xmlns:t="http://myfaces.apache.org/tomahawk"

              xmlns:ui="http://java.sun.com/jsf/facelets"

              xmlns:rich="http://richfaces.org/rich"

              xmlns:a4j="http://richfaces.org/a4j"

              xmlns:custom="http://www.test123.com/jsf"

              xmlns:c="http://java.sun.com/jsp/jstl/core">

          <ui:composition>

          <f:view>

          <h:head>

          <title><ui:insert name="title"/></title>

          </h:head>

          <body>

          <h:form>

           

          <h:dataTable value="#{TestBean.fileUploaders}" var="fileUpLoader">

          <h:column>

          <custom:fileUploadMini fu="#{fileUpLoader}" idPrefix="u" showNoFileUploadedText="false" />

          </h:column>

          </h:dataTable>

           

          </h:form>

          </body>

          </f:view>

          </ui:composition>

          </html>

           

          Here is the Fie Upload Facelets Component (fileUploadMini.xhtml):

           

          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

          <html xmlns="http://www.w3.org/1999/xhtml"

              xmlns:h="http://java.sun.com/jsf/html"

              xmlns:f="http://java.sun.com/jsf/core"

              xmlns:t="http://myfaces.apache.org/tomahawk"

              xmlns:ui="http://java.sun.com/jsf/facelets"

              xmlns:rich="http://richfaces.org/rich"

              xmlns:a4j="http://richfaces.org/a4j">

          <ui:composition>

          <a4j:region>

               <h:panelGrid id="#{idPrefix}fileUploadPG" cellpadding="0" cellspacing="0">

                      <rich:fileUpload fileUploadListener="#{fu.addListener}" autoclear="true" maxFilesQuantity="#{fu.uploadsAvailable}" immediateUpload="#{fu.autoUpload}" acceptedTypes="jpg, gif, png, bmp" allowFlash="#{fu.useFlash}" noDuplicate="true"                       addLabel="Add Image">

                          <a4j:ajax event="uploadcomplete" render="#{idPrefix}info" />

                      </rich:fileUpload>

                      <h:panelGroup id="#{idPrefix}info">

                              <h:outputText value="No files currently uploaded" rendered="#{fu.size==0 and showNoFileUploadedText}" />

                              <rich:dataGrid value="#{fu.files}"  var="file" rowKeyVar="row">

                                      <h:panelGrid styleClass="alignCenter" columns="2" cellpadding="0" cellspacing="0">

                                          <a4j:mediaOutput element="img" mimeType="#{file.mime}" createContent="#{fu.paint}" value="#{row}" style="width:50px; height:50px;" cacheable="false">

                                              <f:param value="#{fu.timeStamp}" name="time"/> 

                                           </a4j:mediaOutput><br/>

                                           <a4j:commandLink value="Delete Image" action="#{fu.removeListener}" render="#{idPrefix}fileUploadPG">

                                                  <f:param value="#{row}" name="fileToBeRemovedRowNo"></f:param>

                                              </a4j:commandLink>

                                    </h:panelGrid>

                              </rich:dataGrid>

                  </h:panelGroup>

              </h:panelGrid>

          </a4j:region>

          </ui:composition>

           

           

          When I upload a file, fu.addListener is called and I see the file is uploaded. once its uploaded "uploadcomplete" event is fired (in  this case it reRender 'info') to show the uploaded  image in the UI and now it throws the fllowing exception.

           

          javax.el.PropertyNotFoundException: /WEB-INF/facelets/components/fileUploadMini.xhtml @27,88 createContent="#{fu.paint}": Target Unreachable, identifier 'fu' resolved to null

              at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:107)

              at org.richfaces.resource.MediaOutputResource.encode(MediaOutputResource.java:62)

              at org.richfaces.resource.UserResourceWrapperImpl.encode(UserResourceWrapperImpl.java:188)

              at org.richfaces.resource.ResourceHandlerImpl.handleResourceRequest(ResourceHandlerImpl.java:222)

              at javax.faces.application.ResourceHandlerWrapper.handleResourceRequest(ResourceHandlerWrapper.java:125)

              at org.apache.myfaces.custom.captcha.CAPTCHAResourceHandlerWrapper.handleResourceRequest(CAPTCHAResourceHandlerWrapper.java:208)

              at javax.faces.application.ResourceHandlerWrapper.handleResourceRequest(ResourceHandlerWrapper.java:125)

              at javax.faces.webapp.FacesServlet.service(FacesServlet.java:310)

              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)

              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

              at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:112)

              at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)

              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

              at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)

              at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)

              at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)

              at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

              at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

              at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)

              at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)

              at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)

              at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)

              at java.lang.Thread.run(Thread.java:662)

          • 2. Re: Facelets a4j:mediaOutput error
            iabughosh Master

            hello nksaran,

            as exception describes, this exception occures because your page didn't pass the value to your composite page correctly, thus this null reference (PropertyNotFoundException) occures, your composite page is not constructed right, there is no <composite:interface> and <composite:implementation> attributes, no composite:interface means that your composite component doesn't accept any attribute, please reference these:

            1-http://www.ibm.com/developerworks/java/library/j-jsf2fu0111/index.html?ca=drs-

            2-Core JavaServerFaces 3rd edition book chapter 9.

             

            regards.

            • 3. Re: Facelets a4j:mediaOutput error
              nksaran Newbie

              Thanks for your quick response. As you mentioned I converted the component using <composite:interface> and <composite:implementation> and still facing the same problem (this time it reports cc as null). Please note that the file upload goes through successfully (I can see the file uploaded in the server), but when <a4j:mediaOutput> tries to paint, it sees cc as null. Is this something to do with <a4j:mediaOutput' createContent attribute issue? follwing are the code and details:

               

              Java Bean:

              package com.test.bean;

               

              import java.util.ArrayList;

              import java.util.List;

              import javax.faces.bean.ManagedBean;

              import javax.faces.bean.SessionScoped;

              import com.test.fileupload.FileUploader;

               

              @ManagedBean(name = "TestBean")

              @SessionScoped

              public class TestBean {

                  private List<FileUploader> fileUploaders;

                  public TestBean(){

                      fileUploaders = new ArrayList<FileUploader>();

                      fileUploaders.add(new FileUploader());

                      fileUploaders.add(new FileUploader());

                      fileUploaders.add(new FileUploader());

                      fileUploaders.add(new FileUploader());

                  }

                 

                  public List<FileUploader> getFileUploaders() {

                      return fileUploaders;

                  }

                 

                  public void setFileUploaders(List<FileUploader> fileUploaders) {

                      this.fileUploaders = fileUploaders;

                  }

                 

              }

               

               

              home2.xhtml page which iterates all the fileuploader in the page:

               

              <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

              <html xmlns="http://www.w3.org/1999/xhtml"

                  xmlns:h="http://java.sun.com/jsf/html"

                  xmlns:f="http://java.sun.com/jsf/core"

                  xmlns:t="http://myfaces.apache.org/tomahawk"

                  xmlns:ui="http://java.sun.com/jsf/facelets"

                  xmlns:rich="http://richfaces.org/rich"

                  xmlns:a4j="http://richfaces.org/a4j"

                  xmlns:c="http://java.sun.com/jsp/jstl/core"

                  xmlns:comp="http://java.sun.com/jsf/composite/facelets/components">

              <ui:composition>

              <h:head>

              <title><ui:insert name="title"/></title>

               

              </h:head>

              <h:body>

              <h:form>

               

              <h:dataTable value="#{TestBean.fileUploaders}" var="fileUpLoader">

              <h:column>

              <comp:fileUploadMinimum fu="#{fileUpLoader}" idPrefix="u" showNoFileUploadedText="false" />

              </h:column>

              </h:dataTable>

              </h:form>

              </h:body>

               

              </ui:composition>

              </html>

               

              Here is the Fie Upload Facelets Component (fileUploadMini.xhtml):

              <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

              <html xmlns="http://www.w3.org/1999/xhtml"

                  xmlns:h="http://java.sun.com/jsf/html"

                  xmlns:f="http://java.sun.com/jsf/core"

                  xmlns:t="http://myfaces.apache.org/tomahawk"

                  xmlns:ui="http://java.sun.com/jsf/facelets"

                  xmlns:rich="http://richfaces.org/rich"

                  xmlns:a4j="http://richfaces.org/a4j"

                  xmlns:composite="http://java.sun.com/jsf/composite">

               

               

              <!-- INTERFACE -->

                <composite:interface>

                  <composite:attribute name="idPrefix"/>

                  <composite:attribute name="fu"/>

                  <composite:attribute name="showNoFileUploadedText"/>

                </composite:interface>

               

               

              <!-- IMPLEMENTATION -->         

                  <composite:implementation>

                   <a4j:region>

                      <h:panelGrid id="#{cc.attrs.idPrefix}fileUploadPG" cellpadding="0" cellspacing="0">

                          <rich:fileUpload fileUploadListener="#{cc.attrs.fu.addListener}" autoclear="true"

                              maxFilesQuantity="#{cc.attrs.fu.uploadsAvailable}"

                              immediateUpload="#{cc.attrs.fu.autoUpload}"

                              acceptedTypes="jpg, gif, png, bmp" allowFlash="#{cc.attrs.fu.useFlash}" noDuplicate="true" addLabel="Add Image">

                              <a4j:ajax event="uploadcomplete" render="#{cc.attrs.idPrefix}info" />

                          </rich:fileUpload>

                          <h:panelGroup id="#{cc.attrs.idPrefix}info">

                                  <h:outputText value="No files currently uploaded"

                                      rendered="#{cc.attrs.fu.size==0 and showNoFileUploadedText}" />

                                  <rich:dataGrid value="#{cc.attrs.fu.files}"

                                      var="file" rowKeyVar="row">

                                          <h:panelGrid styleClass="alignCenter" columns="2" cellpadding="0" cellspacing="0">

                                              <a4j:mediaOutput element="img" mimeType="#{file.mime}"

                                                  createContent="#{cc.attrs.fu.paint}" value="#{row}"

                                                  style="width:50px; height:50px;" cacheable="false">

                                                  <f:param value="#{cc.attrs.fu.timeStamp}" name="time"/> 

                                              </a4j:mediaOutput><br/>

                                                  <a4j:commandLink value="Delete Image" action="#{cc.attrs.fu.removeListener}" render="#{cc.attrs.idPrefix}fileUploadPG">

                                                      <f:param value="#{row}" name="fileToBeRemovedRowNo"></f:param>

                                                  </a4j:commandLink>

                                          </h:panelGrid>

                                  </rich:dataGrid>

                          </h:panelGroup>

                      </h:panelGrid>

                     

                  </a4j:region>

                </composite:implementation>

               

               

              </html>

               

              When I upload a file, fu.addListener is called and I see the file is uploaded successfully. once its uploaded "uploadcomplete" event is fired (in  this case it reRender 'info') to show the uploaded  image in the UI and now it throws the fllowing exception.

               

              javax.el.PropertyNotFoundException: //C:/myinstall/apache-tomcat-6.0.30/webapps/recipe/WEB-INF/classes/META-INF/resources/facelets/components/fileUploadMinimum.xhtml @38,88 createContent="#{cc.attrs.fu.paint}": Target Unreachable, identifier 'cc' resolved to null

                  at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:107)

                  at com.sun.faces.facelets.el.ContextualCompositeMethodExpression.invoke(ContextualCompositeMethodExpression.java:171)

                  at org.richfaces.resource.MediaOutputResource.encode(MediaOutputResource.java:62)

                  at org.richfaces.resource.UserResourceWrapperImpl.encode(UserResourceWrapperImpl.java:188)

                  at org.richfaces.resource.ResourceHandlerImpl.handleResourceRequest(ResourceHandlerImpl.java:222)

                  at javax.faces.application.ResourceHandlerWrapper.handleResourceRequest(ResourceHandlerWrapper.java:125)

                  at org.apache.myfaces.custom.captcha.CAPTCHAResourceHandlerWrapper.handleResourceRequest(CAPTCHAResourceHandlerWrapper.java:208)

                  at javax.faces.application.ResourceHandlerWrapper.handleResourceRequest(ResourceHandlerWrapper.java:125)

                  at javax.faces.webapp.FacesServlet.service(FacesServlet.java:310)

                  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)

                  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

                  at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:112)

                  at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)

                  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

                  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

                  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)

                  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)

                  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)

                  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

                  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

                  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)

                  at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)

                  at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)

                  at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)

                  at java.lang.Thread.run(Thread.java:662)

              • 4. Re: Facelets a4j:mediaOutput error
                nksaran Newbie

                Can someone please help... Is this a4j:mediaOutput component issue?

                • 5. Re: Facelets a4j:mediaOutput error
                  nksaran Newbie

                  Help... Help...!

                  • 6. Re: Facelets a4j:mediaOutput error
                    Thomas Jodes Newbie

                    I'm experiencing the same issue when using the a4j:mediaOutput in a composite component. cc resolved to null.

                    Painting the preview images, you could do a workaround creating a global utiltiy class that implements the paint(OutputStream, Object) - callback. Switch mediaOutput's value attribute to "file" (not "row") since you directly cannot get a reference to the uploaded files in this case.