I finally figured this out, so  I'm going to put an entire example in this
post.  I'm using Tomahawk 1.1.3 with RI JSF created in Borland's JBuilder. 
I've created a .war file from borland and deployed it under Tomcat 5.5 so it
should be Borland independent.  The problems I was having previously were in
trying to deploy Tomahawk on a old JSF project. I'm pretty sure I'm safe in
saying you must use JSP 2.0 and Servlet 2.4 as a minimum.

inputFileUpload/Tomahawk specific elements are bold/italic

In the backing bean WelcomeBean.java, I only read the uploaded file into a
byte [].  In my personal application, I simply insert the byte [] into an
Oracle BLOB.  You may need to write it to a file.  I'll assume you know how
to do that.

I think that's pretty much it.  If you have any questions please respond to
this post.  I'll receive an e-mail and try to help.  If you want to know how
to implement Tomahawk 1.1.3 into Borland's JBuilder, I can help with that
also I believe.

Doug

Required libraries for this minimal project

commons-beanutils.jar
commons-collections.jar
commons-digester.jar
commons-fileupload.jar
commons-logging.jar
jsf-api.jar
jsf-impl.jar
jstl.jar
standard.jar
tomahawk-1.1.3.jar

index.jsp

<html>
<html>
<head>
<title>index</title>
</head>
<body bgcolor="#ffffc0">
<h1></h1>
<jsp:forward page="Welcome.faces"></jsp:forward>
</body>
</html>

Welcome.jsp

<[EMAIL PROTECTED] uri="http://java.sun.com/jsf/html"; prefix="h"%>
<[EMAIL PROTECTED] uri="http://java.sun.com/jsf/core"; prefix="f"%>
<%@ taglib uri="http://myfaces.apache.org/tomahawk"; prefix="t" %>
<html>
<head>
<title>index</title>
</head>
<body bgcolor="#ffffff">
<h1>GoHurst Welcome</h1>
<f:view>
  <h:form id="welcomeForm" enctype="multipart/form-data">
    <t:panelGrid columns="3">
    <t:inputFileUpload id="uFile" value="#{WelcomeBean.theFile}"
storage="file" required="true" />
    </t:panelGrid>
    <h:panelGrid columns="3">
    <h:commandButton id="onlyButton" action="#{WelcomeBean.fmWelcome}"
value="Click here to Upload"/>
    </h:panelGrid>
  </h:form>
</f:view>
</body>
</html>

WelcomeBean.java

package tomahawkfileupload;

import java.io.File;
import java.io.InputStream;
import javax.servlet.http.HttpSession;
import javax.faces.context.FacesContext;
import org.apache.myfaces.custom.fileupload.UploadedFile;

public class WelcomeBean
{
    private UploadedFile theFile;

    public UploadedFile getTheFile() {
      return theFile;
    }

    public void setTheFile (UploadedFile theFile) {
      this.theFile = theFile;
    }

    public String fmWelcome()
    {
        FacesContext context = FacesContext.getCurrentInstance();
        HttpSession session = (HttpSession)
context.getExternalContext().getSession(false);
        try {
          InputStream stream = theFile.getInputStream();
          long fSize = theFile.getSize();
          byte [] buffer = new byte[(int)fSize];
          stream.read(buffer, 0, (int)fSize);
          stream.close();
        } catch (Exception ioe) {
           ioe.printStackTrace(); 
        }
        return "success";
    }
}


web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app 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"; version="2.4">
  <display-name>TomaModule</display-name>
  <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>*.faces</url-pattern>
  </servlet-mapping>
  <filter>
    <filter-name>MyFacesExtensionsFilter</filter-name>
   
<filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
    <init-param>
      <param-name>maxFileSize</param-name>
      <param-value>20m</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>MyFacesExtensionsFilter</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
  </filter-mapping>
  <filter-mapping>
    <filter-name>MyFacesExtensionsFilter</filter-name>
    <url-pattern>/faces/myFacesExtensionResource/*</url-pattern>
  </filter-mapping>
</web-app>


faces-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer
Faces Config 1.1//EN" "http://java.sun.com/dtd/web-facesconfig_1_1.dtd";>
<faces-config xmlns="http://java.sun.com/JSF/Configuration";>
  <managed-bean>
    <managed-bean-name>WelcomeBean</managed-bean-name>
    <managed-bean-class>tomahawkfileupload.WelcomeBean</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
  </managed-bean>

  <navigation-rule>
    <from-view-id>*</from-view-id>
    <navigation-case>
      <from-action>#{WelcomeBean.fmWelcome}</from-action>
      <from-outcome>success</from-outcome>
      <to-view-id>/Welcome.jsp</to-view-id>
    </navigation-case>
    <navigation-case>
      <from-action>#{WelcomeBean.fmBicycle}</from-action>
      <from-outcome>bypass</from-outcome>
      <to-view-id>/Welcome.jsp</to-view-id>
    </navigation-case>
  </navigation-rule>
</faces-config>

-- 
View this message in context: 
http://www.nabble.com/Tomahawk-1.1.3-inputFileUpload-solution-tf2318350.html#a6449010
Sent from the MyFaces - Users mailing list archive at Nabble.com.

Reply via email to