Já procurei essa informação mas não achei solução para o problema, já tentei mudar o escopo, usar Threads, mas realmente eu preciso invocar dois métodos do Bean ao mesmo tempo ou conseguir setar uma variável do bean para true de alguma outra forma, alguém sabe se isso é possível?
Desde já obrigado!
Coloca o código e explica o que vc precisa.
O modal Panel com meu FileUpload no JSF XHMTL:
<a4j:form id="formModal">
<a4j:queue requestDelay="1000" ignoreDupResponce="true"/>
<rich:modalPanel id="panelUploadArquivo" width="340" height="80"
moveable="false" resizeable="false">
<f:facet name="header">
<h:panelGroup>
<h:outputText value="Carregando Arquivo..."></h:outputText>
</h:panelGroup>
</f:facet>
<f:facet name="controls">
<h:panelGroup>
</h:panelGroup>
</f:facet>
<h:graphicImage value="img/animated_progress_bar.gif"
style="width:320px; height:20px;padding-top:0px" />
<h:outputText
value="Este procedimento pode demorar alguns minutos de acordo com o tamanho do arquivo..."
style="font-size:10px;color:red; padding-top:5px"></h:outputText>
</rich:modalPanel>
</a4j:form>
<rich:modalPanel id="modalUploadArquivo" width="271" height="110"
moveable="false" resizeable="false"
onmaskclick="javascript:reativaUploadArquivo();#{rich:component('modalUploadArquivo')}.hide()">
<f:facet name="header">
<h:panelGroup>
<h:outputText value="Upload de Arquivo"></h:outputText>
</h:panelGroup>
</f:facet>
<f:facet name="controls">
<h:panelGroup>
</h:panelGroup>
</f:facet>
<h:form>
<a4j:queue requestDelay="1000" ignoreDupResponces="true">
<rich:fileUpload id="idFileUploadArquivo"
fileUploadListener="#{conteudoDigitalAction.salvarArquivoInstance}"
addControlLabel="Selecionar novo arquivo"
clearAllControlLabel="Limpar" clearControlLabel="remover"
doneLabel="carregado " cancelEntryControlLabel="cancelar"
stopEntryControlLabel="parar" stopControlLabel="Parar"
onfileuploadcomplete="#{rich:component('modalUploadArquivo')}.hide();
#{rich:component('panelUploadArquivo')}.show();"
onuploadcomplete="javascript:salvaArquivoAmazon()"
uploadListClass="hideElement" stopButtonClass="hideElement"
onclear="javascript:reativaUploadArquivo()" autoclear="true"
immediateUpload="false" listHeight="60px" listWidth="250px"
style="height: 150px;" />
</a4j:queue>
</h:form>
Os métodos que salvam o arquivos no Amazon:
public void salvarArquivoAmazonControle() {
if (idExtensao == null) {
return;
}
ConteudoDigitalAction runnable = new ConteudoDigitalAction();
threadAmazon = new Thread(runnable);
threadAmazon.setName("UploadAmazon");
threadAmazon.start();
try {
while (threadAmazon.isAlive()) {
System.out.println("A thread está viva!");
if (flagThread) {
System.out.println("A Thread foi morta!");
flagThread = false;
threadAmazon.interrupt();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void gravaArquivosAmazon(String caminhoArquivo,
final String nomeBucket, String idArquivo, String tipoArquivo,
long tamanhoArquivo) throws NoSuchAlgorithmException, IOException,
ServiceException {
System.out.println("TESTE------------------------------");
conecta();
criaBucket(nomeBucket);
// -----------------------------------------------------------------//
// Upload de objetos //
// -----------------------------------------------------------------//
// fileObject = new S3Object(idArquivo);
// ByteArrayInputStream greetingIS = new ByteArrayInputStream(fileData);
// fileObject.setDataInputStream(greetingIS);
// fileObject.setContentLength(tamanhoArquivo);
// fileObject.setContentType(tipoArquivo);
fileObject = new S3Object(new File(caminhoArquivo + idArquivo));
System.out.println("Teste");
List<StorageObject> objectsToUploadAsMultipart = new ArrayList<StorageObject>();
objectsToUploadAsMultipart.add(fileObject);
long maxSizeForAPartInBytes = 6 * 1024 * 1024;
MultipartUtils mpUtils = new MultipartUtils(maxSizeForAPartInBytes);
//ThreadedStorageService threadedStorageService = new ThreadedStorageService(s3Service, new )
try {
// S3ServiceEventListener
mpUtils.uploadObjects(nomeBucket, s3Service,
objectsToUploadAsMultipart, new S3ServiceEventListener() {
public void event(DownloadObjectsEvent arg0) {
}
public void event(UpdateACLEvent arg0) {
// TODO Auto-generated method stub
}
public void event(LookupACLEvent arg0) {
// TODO Auto-generated method stub
}
public void event(GetObjectHeadsEvent arg0) {
// TODO Auto-generated method stub
}
public void event(GetObjectsEvent arg0) {
// TODO Auto-generated method stub
}
public void event(DeleteObjectsEvent arg0) {
// TODO Auto-generated method stub
}
public void event(CreateBucketsEvent arg0) {
// TODO Auto-generated method stub
}
public void event(CopyObjectsEvent arg0) {
// TODO Auto-generated method stub
}
public void event(CreateObjectsEvent arg0) {
// TODO Auto-generated method stub
}
public void event(ListObjectsEvent arg0) {
// TODO Auto-generated method stub
}
public void event(MultipartCompletesEvent arg0) {
// TODO Auto-generated method stub
}
public void event(MultipartStartsEvent arg0) {
// TODO Auto-generated method stub
}
public void event(MultipartUploadsEvent arg0) {
// TODO Auto-generated method stub
}
});
} catch (Exception e) {
e.printStackTrace();
} finally {
fileObject.closeDataInputStream();
fileObject = null;
s3Service.shutdown();
}
// System.out.println("Início: " + new Date());
// s3Service.putObject(bucket, fileObject);
// System.out.println("Fim: " + new Date());
// Print details about the uploaded object.
System.out.println("Arquivo carregado com sucesso! - " + fileObject);
}
E a função Ajax que invoca o método para mudar o flag da variável para true e sair do meu método com a invocação da Thread:
<script>
window.onbeforeunload = fecharJanela
function fecharJanela(){
destroiThreadAmazon();
return "Você realmente deseja fechar a janela?"
}
</script>
<a:jsFunction name="destroiThreadAmazon"
oncomplete="#{conteudoDigitalAction.destroiThreadAmazon()};" />
E finalmente o método que muda a flag:
public void destroiThreadAmazon() {
JOptionPane.showMessageDialog(null, "TESTE!");
flagThread = true;
}
Eu preciso achar alguma forma de destruir a Thread!
A resposta para sua pergunta é sim!
É só chamar um método que contenha os dois!!!
Hehe, se fosse tão simples assim o problema!Eu preciso invocar outro método a partir de um evento ocorrido pela página XHMTL ou seja pelo javascript!Mas valeu!