Foren

Upload File in jsf 2.0(mojara)

PortletFaces Community Member, geändert vor 12 Jahren.

Upload File in jsf 2.0(mojara)

Regular Member Beiträge: 199 Beitrittsdatum: 03.04.12 Neueste Beiträge
hi
i tried to do file upload in liferay through primefaces 3.0

JSF::
====
<h:form enctype="multipart/form-data">

<p:messages showDetail="true"/>

<p:fileUpload value="#{fileUploadController.file}" mode="simple"/>

<p:commandButton value="Submit" ajax="false"
actionListener="#{fileUploadController.upload}"/>
</h:form>


Class
=====

@ManagedBean
@RequestScoped
public class FileUploadController {

private UploadedFile file;

public UploadedFile getFile() {
return file;
}

public void setFile(UploadedFile file) {
this.file = file;
}

public void upload() {
try {

System.out.println("SIZE::" + file.getSize());
System.out.println("FileName"+file.getFileName());
FacesMessage msg = new FacesMessage("Succesful", file.getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, msg);
} catch (Exception e) {
e.printStackTrace();
}

}
}


But the output is nullpointrexception!..
how can i rectify this?..


thanks!..
thumbnail
Johann Kneringer, geändert vor 12 Jahren.

RE: Upload File in jsf 2.0(mojara)

Junior Member Beiträge: 42 Beitrittsdatum: 10.11.11 Neueste Beiträge
it is important, that you make it exactly like in the example...


so use 2 alloyfaces layouts, put in every layout a form with the same id!
thumbnail
Neil Griffin, geändert vor 12 Jahren.

RE: Upload File in jsf 2.0(mojara)

Liferay Legend Beiträge: 2655 Beitrittsdatum: 27.07.05 Neueste Beiträge
There is a new primefaces3-portlet demo available here:
http://www.liferay.com/community/liferay-projects/liferay-faces/demos#primefaces3-portlet

Currently it uses bridge:inputFile to do a full postback type of upload. It doesn't use p:fileUpload yet, but perhaps sometime in the near future after we get the following issue addressed in PrimeFaces:
http://code.google.com/p/primefaces/issues/detail?id=2905
thumbnail
Neil Griffin, geändert vor 11 Jahren.

RE: Upload File in jsf 2.0(mojara)

Liferay Legend Beiträge: 2655 Beitrittsdatum: 27.07.05 Neueste Beiträge
The p:fileUpload component is now working, but you'll need to upgrade to Liferay Faces Bridge 3.0.0-BETA2 (Liferay 6.0.x) or 3.1.0-BETA2 (Liferay 6.1.x)