4 Replies Latest reply on Apr 14, 2010 11:47 PM by sej

    file uploader

      I am trying to add a file uploader control to a page.  I've changed the form tag to:

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

      and I've added this tag:

      <s:fileUpload id="file" data="#{searchAction.search.data}" fileName="#{searchAction.search.fileName}" />

      There is a submit button:

      <h:commandButton action="#{searchAction.searchIt}" id="btnSearch" value="Search" styleClass="button primaryAction searchButton"/>

      It used to go through searchIt() when you clicked the submit button, but now it does not.  Any idea why?

      in components.xml I've added:


      http://jboss.com/products/seam/web http://jboss.com/products/seam/web-2.0.xsd

      <web:multipart-filter create-temp-files="true"
                            url-pattern="*.seam" />

      in web.xml I have added:

            <filter-name>Seam Filter</filter-name>
            <filter-name>Seam Filter</filter-name>
        • 1. Re: file uploader

          Did you check the Console after serverstart? Maybe there is an error on startup?
          If not, can you clear the console before you click the button, then click the button and post the output please.
          Helpful are some more informations too (source of xhtml, searchAction..)

          • 2. Re: file uploader
            There were no errors in the console after server start, and nothing shows up in the console when clicking submit.

            Here is the search.xhtml page (I've temporarily removed search parameters and search results while I try to get the file uploader to work):

            <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

            <ui:composition xmlns="http://www.w3.org/1999/xhtml"

            <ui:param name="page" value="search" />
            <ui:define name="body">
            <h:form enctype="multipart/form-data" >

            <s:fileUpload id="file" data="#{searchAction.search.data}" fileName="#{searchAction.search.fileName}" />


            <s:decorate id="errorMsg" >
                 <h:messages showDetail="true" showSummary="false" styleClass="alert"/>

            <fieldset class="columns onecol">
                 <legend>Search Criteria</legend>
                 <s:decorate template="/layout/edit.xhtml" id="memberIdField" >
                      <ui:define name="reqd" ><strong class="required">*</strong></ui:define><ui:define name="label" >Member ID</ui:define>
                 <p class="actions" style="border-top: 1px solid #ffffff; margin: 0; padding: 0;">
                 <h:commandButton action="#{searchAction.searchIt}" id="btnSearch" value="Search" styleClass="button primaryAction searchButton"/>




            package com.mbh.esln.sejClient.domain.session;

            import java.util.List;

            import javax.faces.context.ExternalContext;
            import javax.faces.context.FacesContext;

            import org.jboss.seam.ScopeType;
            import org.jboss.seam.annotations.In;
            import org.jboss.seam.annotations.Name;
            import org.jboss.seam.annotations.Out;
            import org.jboss.seam.annotations.Scope;
            import org.jboss.seam.annotations.web.RequestParameter;
            import org.jboss.seam.contexts.Contexts;
            import org.jboss.seam.international.StatusMessages;

            import javax.persistence.EntityManager;
            import javax.servlet.ServletOutputStream;
            import javax.servlet.http.HttpServletResponse;

            import com.mbh.esln.sejClient.domain.Search;
            import com.mbh.esln.sejClient.sqlmaps.Constants;

            public class SearchAction {
                 private Search search = new Search();
                 private List<Search> searchList = null;

                 @In(required=false) @Out(scope=ScopeType.SESSION, required=false)
                 private String memberIdSearch;
                 @In(required=false) @Out(scope=ScopeType.SESSION, required=false)
                 private byte[] theFile;
                 private int time1;

                 @Out(scope=ScopeType.SESSION, required=false)
                 private String fileName;

                 @Out(scope=ScopeType.SESSION, required=false)
                 private byte[] data;

                 private EntityManager entityManager;
                 private Long attachmentId;
                 private ExternalContext extCtx;
                 @In String clientToken;

                 StatusMessages statusMessages;
                 public void leaveApp(){
                      String url = Constants.CLAIMS_APPS_URL;
                      try {
                           FacesContext facesContext = FacesContext.getCurrentInstance();
                           ExternalContext externalCtx = facesContext.getExternalContext();
                      } catch (Exception e) {

                 public void searchIt(){
                      System.out.println("you are now in searchIt().");     //not getting here at all
                      Search attachment = entityManager.find(Search.class, attachmentId);
                      HttpServletResponse response = (HttpServletResponse)extCtx.getResponse();
            //          response.setContentType(attachment.getContentType());
                      response.addHeader("Content-disposition", "attachment; filename=\"" + attachment.getFileName() +"\"");
                      try {
                           ServletOutputStream os = response.getOutputStream();
                           System.out.println("getData: " + attachment.getData());
                           FacesContext facesContext = FacesContext.getCurrentInstance();
                      } catch(Exception e) {
                 private boolean isValidMemberId(String value) {
                      if (null == value) {
                           return false;
                      if(value.length() != 13){
                           return false;
                      for(int i = 0; i < 13; i++){
                           String myChar = value.substring(i, i+1);
                           if(!myChar.equals("0") && !myChar.equals("1") && !myChar.equals("2") && !myChar.equals("3") && !myChar.equals("4") && !myChar.equals("5") && !myChar.equals("6") && !myChar.equals("7") && !myChar.equals("8") && !myChar.equals("9")){
                                return false;
                      return true;

                 public String closeSession(String myPage){
            //          search = new Search();
            //          searchList = null;
                      return "/" + myPage + ".xhtml";
                 public List<Search> getSearchList(){
                      return searchList;
                 public Search getSearch() {
                      return search;

                 public void setSearch(Search search) {
                      this.search = search;

                 public String getMemberIdSearch() {
                      return memberIdSearch;

                 public void setMemberIdSearch(String memberIdSearch) {
                      this.memberIdSearch = memberIdSearch;

                 public void setSearchList(List<Search> searchList) {
                      this.searchList = searchList;

                 public int getTime1() {
                      return time1;

                 public void setTime1(int time1) {
                      this.time1 = time1;

                 public byte[] getTheFile() {
                      return theFile;

                 public void setTheFile(byte[] theFile) {
                      this.theFile = theFile;

                 public byte[] getData() {
                      return data;

                 public void setData(byte[] data) {
                      this.data = data;

                 public String getFileName() {
                      return fileName;

                 public void setFileName(String fileName) {
                      this.fileName = fileName;

                 public EntityManager getEntityManager() {
                      return entityManager;

                 public void setEntityManager(EntityManager entityManager) {
                      this.entityManager = entityManager;

                 public Long getAttachmentId() {
                      return attachmentId;

                 public void setAttachmentId(Long attachmentId) {
                      this.attachmentId = attachmentId;

                 public ExternalContext getExtCtx() {
                      return extCtx;

                 public void setExtCtx(ExternalContext extCtx) {
                      this.extCtx = extCtx;
            • 3. Re: file uploader

              I would check if that search.data available where you trying to put your file data + also try to use the contentType attribute e.g.:

                  id="image" data="#{yourHome.yourImage}" 

              • 4. Re: file uploader
                the <s:fileUpload> tag does not appear to have any effect on it, because if I remove it completely, and only have the enctype attribute added to the form tag, it still does not go through the searchIt().  So there is something about the enctype attribute that is causing this.