Fórum

bridge:inputFile problem

Katarzyna B, modificado 12 Anos atrás.

bridge:inputFile problem

New Member Postagens: 18 Data de Entrada: 07/01/12 Postagens Recentes
Hello,

I'm trying to upload file in JSF Liferay portlet, using bridge:inputFile. The problem I'm facing is that in backing bean the HtmlInputFile member gets set, but its getUploadedFile() method always returns null.

My .xhtml
<f:view xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:ice="http://www.icesoft.com/icefaces/component" xmlns:icecore="http://www.icefaces.org/icefaces/core" xmlns:liferay-ui="http://portletfaces.org/liferayfaces/liferay-ui" xmlns:liferay-util="http://portletfaces.org/liferayfaces/liferay-util" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:bridge="http://portletfaces.org/bridge" xmlns:p="http://java.sun.com/jsp/jstl/core">
	
	<h:head />
	<h:body>

       <h:form enctype="multipart/form-data">
			<bridge:inputfile binding="#{siteDetailsBean.attachment1}" />
			<h:commandbutton actionListener="#{siteDetailsBean.uploadAttachments}" value="Submit" />
		</h:form>

	</h:body>
</f:view>


My bean

@ManagedBean
public class SiteDetailsBean implements Serializable{
        private HtmlInputFile attachment1;

	public void uploadAttachments(ActionEvent actionEvent) {

		UploadedFile uploadedFile1 = attachment1.getUploadedFile();
		if (uploadedFile1 != null) {
			System.out.println("Uploaded file:" + uploadedFile1.getName());
		} else {
			System.out.println("NULL");
		}
	}

	public HtmlInputFile getAttachment1() {
		return attachment1;
	}

	public void setAttachment1(HtmlInputFile attachment1) {
		this.attachment1 = attachment1;
	}
}


I've seen on forum there were posts related to the same problem but no solution was proposed.

P.S. I'm running Liferay 6.0.6 and was able to deploy and run this example on it: http://www.liferay.com/community/liferay-projects/liferay-faces/demos#jsf2-portlet
thumbnail
Neil Griffin, modificado 12 Anos atrás.

RE: bridge:inputFile problem

Liferay Legend Postagens: 2655 Data de Entrada: 27/07/05 Postagens Recentes
I saw that you mentioned the jsf2-portlet was deployed. Does file upload work with the jsf2-portlet? If yes, then perhaps you could start with the jsf2-portlet, and then remove all of the parts of the application that you don't need, until all that is left is a simple file upload portlet.
Katarzyna B, modificado 12 Anos atrás.

RE: bridge:inputFile problem

New Member Postagens: 18 Data de Entrada: 07/01/12 Postagens Recentes
I had a look at libs from example's WAR and the difference is I'm using also ICEFaces 2.0.2 and ICEPush 2.0.2 - I will check withouth them, but maybe there is some known issues with that library set?
thumbnail
Neil Griffin, modificado 12 Anos atrás.

RE: bridge:inputFile problem

Liferay Legend Postagens: 2655 Data de Entrada: 27/07/05 Postagens Recentes
If you add icefaces.jar as a dependency to your project, then ICEfaces will automatically Ajaxify all of the h:commandButton and h:commandLink components in the view. That *might* be causing the problem in your application.

In order to disable this feature for a particular JSF view, add the following markup to the XHTML:

<icecore:config render="false"/>

That should un-auto-Ajaxify your h:commandButton and h:commandLink components.

See: http://wiki.icefaces.org/display/ICE/Core+Tags

Otherwise, if you want an Ajax-based file upload, you can look at the icefaces2-portlet example.