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.

[4553 byte] By [VijayAMa] at [2007-11-27 4:35:32]
# 1

One straight and simple answer which i can give you method associated to action attributes always returns a java.lang.String Object.

REF :

action:

=====

If specified as a string: Directly specifies an outcome used by the navigation handler to determine the JSF page to load next as a result of activating the button or link If specified as a method binding: The method has this signature: String methodName(); the string represents the outcome

source : http://horstmann.com/corejsf/jsf-tags.html#Table4_15

therefore

change

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");

}

to

public String 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");

return "success";

}

else where you can make use of actionlistener property in the following senario.

but the method signature has to be void storeFile(ActionEvent ae)

and could be use like

<h:commandButton actionlistener="#{fileUploadBean.storeFile}" action="success" value="SUBMIT" />

Hope that might help :)

REGARDS,

RaHuL

RahulSharnaa at 2007-7-12 9:45:36 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Action methods does not explicitly have to return a String. When declared void then this will just issue a postback to the same page.Likely the problem is somewhere else. Do you see something in the server log?
BalusCa at 2007-7-12 9:45:36 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
No i have not got any error message in server log. I have used <h:messages> also to error in page. There also no error message.
VijayAMa at 2007-7-12 9:45:36 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
I am not sure if the taglib is the correct one. All Tomahawk components should be referred by the taglib at uri http://myfaces.apache.org with prefix t. Also see at the bottom of http://myfaces.apache.org/tomahawk/index.html
BalusCa at 2007-7-12 9:45:36 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
I have tried simple jsf without the inputFileUpload tag. My jsf is calling action method. It is working fine. Have someone used <x:inputFileUpload>?
VijayAMa at 2007-7-12 9:45:36 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...