Primefaces FileUpload Complete call specify method - jsf

In Primefaces 5.1 I need File upload complete to call another method. i.e. upload button press the handFileUpload action perform then upload complete to need to call another action.
<p:fileUpload fileUploadListener="#{fileUploadView.handleFileUpload}"
mode="advanced" update="messages" allowTypes="/(\.|\/)(gif|jpe?g|png)$/" >
</p:fileUpload>
I try p:ajax event="onfileUploadComplete it not working then which event to call function when upload complete?

p:fileUpload has an oncomplete attribute:
Client side callback to execute when upload ends.
(PrimeFaces 5.1 Documentation, page 207)
You can use this in combination with p:remoteCommand to call a bean method from a JavaScript event (see also http://www.primefaces.org/showcase/ui/ajax/remoteCommand.xhtml).
<p:fileUpload fileUploadListener="#{fileUploadView.handleFileUpload}" mode="advanced" update="messages" allowTypes="/(\.|\/)(gif|jpe?g|png)$/" oncomplete="fileUploadCallback()" />
<p:remoteCommand name="fileUploadCallback" action="#{bean.myMethod}" />

Related

p:fileupload image preview is not working

I am using prime faces file upload feature in my application form, whenever i upload the file it is not displaying the preview image in screen.
I would like to know which attribute and class to refer for this issue. please find the sample code below.
<fileUpload
id="uploadImage"
fileLimit="1"
fileUploadListener="#{publicSarFormDataBean.handleFileUpload}"
process="#form"
mode="advanced"
multiple="false"
auto="true"
onstart="PF('statusDialog').show()"
oncomplete="PF('statusDialog').hide(), PF('documentListTbl').filter()"
dragDropSupport="true"
sizeLimit="1000000000"
allowTypes="/(\.|\/)(png|jpeg|JPEG|jpg|JPG)$/"
invalidFileMessage="File is invalid"
update="messages"
styleClass="Fleft FontBold">
</p:fileUpload>
The 'preview' is only relevant before uploading. And since you have auto="true" the files are automatically uploaded and a preview in the p:fileUpload is useless.
It is all working fine in the PrimeFaces upload showcase

p:remoteCommand and p:messages with autoUpdate="true" clears messages [duplicate]

I'm using PrimeFaces poll component to refresh some content.
<h:form id="formBsvtt">
<p:messages autoUpdate="true" showDetail="false" />
<p:outputPanel id="panelOut" layout="block">
...
... content to refresh
...
</p:outputPanel>
<p:panelGrid id="panelIn" layout="block">
...
... various input components with validation
...
</p:panelGrid>
<p:poll widgetVar="poll1" autoStart="true" global="false" interval="15"
partialSubmit="true" process="#this" update="panelOut"
listener="#{myBean.myListener}">
</p:poll>
</h:form>
As you can see I'm using messages with autoUpdate=true. My Problem is: In case of validation errors FacesMessages will be shown, but disappear not later than 15 seconds.
Is it possible to prevent poll from clearing FacesMessages without setting messages autoUpdate=false?
My web application is much bigger as code snippet specified above and my intention is not updating messages manually in each possible case!
PrimeFaces 2.x/3.x
This is not natively possible, so a trick is needed. In the rendered attribute of <p:messages>, check if <p:poll> was been triggered and if so, then return false. This way JSF thinks there's no auto-updatable messages component in the component tree during rendering and will therefore ignore it.
If the <p:poll> is triggered, then its client ID appears as javax.faces.source request parameter. So, this should do:
<p:messages ... rendered="#{param['javax.faces.source'] ne poll.clientId}" />
...
<p:poll binding="#{poll}" ... />
(note: no additional bean properties needed)
PrimeFaces 4.x+
All PrimeFaces command components got a new ignoreAutoUpdate attribute which you could set to false to ignore all autoUpdate="true" components in the ajax update.
<p:poll ... ignoreAutoUpdate="true" />
For folks using Primefaces 4.0 and above, the Primefaces team have added an attribute to their ajax aware components to skip triggering components with autoUpdate set to true. So your poll would be
<p:poll ignoreAutoUpdate="true" .../>
See also their blog post about it: http://blog.primefaces.org/?p=2836

p:fileUpload response returns before actionListener method ended in backing bean

I have a problem with Primefaces 5.2 fileUpload actionListener in a JSF 2.2 application. Below is an example of code:
<h:form id="form1" enctype="multipart/form-data" >
<h:panelGroup id="fileUploader">
<p:fileUpload fileUploadListener="#{fileUploadControllerBean.handleFileUpload}"
onstart="PF('statusDialog').show();"
oncomplete="PF('statusDialog').hide();"
mode="advanced"
dragDropSupport="false"
multiple="false"
update="form1:uploadMessagesGrowl,
:form2:fileUploadMessage,
:form3:fileUploadPanelGroup"
uploadLabel="#{common['validateFileStudents']}"
label="#{common['addFileStudents']}"
cancelLabel="#{common['cancelFileStudents']}"
allowTypes="/(\.|\/)(csv)$/"/>
<p:growl id="uploadMessagesGrowl" showDetail="true" />
</h:panelGroup>
</h:form>
I need to upload a file and handle it in actionListener (parse, validate to actual data, etc.). After that the button 'Insert' on the 3rd form should be rendered if file is valid and no data from this file exists in database. When there is a small amount of data in the file - all is OK. But when there is a big amount of data - response returns before all data in file validated(before actionListener method ended). This leading to potential mistake when bad data in the end of file and validates after response is sended.
I think, i can do this in another way - just add validation button and validate file after upload, but i want to use fileUpload actionlistener for upload and validation at the same time.
Anybody have an idea why response returns before actionListener method ended?
Remove :form3:fileUploadPanelGroup from the update parameter and update the component at the end of your actionListener().
RequestContext.getCurrentInstance().update(":form3:fileUploadPanelGroup");

PrimeFaces fileupload ie9 not multiple select

PrimeFaces 4.0 FileUpload multiple="true" but i am not selection multiple. only one file select.
it is work in chrome but is not work ie9. Why?
xhtml
<p:dialog id="DosyaDlg" widgetVar="DosyaDialog" modal="true" resizable="false" appendTo="#(body)" header="#{msg['header.dialog.dosyaEkle']}" closeOnEscape="true">
<h:form id="DosyaForm" enctype="multipart/form-data">
<p:fileUpload fileUploadListener="#{yazilimArizaBean.dosyaYenile}" dragDropSupport="false" fileLimit="3" sizeLimit="1000000" mode="advanced" multiple="true" uploadLabel="#{msg['button.yukle']}"
cancelLabel="#{msg['button.iptal']}" description="Select Images" label="#{msg['button.sec']}" allowTypes="/(\\.|\\/)(doc|docx|xls|xlsx|ppt|pptx|txt|png)$/" oncomplete="DosyaDialog.hide()" />
</h:form>
</p:dialog>
Thank you for your helps
Seems like IE9 does not support multiple File Upload from Primefaces post v2.2.1 (meaning your v4.0 is included in the non-working ones).
See issue here : https://code.google.com/p/primefaces/issues/detail?id=3869
This will not get fixed.

How to execute h:commandButton actionListener before onclick?

I need some help in the below code
<h:commandButton id="WhatifButtonID" value="#{demandBean.dmdReviewScreenLabelVO.whatIf}" style="width:60px; height:22px;" actionListener="#{demandBean.whatif}" onclick="window.open('DemandTargetList.xhtml','whatif','width=460,height=280,top=150,left=350,resizable=no,scrollbars=no')" >
<f:ajax execute="#this" ></f:ajax>
</h:commandButton>
In the above case, the onclick attribute gets executed first followed by the actionlistener attribute. I wanted the actionListener attribute to get executed first followed by the onclick function, since the page that loads onclick needs to get certain values from the actionListener. Please let me know how to acheive the same. Thanks in Advance.
Just let <f:ajax> render a script on complete.
<h:commandButton value="#{demandBean.dmdReviewScreenLabelVO.whatIf}" actionListener="#{demandBean.whatif}">
<f:ajax execute="#this" render="popupScript" />
</h:commandButton>
<h:panelGroup id="popupScript">
<h:outputScript rendered="#{demandBean.whatifPressed}">
window.open('DemandTargetList.xhtml','whatif','width=460,height=280,top=150,left=350,resizable=no,scrollbars=no');
</h:outputScript>
</h:panelGroup>
wherein you set whatifPressed to true in the whatif() method.
PrimeFaces may help with this with the use of the <p:remoteCommand/> tag. You can then just use a plain old button to call the remoteCommand, then simply execute the window.open().
<p:remoteCommand name="viewSomething" actionListener="#{someActionIWantToExecuteBeforeOpeningWindow}" update="#this" process="#this"/>
<button onclick="viewSomething(); window.open('http://somewhere.com', 'windowName', 'height=924,width=723');">Click me!</button>
You can use it over lists of items if you call the javascript function it creates something unique.

Resources