もう一度あなたの助けが必要です!
タスクがあります: .xhtml ページで html ページをプレビューする必要があります。私の html ページはフラッシュ チャートを使用しているため、他のコンテンツでフラッシュを表示できる必要があります。また、このプレビューは元のページよりも小さくする必要があります。
私はそれをやろうとしています:テキストは見えましたが、フラッシュと画像のコンテンツは見えませんでした。誰かが言うことができます - どこに問題がありますか? そして、多分私はそれを別の方法で行う必要がありますか?
ここにいくつかのコードがあります:
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) でのリソース データのデコード エラー
SEVERE: サーブレット Faces サーブレットの Servlet.service() が例外 org.ajax4jsf.resource.ResourceNotFoundException をスローしました: リソースが登録されていません: org.ajax4jsf.resource.UserResource/c/n/-1082243251/css/stylesheet.css