I need to use PrimeFaces p:fileDownload from within a data-table inside a modal dialog, but due to the use of ajax="false" (else the file download won't be triggered) inside command button the dialog disappears. Do you have any clue?
<p:commandLink value="#{row.name}" ajax="false"
actionListener="#{documentsBean.fileDownloadController(row)}">
<p:fileDownload value="#{documentsBean.fileStream}" />
</p:commandLink>
Above is the command link triggering the file download and it is included inside a data-table, the data-table itself is inserted in a modal dialog. Any help appreciated.
I Tested this method and it's worked fine for me, but to make a complete answer add some code to understand if there is a problem
public void downloaddoc(FileUploadEvent file) throws FileNotFoundException, TransformerConfigurationException, TransformerException {
InputStream input = file.getFile().getInputstream();
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
setDownload(new DefaultStreamedContent(input, externalContext.getMimeType(file.getFile().getName(), file.getFile().getName()));
}
you can read more in Primefaces Web Site
Hope that helped you.
Related
Am Upgrading application from PrimeFaces 6.1 to PrimeFaces 6.2. I have <p:dialog appendTo="#(body)" id="dialog" widgetVar="widgetVar" modal="true"> with <p:message id="validation"> element inside it.
Am opening dialog using PF('widgetVar').show(). When I click p:commandButton inside dialog, doing some validation and showing message using below code,
FacesContext.getCurrentInstance().addMessage("validation", new
FacesMessage(FacesMessage.SEVERITY_ERROR, "validation error", null))
With in the same method am reopening dialog and update it with below code,
RequestContext context = RequestContext.getCurrentInstance();
context.update("dialog");
context.execute("PF('widgetVar').show();")
In PrimeFaces 6.1 its working fine and validation message getting displayed. But in PrimeFaces 6.2 validation Message not displaying in dialog. I know RequestContext is deprecated in PF 6.2. Am also tried with below code,
PrimeFaces primefaces = PrimeFaces.current();
primefaces.ajax().update("dialog");
primefaces.executeScript("PF('widgetVar').show();");
Facing same issue. I saw that message displaying and immediately its getting cleared.
But, when I remove the ajax update primefaces.ajax().update("dialog"); It's working fine.
What is the reason for this issue?
Code used in MBean:-
private StreamedContent file;
public void actionGenerate () {
String reportType= XML/PDF/XLS;
byte[] reportOut;
file = new DefaultStreamedContent(new ByteArrayInputStream(reportOut), ReportMimeType.valueOf(reportType)
.getLabel(), "abcListReport." + reportType.toLowerCase());
}
Code in XHTML:-
<div id="p_searchButtons">
<p:commandButton ajax="false" id="btnGenerateReport"
target="_blank" value="#{text.common_Submit}"
actionListener="#{abcListPrintMB.actionGenerate}"
widgetVar="generateReport">
<p:fileDownload value="#{abcListPrintMB.file}" />
</p:commandButton>
</div>
primefaces 3.3 is being used.
IE8 able to download the PDF in the local enviroment (local domain)
p:fileDownload doesn't work in IE8 if the download is requested over https. it works only if the IE settings "Do not save encrypted page to disk" is activated.
Check the link below:
https://code.google.com/p/primefaces/issues/detail?id=5934
Security issue with IE 8
You need to check advanced setting of browser
I have this very simple code which works fine until I add a f:ajax tag.
Code that works:
<h:commandButton disabled="#{!feature.available}" class="featureButton"
value="#{feature.selected ? 'selected': feature.available? 'available':'unavailable'} "
style="vertical-align: top;" action="#{Bean.toggleFeature(feature)}">
</h:commandButton>
Code that doesn't work:
<h:commandButton disabled="#{!feature.available}" class="featureButton"
value="#{feature.selected ? 'selected': feature.available? 'available':'unavailable'} "
style="vertical-align: top;" action="#{Bean.toggleFeature(feature)}">
<f:ajax event="click" />
</h:commandButton>
As far as I can tell the jsf.js file is loaded fine, this is automatically added by the facelet servlet to the head of my rendered document
<script type="text/javascript" src="/www/javax.faces.resource/jsf.js.xhtml?ln=javax.faces"></script> and I was even able to do a jsf.ajax.request directly from javascript and got the page to rerender something.
I am using mojarra 2.1.13, tomcat 7, eclipse juno, java 7.
Any thoughts on what I might be doing wrong or how I might be able to troubleshoot this issue? debugging it in javascript didn't help at all.
Thanks.
I failed to mention above that I had nested ui:repeats and it turns out there is a bug with mojarra regarding that. As far as I can tell the fix has just been committed but it isn't out as a jar yet however I tried myfaces and it worked fine, so I'll do that for now. Here are the bug details:
http://java.net/jira/browse/JAVASERVERFACES-1817
I have this line of code in my application:
<f:ajax event="click"
render="#{ULInvestmentPatternUI.premiumForm}
fundstable btnModify btnSave"
The section of code is in a h:commandButton in an .xhtml file.
When I run the code locally and click on the button I get this error message showing up in my console in Eclipse :
SEVERE: java.lang.IllegalArgumentException: ""
and the buttons which are supposed to update (become enabled) don't.
I've narrowed down the problem to the line wrapping in the render attribute:
render="#{ULInvestmentPatternUI.premiumForm}
fundstable btnModify btnSave"
If this is all on one line (no carriage return between #{ULInvestmentPatternUI.premiumForm} and fundstable) then the SEVERE: java.lang.IllegalArgumentException: "" message is not displayed in the console. The relevent buttons on the page still do not update though.
I'm new to the development team that I am in. All the other developers in the team are using the same code and it is working fine for them. I've checked to make sure that my environment is set up the same as everyone else in the team, and everything seems exactly the same.
Can anyone suggest anything please ?
Thanks,
Trish.
I had to take over an MVC 3 project from another developer. One of the first things he did was to stop the yellow screen of death so that all exceptions are only logged to a file. You now only get a generic message saying an error has occurred.
I would like to switch it back on (since it gets really annoying having to check through the logfiles the whole time) - how do I do this.
I checked through the web.config but I can't see where this happens.
I did try doing customerrors=off, but that didn't do anything. Also removed the global error handling attribute, didn't do anything.
On further clarification, it seems if an exception occurs in a controller I do get the yellow screen of death, but if it occurs in a (razor) view I just get a standard generic error.
You can see the web.config here
You can see the global.asax here
This question is a little old, but maybe this will help someone. In addition to setting <customerErrors mode="Off" />, also set this under <system.webServer>: <httpErrors errorMode="Detailed" />
<system.webServer>
<httpErrors errorMode="Detailed"/>
</system.webServer>
Normally you set this in web.config in the customErrors element under system.web.
Just try to set mode=Off:
<customErrors mode="Off" />
In Global.asax you can remove filters.Add(new HandleErrorAttribute()); from public static void RegisterGlobalFilters(GlobalFilterCollection filters).
As pointed out in the comments - the problem was with a Custom Base controller overriding the OnException Method.
None of this worked for me. Check if someone might have added code to clear the error in the application error event handler.
protected void Application_Error(object sender, EventArgs e)
{
Exception lastException = Server.GetLastError().GetBaseException();
Log.Error("Global.asax: WebApplication error", lastException);
//****Server.ClearError();
}