Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
James Isaac
Difficulty with fileUpload in Liferay
August 28, 2012 9:55 PM
Answer

James Isaac

Rank: New Member

Posts: 4

Join Date: August 28, 2012

Recent Posts

I've been trying to use the file upload feature in my liferay-jsf project. I tried using the PrimeFaces fileUpload tag but ran into several issues. The fileUploadListener never got called even after placing the Filter Servlet mapping in the web.xml.

After considerable googling, I decided to go with the liferay-faces-bridge component. I placed the related liferay-faces-alloy, liferay-faces-bridge-api, liferay-faces-bridge-impl, liferay-faces-portal, liferay-faces-util jars and removed the porletfaces-bridge from WEB-INF/lib. But the problem is that when I do this, my portlet gets undeployed.

Aug 28, 2012 10:42:17 AM org.apache.catalina.startup.HostConfig checkResources
INFO: Undeploying context [/DemoPoc-portlet]
Aug 28, 2012 10:42:17 AM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor C:\liferay-portal-6.1.10-ee-ga1\tomcat-7.0.25\conf\Catalina\localhost\DemoPoc-portlet.xml
Aug 28, 2012 10:42:17 AM org.apache.catalina.startup.HostConfig deployDescriptor
WARNING: A docBase C:\liferay-portal-6.1.10-ee-ga1\tomcat-7.0.25\webapps\DemoPoc-portlet inside the host appBase has been specified, and will be ignored
Aug 28, 2012 10:42:17 AM org.apache.catalina.startup.SetContextPropertiesRule begin
WARNING: [SetContextPropertiesRule]{Context} Setting property 'source' to 'org.eclipse.jst.jee.serveremoticonemoPoc-portlet' did not find a matching property.
Aug 28, 2012 10:42:18 AM org.apache.catalina.core.StandardContext addApplicationListener
INFO: The listener "com.sun.faces.config.ConfigureListener" is already configured for this context. The duplicate definition has been ignored.
Aug 28, 2012 10:42:20 AM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
Aug 28, 2012 10:42:20 AM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/DemoPoc-portlet] startup failed due to previous errors
10:42:20,995 INFO [PluginPackageUtil:1026] Reading plugin package for DemoPoc-portlet
10:42:31,001 WARN [PluginPackageUtil:1365] Unable to reindex unistalled package DemoPoc-portlet: Unable to communicate with repository http://plugins.liferay.com/enterprise

This is what I've put in my xhtml page:
<p:dialog id="modalDialog2" closable="true" header="Select file" widgetVar="dlg3" height="200">
<h:form enctype="multipart/form-data">
<h:panelGrid columns="1">
<bridge:inputFile fileUploadListener="#{fileUploadBackingBean.handleFileUpload}" multiple="multiple" />
</h:panelGrid>
</h:form>
</p:dialog>

My FileUploadBackingBean looks like this:

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

import com.liferay.faces.bridge.model.UploadedFile;
import com.liferay.faces.bridge.event.FileUploadEvent;

@ManagedBean
@ViewScoped
public class FileUploadBackingBean {

public void handleFileUpload(FileUploadEvent fileUploadEvent) throws Exception {
UploadedFile uploadedFile = fileUploadEvent.getUploadedFile();
System.out.println("########## Succesful"+ uploadedFile + " is uploaded.");
}

}

It would be great if someone pointed out where I went wrong.
Neil Griffin
RE: Difficulty with fileUpload in Liferay
August 29, 2012 7:58 AM
Answer

Neil Griffin

LIFERAY STAFF

Rank: Liferay Legend

Posts: 2349

Join Date: July 26, 2005

Recent Posts

I would recommend that you take a look at the primefaces3-portlet demo which has a p:fileUpload example.

The "SEVERE: Error listenerStart" error can be made more clear by following the instructions in Mika Koivisto's blog post.

Typically there is a ClassNotFoundException or NoClassDefFoundError that is being thrown due to missing/duplicate JARs in your portlet's WAR WEB-INF/lib folder.
James Isaac
RE: Difficulty with fileUpload in Liferay
August 29, 2012 11:53 PM
Answer

James Isaac

Rank: New Member

Posts: 4

Join Date: August 28, 2012

Recent Posts

Hi Neil,
Thanks a lot for your reply.

Please check this out:

<p:menuitem value="Import using CSV" onclick="dlg3.show();" />

-- -- -- --

<p:dialog id="modalDialog2" closable="true" header="Select file" widgetVar="dlg3" height="200">
<h:form enctype="multipart/form-data">
<p:fileUpload value="#{fileUploadBackingBean.file}" mode="simple"/>
<p:commandButton value="Submit" ajax="false"
actionListener="#{fileUploadBackingBean.handleFileUpload}"/>
</h:form>
</p:dialog>

And in the backing bean:
public void handleFileUpload(FileUploadEvent event) {
System.out.println("Uploaded file is getting called");
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
PortletSession portletSession = (PortletSession) externalContext.getSession(false);
String uniqueFolderName = portletSession.getId();
org.primefaces.model.UploadedFile uploadedFile = event.getFile();
System.out.println("Uploaded file is "+uploadedFile);
System.out.println("Unique Folder name is "+uniqueFolderName);
}

Why is it that the listener never gets called? Is it because the html code I have shown above was nested in another <h:form> ?
Neil Griffin
RE: Difficulty with fileUpload in Liferay
August 30, 2012 9:44 AM
Answer

Neil Griffin

LIFERAY STAFF

Rank: Liferay Legend

Posts: 2349

Join Date: July 26, 2005

Recent Posts

When you click on the p:menuItem, does the p:dialog appear?

One thing that I noticed, is that the primefaces3-portlet demo applicant.xhtml Facelet composition has this:

1<h:form>
2    <p:dialog>
3        <p:fileUplaod />
4    </p:dialog>
5</h:form>


But yours looks more like this:

1<p:dialog>
2    <h:form>
3        <p:fileUplaod />
4    </h:form>
5</p:dialog>


Not sure if it will fix it, but it be worth trying it with h:form as the outermost component tag.
James Isaac
RE: Difficulty with fileUpload in Liferay
August 31, 2012 1:10 AM
Answer

James Isaac

Rank: New Member

Posts: 4

Join Date: August 28, 2012

Recent Posts

Hi Neil,

Thanks for the reply.

Tried it with the <h:form> outside. But the listener still doesn't get called. And yes, the dialog does get called.

Regards,
James
Jesse Fox
RE: Difficulty with fileUpload in Liferay
August 31, 2012 6:49 AM
Answer

Jesse Fox

Rank: New Member

Posts: 1

Join Date: August 31, 2012

Recent Posts

thanks for sharing this information.
Neil Griffin
RE: Difficulty with fileUpload in Liferay
August 31, 2012 10:44 AM
Answer

Neil Griffin

LIFERAY STAFF

Rank: Liferay Legend

Posts: 2349

Join Date: July 26, 2005

Recent Posts

Hi James,

Sorry, I should have looked at your original XHTML markup more closely. I see that you are using bridge:inputFile from Liferay Faces Bridge. If you are using PrimeFaces, then you can use p:fileUpload component tag which has a richer UI with multiple file upload functionality. It might be more compatible with p:dialog. When you get a chance, could you try p:fileUpload instead of bridge:inputFile?

Neil
Neil Griffin
RE: Difficulty with fileUpload in Liferay
August 31, 2012 10:46 AM
Answer

Neil Griffin

LIFERAY STAFF

Rank: Liferay Legend

Posts: 2349

Join Date: July 26, 2005

Recent Posts

Upon further review, I think you may have already switched to p:fileUpload after I mentioned the primefaces3-portlet demo.

It might be the case that p:fileUpload is not compatible with p:dialog. Can you remove the p:dialog from the view and see if your listener starts getting called?
James Isaac
RE: Difficulty with fileUpload in Liferay
September 2, 2012 10:44 PM
Answer

James Isaac

Rank: New Member

Posts: 4

Join Date: August 28, 2012

Recent Posts

Hi Neil,

Thanks for taking the time to look into this issue.

I tried using the <p:fileUpload> without the <p:dialog> but it still doesn't work.
I modified the xhtml code to look like this:

<h:form enctype="multipart/form-data" prependId="false">
<p:fileUpload value="#{fileUploadBackingBean.file}" mode="simple"/>
<p:commandButton value="Submit" ajax="false"
action="#{fileUploadBackingBean.upload}"/>
</h:form>

I could see that the file property in the bean never gets set. So, in the upload() method (which now gets called as it is an action and not an actionListener), the value of file is null.
Do we have to do any further configuration in web.xml other than this:

<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
Neil Griffin
RE: Difficulty with fileUpload in Liferay
September 3, 2012 5:29 AM
Answer

Neil Griffin

LIFERAY STAFF

Rank: Liferay Legend

Posts: 2349

Join Date: July 26, 2005

Recent Posts

Hi James,

The PrimeFaces FileUpload Filter is not compatible with portlets. Instead, the file upload abilities are built directly into Liferay Faces Bridge. So you can delete that from your WEB-INF/web.xml descriptor.

Neil