Is it possible to export the editor data to pdf using Data exporter of primefaces.
I tried with following code but it didnt worked.
<p:editor value="#{mailBean.mail}" id="editor">
</p:editor>
<p:commandLink>
<p:graphicImage value="/images/pdf.gif" />
<p:dataExporter type="pdf" target="editor" fileName="files" pageOnly="true"/>
</p:commandLink>
No its not
from the user guide:
DataExporter is handy for exporting data listed using a Primefaces Datatable to various formats
such as excel, pdf, csv and xml.
more from the user guide
Target must
point to a PrimeFaces Datatable
Edit
What you could try is : Integrate TinyMCE editor in your project and take a look at this thread HTML to PDF demo , here is a direct link WYSIWYG Editor Export to PDF
Data exporter publisher button must not ajax, and target value should refer to an datatable, also you need itext 2.1.7 Optional DataExporter (PDF) *apache poi 3.7 Optional DataExporter* libraries (Excel)..
Even if they are all right, data exporter not stable yet, it depends your datatable. For example it can not export data when you use dynamic column with column group.
I prefer export your own documents using itext libraries, its also more flexible.
Good Luck!
if the Target must point to a PrimeFaces Datatable , then how the below code is possible
this is from primeface site .(http://www.primefaces.org/showcase/ui/chartExport.jsf)
<p:lineChart value="#{chartBean.linearModel}" legendPosition="e" zoom="true"
title="Linear Chart" minY="0" maxY="10" style="width:500px;height:300px" widgetVar="chart"/>
<p:commandButton type="button" value="Export" icon="ui-icon-extlink" onclick="exportChart()"/>
<p:dialog widgetVar="dlg" showEffect="fade" modal="true" header="Chart as an Image">
<p:outputPanel id="output" layout="block" style="width:500px;height:300px"/>
</p:dialog>
function exportChart() {
//export image
$('#output').empty().append(PF('chart').exportAsImage());
//show the dialog
PF('dlg').show();
}
here the source file is a chart and using the function exportChart() get the exported data as image.that means we can export any data not only the primeface datatable.
Related
I am using PrimeFaces File Upload with mode="advanced" and multiple="true" just like the demo shows here https://www.primefaces.org/showcase/ui/file/upload/multiple.xhtml?jfwid=50dd6
In this case, the user uploads multiple files and is shown the files to edit the list. The user must then click "upload" to upload the files. If they fail to click upload and submit the form on the page, the files don't get uploaded. I know about the auto="true" option, but we want to keep the ability to edit the list.
How can I prevent form submission if the user has pending file uploads?
You can block the submit button by checking the number of files in the onclick attribute:
<h:form>
<p:fileUpload widgetVar="upload" .../>
<p:commandButton onclick="return PF('upload').files.length===0" .../>
</h:form>
Of course it would be better to extend this check and show a message to the user if they forgot to upload any files. For example by adding a message to a p:growl component:
PF('growl').add({detail:'Please upload files first',severity:'warn'});
See also:
Add message to p:growl using Javascript
Well I don't know if you are using some other "dirty" form logic but can't you just set your dirty flag in the onAdd JS function of the FileUploader?
onAdd="setDirty(true);"
Then you can use onBeforeUnload to display the dirty dialog like in this post: What is the easiest way to detect if at least one field has been changed on an HTML form?
Trying to narrow in on our issue we are upgrading from Jboss 6 EAP (JSF 2.1) to Jboss 7 EAP (JSF 2.2). Our working application now has an issue with OmniFaces ViewScoped beans.
Versions:
Mojarra 2.2.14
OminFaces 2.6.9
PrimeFaces 6.2.5
We have a datatable like this:
<p:dataTable id="tblLegalHolds" widgetVar="tableLegalHolds" var="row"
rowKey="#{row.id}" filterEvent="enter"
lazy="true"
value="#{bean.lazyDataModel}"
rows="15">
NOTE: Our bean is OmniFaces ViewScoped and our table is working fine at this point!
Problem:
Next we add a column that contains a navigation to a new page like this:
<p:column width="60" exportable="false">
<p:button value="Open" outcome="legal-hold-edit">
<f:param name="id" value="#{row.id}" />
</p:button>
</p:column>
Now our bean is getting loaded and unloaded immediately and if we do a View Source of the HTML we see the Omnifaces script added twice like so...
OmniFaces.Unload.init('f1c1ff81-c87f-4406-b98f-a3eaff977e96');
OmniFaces.Unload.init('45e7de9d-53c7-4426-a972-797c48c46733');
We added #PostConstruct to our ViewScoped beans to prove its getting called twice. Our faces-config.xml looks like this for that Navigation.
<navigation-case>
<from-outcome>legal-hold-edit</from-outcome>
<to-view-id>/legal/legal-hold-edit.xhtml</to-view-id>
<redirect include-view-params="true"/>
</navigation-case>
Now what is interesting is if we remove the "include-view-params" in faces-config.xml like the code below everything starts working fine the ViewScoped bean is created only once and only 1 OmniFaces.Unload.init script is added to the page.
<navigation-case>
<from-outcome>legal-hold-edit</from-outcome>
<to-view-id>/legal/legal-hold-edit.xhtml</to-view-id>
<redirect/>
</navigation-case>
As an added note our outcome page is using o:viewparam to receive the param like this:
<f:metadata>
<o:viewParam name="id" value="#{legalHoldForm.legalHold}" required="false" />
<f:event type="preInvokeAction" listener="#{controller.initializeViewLegalHold}" />
</f:metadata>
So my questions are:
Why does removing "include-view-params" make it work?
Is this a bug similar to this recent ViewScoped issue? : https://github.com/omnifaces/omnifaces/issues/463
This appears to be a bug in Mojarra. It's indirectly calling the PreDestroyViewMapEvent when figuring out the view parameters for the other view.
During the render response phase, when the URL for an UIOutcomeTarget component (e.g. <p:button>) is to be generated, and includeViewParams is set to true (as defined in your navigation case), then it needs to consult all <f:viewParam> of the target view. In order to achieve this, it will need to build an UIViewRoot instance of it.
However, it actually temporarily sets that new UIViewRoot as the current view root of the faces context in order to access the <f:viewParam>. It will restore the original view, but this is where it goes wrong in Mojarra. It is restoring context.setProcessingEvents(true) too early. It should actually have done it after restoring the original view.
For now, your best bet is to report this issue against Mojarra and avoid using includeViewParams in combination with OmniFaces #ViewScoped.
Issue reported: https://github.com/eclipse-ee4j/mojarra/issues/4503
PR Provided: https://github.com/eclipse-ee4j/mojarra/pull/4730
This fix will be included in 2.3.15, 3.0.1 and 4.0.0 of Mojarra.
I've added a core class project to my solution with a controller and view. The solution runs and loads the controller and view fine.
The problem is I don't have the razor syntax in the view. I'd like to use the #Model and the helpers etc. I've seen information online but none relating to .Net Core class projects.
Help would be good
Convert the class project to a mini Web project. Razor support in non-web projects is not a popular request at this moment.
Edit a csproj file to:
<Project Sdk="Microsoft.NET.Sdk.Web">
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
</ItemGroup>
Add empty Program class with Main method cause compiler will ask for this.
Is this possible? Adding the following two lines to a csproj for a web application enables precompilation and produces a Project.PrecompiledViews.dll:
<MvcRazorCompileOnPublish>true</MvcRazorCompileOnPublish>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.ViewCompilation" Version="1.1.0" />
Adding the same two lines to a class library which contains views does not produce a Library.PrecompiledViews.dll. Is this not currently supported, or does a class library require a little more coaxing?
I am using primefaces 3.3.1 and liferay 6.
In my portlet I want to add fileUpload for primefaces. But each time whenever my page loads this primefaces component is not visible through firebug. I need to make its display to block.
Also, any components below the fileUpload which consists of javascript method or ajax is not working.
I have noticed that in firebug whenever my page loads it shows me one error such as
this.form.fileUpload is not a function
I guess due to this error my fileUpload is not working. But I am not able to to fix it.
<p:fileUpload fileUploadListener="#{fileUploadController.handleFileUpload}" mode="advanced" fileLimit="3"/>
Upgrade your primefaces to version 3.5 and add commons-fileupload to your project
I think it caused by you didn't add the commons-fileupload and commons-io in your project lib. Also, don't forget do define FileUploadFilter in your web.xml.
Let me show you how i did file upload in my primefaces before, hope this example can solve your problem.
My xhtml page :
<p:fileUpload allowTypes="/(\.|\/)(csv)$/" fileUploadListener="#{fileBean.handleFileUpload}"/>
My FileBean.java :
public class FileBean {
private UploadedFile file;
public void handleFileUpload(FileUploadEvent event) throws Exception {
file = event.getFile();
InputStream input = file.getInputstream();
OutputStream output = new FileOutputStream(new File("D:/UploadedFile/", file.getFileName()));
IOUtils.copy(input, output);
}
Add this to your web.xml :
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>
org.primefaces.webapp.filter.FileUploadFilter
</filter-class>
</filter>
And as I said before, add commons-fileupload and commons-io to your project lib.
Fixed this issue in Liferay Portal 6.0.x.
Can you add this code to web.xml and try it?
<!-- Workaround for PrimeFaces 3.2: -->
<context-param>
<param-name>com.liferay.faces.bridge.primeFileUploadForceResourceURL</param-name>
<param-value>true</param-value>
</context-param>
Here is link for more information.
After trying everything else concerning web.xml,pom.xml,... I came back to the obvious things :-)
Maybe you are just forgetting to wrap an form around your upload elements:
<h:form enctype="multipart/form-data">
<p:fileUpload mode="simple" value="#{mgr.file}"/>
<p:commandButton value="Hochladen" ajax="false" onclick="start();"
action="#{mgr.uploadBescheid(bescheidTyp)}" update="growl"/>
</h:form>
Without that point it won't work...