2010-06-14 86 views
0

我再次需要你的幫助!如何使用richfaces預覽html頁面?

我有任務:我需要在.xhtml頁面預覽html頁面。我的html頁面使用flash圖表,所以我需要能夠與其他內容一起顯示flash。此預覽也必須小於原始頁面。

我嘗試這樣做:我可以看到文字,但沒有閃光燈和圖像內容。有人可以說 - 問題在哪裏?也許我需要以另一種方式做到這一點?

下面是一些代碼:

package no.sfront.clientadmin; 

    /** 
    * @author Elena Veretilo 
    * 
    */ 

    import java.io.IOException; 
    import java.io.OutputStream; 
    import java.util.ArrayList; 

    import javax.faces.context.FacesContext; 

    import org.richfaces.event.UploadEvent; 
    import org.richfaces.model.UploadItem; 

    public class HtmlFileUpload 
    { 
     private ArrayList<HtmlFile> files = new ArrayList<HtmlFile>(); 
     private int uploadsAvailable = 1; 
     private boolean autoUpload = true; 
     private boolean useFlash = true; 


     public static HtmlFileUpload getInstance() { 
      FacesContext facesContext = FacesContext.getCurrentInstance(); 

      return (HtmlFileUpload) facesContext.getApplication().getELResolver() 
        .getValue(facesContext.getELContext(), null, "htmlFileUpload"); 
     } 

     public HtmlFileUpload() { 
     } 

     public void paint(OutputStream stream, Object object) throws IOException { 
      stream.write(getFiles().get((Integer)object).getData()); 
     } 

     public void listener(UploadEvent event) throws Exception{ 
      UploadItem item = event.getUploadItem(); 
      HtmlFile file = new HtmlFile(); 
      byte[] array = item.getData(); 
      file.setLength(array.length); 
      file.setName(item.getFileName()); 
      file.setData(item.getData()); 
      files.add(file); 
      uploadsAvailable--; 
     } 

     public String clearUploadData() { 
      files.clear(); 
      setUploadsAvailable(1); 
      return null; 
     } 

     public int getSize() { 
      if (getFiles().size() > 0) 
       return getFiles().size(); 
      else 
       return 0; 
     } 

     public long getTimeStamp(){ 
      return System.currentTimeMillis(); 
     } 

     public ArrayList<HtmlFile> getFiles() { 
      return files; 
     } 

     public void setFiles(ArrayList<HtmlFile> files) { 
      this.files = files; 
     } 

     public int getUploadsAvailable() { 
      return uploadsAvailable; 
     } 

     public void setUploadsAvailable(int uploadsAvailable) { 
      this.uploadsAvailable = uploadsAvailable; 
     } 

     public boolean isAutoUpload() { 
      return autoUpload; 
     } 

     public void setAutoUpload(boolean autoUpload) { 
      this.autoUpload = autoUpload; 
     } 

     public boolean isUseFlash() { 
      return useFlash; 
     } 

     public void setUseFlash(boolean useFlash) { 
      this.useFlash = useFlash; 
     } 

    } 




public void setName(String name) { 
    Name = name; 
    int extDot = name.lastIndexOf('.'); 
    if(extDot > 0){ 
     String extension = name.substring(extDot +1); 
     if("html".equals(extension)){ 
      mime = "text/html";//"multipart/related";//"text/html"; 
     } else if("mht".equals(extension)){ 
      mime = "text/html";//"multipart/related";//"text/html"; 
     } else if("xhtml".equals(extension)){ 
      mime = "application/xhtml+xml"; 
     } else { 
      mime = "application/x-shockwave-flash"; 
     } 
    } 
} 






     <ui:composition xmlns="http://www.w3.org/1999/xhtml" 
      xmlns:ui="http://java.sun.com/jsf/facelets" 
      xmlns:a4j="http://richfaces.org/a4j" 
      xmlns:rich="http://richfaces.org/rich" 
      xmlns:h="http://java.sun.com/jsf/html" 
      xmlns:f="http://java.sun.com/jsf/core" 
      xmlns:fc="http://www.fusioncharts.com" 
      xmlns:t="http://myfaces.apache.org/tomahawk" 
      template="template.xhtml"> 
<ui:define name="title">Client Admin Page</ui:define> 
<ui:define name="content"> 

     <style> 
      .top { 
       vertical-align: top; 

      } 
      .info { 
       height: 100%; 
       overflow: auto; 
      } 
     </style> 

    <h:form> 
     <h:panelGrid columns="1" rows="2" columnClasses="top,top"> 
      <rich:fileUpload fileUploadListener="#{htmlFileUpload.listener}" 
       maxFilesQuantity="#{htmlFileUpload.uploadsAvailable}" 
       id="upload" 
       immediateUpload="#{htmlFileUpload.autoUpload}" 
       acceptedTypes="html,xhtml,mht" allowFlash="#{htmlFileUpload.useFlash}" 
       listHeight="70px"> 
       <a4j:support event="onuploadcomplete" reRender="info" /> 
       <a4j:support event="onclear" reRender="upload,info" action="#{htmlFileUpload.clearUploadData}"/> 
      </rich:fileUpload> 
      <h:panelGroup id="info"> 
       <rich:panel bodyClass="info"> 
        <f:facet name="header"> 
         <h:outputText value="Uploaded Files Info" /> 
        </f:facet> 
        <h:outputText value="No files currently uploaded" 
         rendered="#{htmlFileUpload.size==0}" /> 
        <rich:dataGrid columns="1" value="#{htmlFileUpload.files}" 
         var="file" rowKeyVar="row"> 
         <rich:panel> 
          <h:panelGrid columns="1"> 
           <a4j:mediaOutput element="object" mimeType="#{file.mime}" 
            createContent="#{htmlFileUpload.paint}" 
            value="#{row}" cacheable="true"> 
            <f:param value="#{htmlFileUpload.timeStamp}" name="time"/> 
           </a4j:mediaOutput> 
          </h:panelGrid> 
         </rich:panel> 
        </rich:dataGrid> 
       </rich:panel> 
       <rich:spacer height="2"/> 
       <br/> 
       <a4j:commandButton action="#{htmlFileUpload.clearUploadData}" 
        reRender="info, upload" value="Clear Uploaded Data" 
        rendered="#{htmlFileUpload.size>0}" /> 
      </h:panelGroup> 
     </h:panelGrid> 
    </h:form> 


</ui:define> 
<ui:define name="return" /> 

當我使用MIME類型爲 「text/html的」 - 我只能看到文字和其他內容(圖片,SWF)我得到下一個例外:

org.ajax4jsf.resource.ResourceNotFoundException:資源未註冊:org.ajax4jsf.resource.UserResource/C/N/-1082243251/FusionCharts的/ AngularGauge.swf

JA vax.faces.FacesException:錯誤解碼資源數據 在org.ajax4jsf.resource.ResourceBuilderImpl.decrypt(ResourceBuilderImpl.java:627)

重度:Servlet.service()進行的servlet面臨的Servlet拋出異常 org.ajax4jsf。 resource.ResourceNotFoundException:資源未註冊:org.ajax4jsf.resource.UserResource/C/N/-1082243251/CSS/stylesheet.css中

回答

-1

使用Apache檢票Web框架預覽和發展你的網頁