0

我再次需要你的帮助!

我有任务:我需要在 .xhtml 页面中预览 html 页面。我的 html 页面使用 flash 图表,所以我需要能够显示带有其他内容的 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

javax.faces.FacesException:在 org.ajax4jsf.resource.ResourceBuilderImpl.decrypt 解码资源数据时出错(ResourceBuilderImpl.java:627)

严重:Servlet Faces Servlet 的 Servlet.service() 抛出异常 org.ajax4jsf.resource.ResourceNotFoundException:资源未注册:org.ajax4jsf.resource.UserResource/c/n/-1082243251/css/stylesheet.css

4

1 回答 1

-1

使用 Apache wicket Web 框架来预览和开发您的页面

于 2011-01-06T09:59:50.327 回答