FileUpload Primfaces
Publicado por Karina Yanez (1 intervención) el 18/03/2015 22:39:50
Buenas tarde tengo un problema espty trabajando con jpa y primface en el entrono Neatbeans y postgres lo que yo necesito es guardar la url en la base de datos como string y copiar el archivo al lado del servidor para eso ya desarrolle pero el problema es k no me coge e event del FILEUPLOAD ayudenemen en eso les dejo el codigo
Formulario
LO que tengo en el Controlador
en total el path es la url pero me da problema en el public void handleFileUpload(FileUploadEvent event1)
puntero en null ....
gracias x su ayuda
Formulario
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<h:form enctype="multipart/form-data" >
<p:messages id="messages" autoUpdate="true" closable="true" />
<p:panel header="NUEVA SOLICITUD" style="text-align:center; margin: auto;">
<h:panelGrid columns="2" style="text-align: left; margin-left:35%;" >
<p:outputLabel value="Subir Oficio"/>
<p:fileUpload id="of" value="#{tSolicitudController.event1}" mode="simple" update="messages"/>
<p:commandButton value="Submit" action="#{tSolicitudController.handleFileUpload}" />
</h:panelGrid>
</p:panel>
</h:form>
LO que tengo en el Controlador
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
public void handleFileUpload(FileUploadEvent event1) {
try {
var = save(event1);
FacesMessage message = new FacesMessage("Succesful", event1.getFile().getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, message);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public String save(FileUploadEvent event1) throws Exception {
String path="Sin descrpcion";
try{
SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMddHHmmss");
String name = fmt.format(new Date())
+ event1.getFile().getFileName().substring(
event1.getFile().getFileName().lastIndexOf('.'));
aux=name;
path = "d:\\tmp\\" + name;
File file = new File(path);
InputStream is = event1.getFile().getInputstream();
OutputStream out = new FileOutputStream(file);
byte buf[] = new byte[1024];
int len;
while ((len = is.read(buf)) > 0) {
out.write(buf, 0, len);
}
}catch(Exception ex){
ex.printStackTrace();
}
return (path);
}
en total el path es la url pero me da problema en el public void handleFileUpload(FileUploadEvent event1)
puntero en null ....
gracias x su ayuda
Valora esta pregunta


0