Fileupload of PrimeFaces is not working in my liferay portlet? - primefaces

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...

Related

Can not find "locale.properties" file from PDF.js

I use this plugin: PDF.js.
I am trying to solve the problems that show in console log.
Follow image:
Here is a simple project ready, only download and run project you will see the same problem. I've tried everything and I can not solve a problem.
Follow html:
<div style="width: 800px; height: 500px;">
<iframe width="800" height="500" id="iframePdfViewer" seamless="seamless" scrolling="no" src="~/Scripts/pdfjs-dist/web/viewer.html"></iframe>
</div>
See another image that contains "locale.properties" file:
And I also get a lot of warnings from l10n.js. I downloaded it here: http://mozilla.github.io/pdf.js/ by clicking the "download" button.
Any solution ?
Adding .properties MIME type configuration inside web.config file should work:
<configuration>
<!-- other stuff -->
<system.webServer>
<staticContent>
<mimeMap fileExtension=".properties" mimeType="application/octet-stream" />
</staticContent>
</system.webServer>
</configuration>
If the project is already deployed in IIS (not IIS Express), go to site name => MIME Types => Add, and set .properties extension with application/octet-stream type as in provided image below:
Here is the console log view with all l10n.js errors disappear:
The reason behind usage of application/octet-stream is that the corresponding file should be treated as stream, even file contents are readable and stored in text format.
Reference: l10n.js - locale.properties 404 (Not Found)
If you are using .net core (2.1) try to add .properties as static file in your "public void Configure(IApplicationBuilder app, IHostingEnvironment env)" method
var provider = new FileExtensionContentTypeProvider();
provider.Mappings[".properties"] = "application/octet-stream";
app.UseSpaStaticFiles(new StaticFileOptions
{
ContentTypeProvider = provider
});
Inspired by Lukáš Janeček, If you are using .net core(3.1). try to add the following code to your public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
var provider = new FileExtensionContentTypeProvider();
provider.Mappings[".properties"] = "application/octet-stream";
app.UseStaticFiles(new StaticFileOptions()
{
ContentTypeProvider = provider
});

OmniFaces loading/unloading ViewScopedBean

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.

Libgdx ClassReflection.newInstance don't work with html version

I'm working on an application that must work on desktop, android and web browser.
On Desktop and Android I have no problem, everything work fine.
But on the HTML version, the newinstance of a class won't work. I don't understand why.
Here is my code:
public static Node newInstanceGdx(Class<? extends Node> nodeModel) throws ReflectionException {
if (nodeModel != null)
try {
return ClassReflection.newInstance(nodeModel);
} catch (Exception e) {
e.printStackTrace();
Gdx.app.setLogLevel(Application.LOG_DEBUG);
Gdx.app.log("Reflection", "Can't initialize Node class : " + (Node.class).getName());
}
return null
}
And here is myGame.gwt.xml code :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit trunk//EN" "http://google-web-toolkit.googlecode.com/svn/trunk/distro-source/core/src/gwt-module.dtd">
<module>
<source path="fr/EU/Game" />
<extend-configuration-property name="gdx.reflect.include" value="com.me.reflected.ReflectedClass" />
<extend-configuration-property name="gdx.reflect.include" value="com.badlogic.gdx.utils.reflect.ClassReflection"/>
<extend-configuration-property name="gdx.reflect.include" value="com.badlogic.gdx.utils.reflect.ReflectionException"/>
</module>
It always return "null" for the html version, but on the other version, everything work.
Thanks in advance for your help.
I found out my problem, I hope it will help other !
GWT needs to know the type of the Object it use.
So when you do ClassReflection.newInstance(o) the "o" type must be known by GWT.
To do so, you must import in *.gwx.xml, your class with :
<extend-configuration-property name="gdx.reflect.include" value="path.ClassOfObject"/>
gdx.reflect.include does only help for libGDX' built-in methods like for deserializing objects from jsons. If you want to use this, you have to look into the libGDX sources what kind of statements they are using.
I would recommend you to go away from reflection when not absolutely neccessary. It is a nice solution which looks better than using a factory method implementing new statements, but in my experience you will have problems with ProGuard and GWT sooner or later that can be avoided.

Link to primefaces theme stylesheet is missing session id

I've added a primefaces theme to the web.xml...
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>le-frog</param-value>
</context-param>
... and get a link to the stylesheet in the head ...
<link type="text/css" rel="stylesheet" href="/pos2hue/javax.faces.resource/theme.css.jsf?ln=primefaces-le-frog" />
...which would be correct, if we wouldn't use single-sign-on, which redirects all URLs without a sessionid to the login screen. So the stylesheet resolves to:
<HTML><HEAD><TITLE>HTTP Post Binding (Request)</TITLE></HEAD><BODY Onload="document.forms[0].submit()"><FORM METHOD="POST" ACTION="https://configured.identity.url"><INPUT TYPE="HIDDEN" NAME="SAMLRequest" VALUE="..."/></FORM></BODY></HTML>
Other links coming from primefaces are OK, for example:
<script type="text/javascript" src="/contextroot/javax.faces.resource/jsf.js.jsf;jsessionid=eo0Oo0oK37AUm7bNOaFqdrB-?ln=javax.faces"></script>
As additional info I have to add:
session mode in web.xml is set to "URL" (i don't want to change that)
<session-config>
<tracking-mode>URL</tracking-mode>
</session-config>
for single-sign-on we use picketlink (i have a picketlink.xml in the WEB-INF folder)
web server is JBoss EAP 6.1
Any ideas, how i could
make primefaces add the sessionid to the stylesheet href?
make an exclusion to the single-sign-on mechanism?
or make it work otherwise?
Adding the stylesheet directly is possible, but unwanted, because we use a JSF2 template for all applications, but i want to configure it for one application only.
Thank you in advance!

Primefaces Data Exporter with Primefaces Editor

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.