Verifiquei a pagina de debug e tem uma conversação de id 4 que tem o meu componente fileUploadBean
porem qdo chamo o outro metodo na pagina que esta anotado com @End ele chama o construtor do bean
e zera tudo, ai minhas variaveis de instancia que preciso para concluir a tarefa sempre esta nulas,
o que sera que esta ocorrendo?
vou postar td meu codigo aki:
ManagedBean:
@SuppressWarnings("serial")
@Name(value = "fileUploadBean")
@Scope(ScopeType.CONVERSATION)
public class FileUploadBean implements Serializable {
private br.com.sanepar.sns.imageUploadUtils.File file = new br.com.sanepar.sns.imageUploadUtils.File();;
private UploadItem anexo;
@In
private FacesMessages facesMessages;
private static final String UPLOAD_FOLDER = "anexos";
private byte[] fileByte;
private String localName;
public FileUploadBean() {
System.out.println("Bean created.");
}
public void paint(OutputStream stream, Object object) throws IOException {
if (file.getData() != null) {
stream.write(file.getData());
}
}
@Begin
public void listener(UploadEvent event) throws Exception {
UploadItem item = event.getUploadItem();
file.setLength(item.getData().length);
file.setName(item.getFileName());
file.setData(item.getData());
this.anexo = event.getUploadItem();
salvarAnexos();
}
public Boolean salvarAnexos() {
File uploadedFile = null;
if (this.anexo != null && this.anexo.getData() != null) {
try {
uploadedFile = AnexosUtils.saveLocalAnexo(this.anexo.getData(),
UPLOAD_FOLDER);
} catch (Exception e) {
facesMessages
.add("Ocorreu um erro e não foi possível enviar o arquivo em anexo.",
Severity.ERROR);
e.printStackTrace();
return false;
}
Anexo anexoE = new Anexo();
// nome do arquivo
String nomeArquivo = AnexosUtils.extractFileName(this.anexo
.getFileName());
anexoE.setNomeDoArquivo(nomeArquivo);
// nome do arquivo
AnexosUtils.saveFile(uploadedFile, anexoE, UPLOAD_FOLDER);
}
return true;
}
minha pagina xhtml:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:s="http://jboss.com/products/seam/taglib"
template="/pages/default.xhtml">
<ui:define name="conteudo">
<h:form>
<rich:editor value="#{imageBean.editorValue}" theme="advanced"
onsetup="ed.addButton('mybutton', {title : 'My button',
image : 'http://localhost:8080/SnsWeb/images/barra_home.gif',
onclick : function() {
Richfaces.showModalPanel('uploadPanel')
}
})
"
viewMode="tinyMCE"
plugins="layer,table,advhr,advlink,advimage,iespell,inlinepopups,insertdatetime,preview,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,pagebreak">
<f:param name="theme_advanced_buttons1"
value="mybutton,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,fontselect,fontsizeselect" />
<f:param name="theme_advanced_buttons2"
value="cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor" />
<f:param name="theme_advanced_buttons3"
value="tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,advhr,|,print,|,ltr,rtl,|,fullscreen" />
<f:param name="theme_advanced_buttons4"
value="insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,pagebreak" />
<f:param name="file_browser_callback" value="myFileBrowser2" />
<f:param name="theme_advanced_font_sizes"
value="10px,12px,14px,16px,24px" />
<f:param name="theme_advanced_fonts"
value="Arial=arial,helvetica,sans-serif;Arial Black=arial black,avant garde;Courier New=courier new,courier;Helvetica=helvetica;" />
<f:param name="language" value="pt" />
<f:param name="theme_advanced_toolbar_location" value="top" />
<f:param name="theme_advanced_toolbar_align" value="left" />
<f:param name="relative_urls" value="false" />
<f:param name="remove_script_host" value="false" />
</rich:editor>
<h:commandLink target="blank" action="/pages/editorPDF.seam">
<h:graphicImage alt="Export Pdf" url="/imgages/_view.gif"
title="Export table to PDF" />
</h:commandLink>
</h:form>
<rich:modalPanel id="uploadPanel" autosized="true">
<f:facet name="header">
<h:outputText value="Upload de Imagens" />
</f:facet>
<f:facet name="controls">
<h:panelGroup>
<h:graphicImage value="/images/close.png" id="upLink" />
<rich:componentControl for="uploadPanel" attachTo="upLink"
operation="hide" event="onclick" />
</h:panelGroup>
</f:facet>
<h:form>
<h:panelGrid columns="2" columnClasses="top,top">
<rich:fileUpload fileUploadListener="#{fileUploadBean.listener}"
maxFilesQuantity="1" id="upload" immediateUpload="true"
acceptedTypes="jpg, gif, png, bmp" stopEntryControlLabel="Parar"
transferErrorLabel="Ocorreu um erro no envio do arquivo"
sizeErrorLabel="Arquivo NAO enviado. Tamanho maior que o permitido (5Mb)"
onsizerejected="alert('Arquivo com tamanho maior que o permitido (5Mb)')"
ontyperejected="alert('Tipo de arquivo invalido, ou duplicado.')">
<a4j:support event="onuploadcomplete" reRender="info" />
</rich:fileUpload>
<h:panelGroup id="info">
<rich:panel>
<f:facet name="header">
<h:outputText value="Preview" />
</f:facet>
<a4j:mediaOutput element="img"
mimeType="#{fileUploadBean.file.mime}"
createContent="#{fileUploadBean.paint}"
value="#{fileUploadBean.file}"
style="width:100px; height:100px;" cacheable="false">
<f:param value="#{fileUploadBean.timeStamp}" name="time" />
</a4j:mediaOutput>
<a4j:commandButton value="Inserir Imagem"
onclick="insertImage('#{fileUploadBean.file.name}');Richfaces.hideModalPanel('uploadPanel')" />
</rich:panel>
</h:panelGroup>
</h:panelGrid>
</h:form>
</rich:modalPanel>
</ui:define>
</ui:composition>
Obrigado pela ajuda.