Action method not called in Backing Bean
I am using <x:inputFileUpload> tag inside my jsp page. I am trying to call action method when clicking button, but action method not called.
My jsp page:
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://myfaces.apache.org/extensions" prefix="x"%>
<html>
<head>
<title>File upload Test</title>
</head>
<body>
<f:view>
<h:form id="form1" enctype="multipart/form-data">
<h:messages id="asdghsda"/>
<h:outputText value="This is file upload page functionlaity POC" />
<h:inputText value="#{fileUploadBean.textField}" />
<x:inputFileUpload id="myFileId" value="#{fileUploadBean.myFile}" storage="file" required="true"/>
<h:commandButton action="#{fileUploadBean.storeFile}" value="Enter here" />
<h:commandLink value="Clicl Here!!" action="#{fileUploadBean.storeFile}"></h:commandLink>
</h:form>
</f:view>
</body>
</html>
My backing bean:
package com.beans;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.log4j.Logger;
import org.apache.myfaces.custom.fileupload.UploadedFile;
public class FileUploadBean {
private static Logger logger = Logger.getLogger(FileUploadBean.class.getName());
private String textField;
private UploadedFile myFile;
public UploadedFile getMyFile() {
logger.info("inside get method");
return myFile;
}
public void setMyFile(UploadedFile myFile) {
logger.info("inside set method");
this.myFile = myFile;
}
public void storeFile(){
logger.info("Inside the storeFile method");
logger.info("The text field value: " + getTextField());
try {
InputStream in = new BufferedInputStream(myFile.getInputStream());
logger.info("The string is: " + in.read());
System.out.println(in.read());
File f = new File("D:\\share\\sample.txt");
OutputStream out = new FileOutputStream(f);
out.write(in.read());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
logger.info("Exit from the storeFile method");
}
public String getTextField() {
return textField;
}
public void setTextField(String textField) {
this.textField = textField;
}
}
My web.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>MyJSFProject</display-name>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<filter>
<filter-name>ExtensionsFilter</filter-name>
<filter-class>org.apache.myfaces.component.html.util.ExtensionsFilter</filter-class>
<init-param>
<param-name>uploadMaxFileSize</param-name>
<param-value>10m</param-value>
</init-param>
<init-param>
<param-name>uploadThresholdSize</param-name>
<param-value>100k</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>ExtensionsFilter</filter-name>
<servlet-name>FacesServlet</servlet-name>
</filter-mapping>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
</web-app>
Can someone help me on this? I need urgently.

