如何使用richfaces预览html页面?

发布于 2024-09-06 01:39:25 字数 7124 浏览 2 评论 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

I need your help once more!

I have the task: I need to preview the html pages in .xhtml page. My html pages use flash charts, so I need to be able to show flash with other content. Also this previews must be smaller than the original page.

I try to do it with : I could see the text, but no flash and image content. Could somebody say - where is the problem? And maybe I need to do it in another way?

Here is some code:

    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" />

When I use mime type "text/html" - I could see only text and for other content (images, swf ) I get next exceptions:

org.ajax4jsf.resource.ResourceNotFoundException: Resource not registered : org.ajax4jsf.resource.UserResource/c/n/-1082243251/FusionCharts/AngularGauge.swf

javax.faces.FacesException: Error decode resource data
at org.ajax4jsf.resource.ResourceBuilderImpl.decrypt(ResourceBuilderImpl.java:627)

SEVERE: Servlet.service() for servlet Faces Servlet threw exception
org.ajax4jsf.resource.ResourceNotFoundException: Resource not registered : org.ajax4jsf.resource.UserResource/c/n/-1082243251/css/stylesheet.css

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墨落成白 2024-09-13 01:39:25

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

Use Apache wicket web framework to preview and develop your pages

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文