File Upload problem: JSF, IBM WPS and Portlet - Please HELP Vey Very Urgent

I want to upload a file from the front end using JSF and Portlets deployed on IBM WebSphere Portal.
I have used Apache's commons file upload functionality as the file upload provided in JSF doesnot work with portlets and the action event is not invoked If I keep enctype="multipart/form-data". So I included 3 forms in my Faces JSP file.
1) h:form = For displyign error message on screen
2) html:form = Include the enctype="multipart/form-data" and the input type file for uploading. And a submit button
3) h:form: Here I have a command link which is remotely excuted on click of sumit button in my html form. This is to invoke the action event in the pagecode to get the bean value from the context.
Now in the my doView method in the portlet, isMultipartContent(httpservletrequest) always returns null as the content type is text/html and not multipart. Onclick of the submit button in the the html form I am calling a javascript function which sets the __LINK_TARGET__ to the command link in the 3rd h:form which will call the page code.
The problem here is action is invoked only when I return false from the above javascript else it will trigger for the first time and from second time onwards it will not invoke the action event in the pagecode method. Whent the javascript function returns false, the content type is always text/html. However if I return "true" from the javascript the content type is multipart/form-data, but the action is not triggered for the second time. So basically when the javascript functions returns true, for the first click everything works perfectly. When it returns false, the content type is text/html, but the action is invoked in the page code every time.
Returning always true would solve my problem with the content type, but the action with the command link will not get invoked always as its some type of problem with h:commanLink :(.
I guess I gave too much info. Heres my code stepby step.
Can somebody please tell me , how I should also invoke the action in the page code and get the content type as "multipart/form-data" at the same time.
1:
======================= Faces JSP File: BPSMacro.jsp ====================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="GENERATOR" content="IBM Software Development Platform">
<meta http-equiv="Content-Style-Type" content="text/css">
<%@taglib uri="http://java.sun.com/portlet" prefix="portlet"%>
<%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt"%>
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@taglib uri="http://www.ibm.com/jsf/html_extended" prefix="hx"%>
<%@taglib uri="/WEB-INF/tld/j4j.tld" prefix="j4j"%>
<%@taglib uri="/WEB-INF/tld/core.tld" prefix="core"%>
<%@page language="java" contentType="text/html; charset=ISO-8859-1"
     pageEncoding="ISO-8859-1" session="false"%>
<portlet:defineObjects />
<link rel="stylesheet" type="text/css"
     href='<%= renderResponse.encodeURL(renderRequest.getContextPath() + "/theme/stylesheet.css") %>'
     title="Style">
<script type="text/javascript">
function formSubmit() {
     var formName2 = document.getElementById("proxy_form_main_").title;
     var formName1 = document.getElementById("BPSMacroFormId").title;
     document.getElementById("__LINK_TARGET__").value = document.getElementById("proxy_HD_COMMAND_").title;
     document.getElementById(formName2).submit();
     return false;
</script>
<f:view>
     <hx:scriptCollector id="bpsMacroScriptCollector">
          <f:loadBundle var="bps" basename="bordereauprocessingsystem" />
          <table bgcolor="#FFF9C3">
               <tr>
                    <td><h:form id="BPSMacroFormMain" styleClass="form">
                         <table class="tablemiddle" cellspacing="0" cellpadding="0">
                              <tr>
                                   <td><h:messages layout="table" styleClass="errormessage"
                                             id="ValidationErrorMsg" /> </td>
                              </tr>
                         </table>
                         <j4j:idProxy id="proxy_form_main_0_" />
                    </h:form></td>
               </tr>
               <tr>
                    <td>
                    <form id="BPSMacroFormId" enctype="multipart/form-data">
                    <table bgcolor="#FFF9C3">
                         <tr>
                              <td height="36" width="324">Worksheet <input type="file"
                                   name="upfile" /></td>
                         </tr>
                              <tr>
                                   <td align="center" width="324"><input TYPE="submit"
                                   onclick="return formSubmit();" value="Upload">
                              </td>
                         </tr>
                    </table>
                    </form>
                    </td>
               </tr>
               <tr>
                    <td>
                    <h:form id="BPSMacroFormMain2" styleClass="form">
                         <table cellspacing="2" cellpadding="2" class="tablemiddle">
                              <tbody>
                                   <tr>
                                        <td colspan="2" align="center"><h:commandLink
                                             styleClass="commandLink" id="lnkuserdelete"
                                             action="#{pc_BPSMacro.doIdUpload1Action}">
                                             <hx:graphicImageEx
                                                  styleClass="graphicImageEx" id="imgBtnCreateUser"
                                                  value="/theme/images/btnUpload.gif" style="border:0;cursor:pointer"></hx:graphicImageEx>
                                             <j4j:idProxy id="proxy_HD_COMMAND_" />
                                        </h:commandLink></td>
                                        <h:inputHidden id="dtSize"
                                             value="#{pc_BPSMacro.fileDetailsList.clicked}">
                                             <j4j:idProxy id="proxy_clicked_" />
                                        </h:inputHidden>
                                   </tr>
                              </tbody>
                         </table>
                         <j4j:idProxy id="proxy_form_main_" />
                    </h:form>
               </td>
               </tr>
          </table>
     </hx:scriptCollector>
</f:view>
================== END: FACES JSP FILE: BPSMacro.jsp ========================
2:
=================== Action event in the Page Code: BPSMacro.java ============
public String doIdUpload1Action() {
          System.out.println("PageCode");
          FacesContext context = FacesContext.getCurrentInstance();
          BPSMacroDetailsDataBean fileDetails = (BPSMacroDetailsDataBean)context.getApplication().createValueBinding("#{fileDetails}").getValue(context);
          BPSMacroListDataBean fileDetailsList = (BPSMacroListDataBean)context.getApplication().createValueBinding("#{fileDetailsList}").getValue(context);
          PortletSession sess = (PortletSession)context.getExternalContext().getSession(false);
          sess.setAttribute("BPS_MACRO_CONTEXT", context, PortletSession.APPLICATION_SCOPE);
          sess.setAttribute("BPS_MACRO_FILE_DETAILS", fileDetails, PortletSession.APPLICATION_SCOPE);
          sess.setAttribute("BPS_MACRO_FILE_LIST", fileDetailsList, PortletSession.APPLICATION_SCOPE);
          HttpServletRequest request = (HttpServletRequest)context.getExternalContext().getRequest();
          boolean isMultipart = ServletFileUpload.isMultipartContent(request);
          request.getContentType();
          return "gotoBPSMacro";
============== END Of Page Code Action event ==============================
3:
============== doView() Portlet method ================================
public void doView(RenderRequest arg0, RenderResponse arg1)
     throws PortletException, IOException {
          String METHOD_NAME = "doView(RenderRequest arg0, RenderResponse arg1)";
          Logger.debug(this.getClass(), METHOD_NAME, "Entering BPSMacroPortlet");
          FacesContext context = FacesContext.getCurrentInstance();      
          PortletSession sess1 = arg0.getPortletSession(true);
          BPSMacroDetailsDataBean fileDetails = new BPSMacroDetailsDataBean();
          BPSMacroListDataBean fileDetailsList = new BPSMacroListDataBean();
          context = (FacesContext)sess1.getAttribute("BPS_MACRO_CONTEXT", PortletSession.APPLICATION_SCOPE);
          if(context != null){
               fileDetails = (BPSMacroDetailsDataBean)sess1.getAttribute("BPS_MACRO_FILE_DETAILS", PortletSession.APPLICATION_SCOPE);
               fileDetailsList = (BPSMacroListDataBean)sess1.getAttribute("BPS_MACRO_FILE_LIST", PortletSession.APPLICATION_SCOPE);
          sess1.removeAttribute("BPS_MACRO_CONTEXT", PortletSession.APPLICATION_SCOPE);
          sess1.removeAttribute("BPS_MACRO_FILE_DETAILS", PortletSession.APPLICATION_SCOPE);
          sess1.removeAttribute("BPS_MACRO_FILE_LIST", PortletSession.APPLICATION_SCOPE);
          HttpServletRequest servletRequest = (HttpServletRequest)arg0;
          PortletRequest pReq = (PortletRequest)arg0;
          HttpServletResponse servletResponse= (HttpServletResponse)arg1;
          System.out.println("\n\n Content Type" + servletRequest.getContentType());
          try{
               if(context != null){
          boolean isFileMultipart = ServletFileUpload.isMultipartContent(servletRequest);
          System.out.println("\nFILE TO BE UPLOADED IS MULTIPART ? " + isFileMultipart);
          if(isFileMultipart){
               FileItemFactory factory = new DiskFileItemFactory();
               ServletFileUpload upload = new ServletFileUpload(factory);
               List items = upload.parseRequest(servletRequest);
               Iterator iterator = items.iterator();
               while (iterator.hasNext()) {
                    FileItem item = (FileItem) iterator.next();
                    InputStream iStream = item.getInputStream();
                    ByteArrayOutputStream ByteArrayOS = new ByteArrayOutputStream();
                    int sizeofFile =(int) item.getSize();
                    byte buffer[] = new byte[sizeofFile];
                    int bytesRead = 0;
                    while( (bytesRead = iStream.read(buffer, 0, sizeofFile)) != -1 )
                         ByteArrayOS.write( buffer, 0, bytesRead );
                    String data = new String( ByteArrayOS.toByteArray() );
                    int k = 0;
                    //Check if the file is Refund or Premium
                    int dynamicArraySize = 0;// = st2.countTokens() * 9;
                    dynamicArraySize = st2.countTokens() * 9;
                    if (!item.isFormField() ){
                         File cfile=new File(item.getName());
                         String fileName = "";
                         String separator = "\\";
                         int pos = item.getName().lastIndexOf(separator);
                         int pos2 = item.getName().lastIndexOf(".");
                         if(pos2>-1){
                              fileName =item.getName().substring(pos+1, pos2);
                         }else{
                              fileName =item.getName().substring(pos+1);
                         File fileToBeUploaded=new File("C:\\Sal\\BPS MACRO\\FileTransfer\\Desti", fileName);
                         item.write(fileToBeUploaded);
                         validate.displaySuccessMessage(context);
          }catch(Exception e){System.out.println(e);
          Logger.debug(this.getClass(), METHOD_NAME, "Leaving BPSMacroPortlet");
          super.doView(arg0, arg1);
==== END: doView method in the portle class. ================================
Thanks.

one more question. Is there a way where I can submit two forms ?
Thats is submit 2nd form only when the first form is submitted.
I tried this it works.
function formSubmit(){
document.form1.submit();
alert();
document.form2.submit();
But If I dont put an alert(basically it disables the parent page) in between, only the second form is submitted.
If I put a delay of say 3 seconds in between then it will throw a SOCKET CLOSED error in the code triggered due to first form submit.
Thus disabling the paresnt page for a few seconds is reolving my problem.
Any ideas ?
Well Basically when the Alert pop's up the parent page "STALLS" and thus the form2 does not submit till I click on OK, Is there a way I can stall the browser/Parent JSP page using JAVA SCRIPT ??
Edited by: hector on Oct 9, 2007 11:09 AM
Edited by: hector on Oct 9, 2007 2:12 PM

Similar Messages

  • Problems with disk permissions and others - Please help

    I recently updated to 10.5.8. When I open GoLive 6 i just get the spinning ball of death. When I try and run disk permissions it just scrolls and scrolls "reading permissions database and does nothing. I am on an iBook G4 1.33 and the system always seems to be dragging. Please help.
    Message was edited by: Marcus MacColonna

    HI Marcus,
    the system always seems to be dragging
    Check to see how much available space there is on the startup disk. Right or control click the MacintoshHD icon. Click Get Info. In the Get Info window you will see Capacity and Available. *Make sure you always have a minimum of 15% free disk space.*
    If free disk space isn't an issue, help here for the SSBOD
    Carolyn

  • Problem with CMP bean and MySQL: please help me!!!

    Hi,
    I am using J2EE Sun server 1.3 and Mysql 4.0 database with its MySQL Connector/J 3.0.
    The driver connection to the database is fine since "Generate Default SQL" in deploytool gives "SQL generation complete".
    However, I can't have a simple row with one text field called test being created in my mysql table called test.
    Of course , the mysql server is started and the test table set for use.
    Here is my code (I try to access my database from a servlet using a CMP Entity bean):
    try{
    Context initial = new InitialContext();
    Object objref = initial.lookup(EntityHome.JNDI_NAME);
    EntityHome home = (EntityHome)PortableRemoteObject.narrow(objref,EntityHome.class);     
    Entity test= home.create("zob");               
    /*EntityHome home = (EntityHome)PortableRemoteObject.narrow(objref,EntityHome.class);     
    catch (Exception ex){                                                                out.println("exception message : " + ex.getMessage()+"</body></html>");}
    I get the following exception message :
    RemoteException occurred in server thread; nested exception is: java.rmi.RemoteException: nested exception is: java.sql.SQLException: Syntax error or access violation, message from server: "You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '"EntityCMPTable" WHERE "test" = 'zob'' at line 1"; nested exception is: java.sql.SQLException: Syntax error or access violation, message from server: "You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '"EntityCMPTable" WHERE "test" = 'zob'' at line 1"
    I would be very grateful for help since I have a close deadline for this!!!!!!!!
    Thank you very much in advance dear java experts!!!!!!!
                                       

    Hallo
    I have the same problem and the same configuration.
    Do you have a solution for this problem ??
    Thanks
    Georg

  • Big problems with Firewire iPod and camcorder  - please help!

    Hi all,
    I don't know where else to turn with this problem. I think I've damaged my Firewire kit.
    I have an iPod 4G 20GB and a Canon MV901 MiniDV Camcorder. I used them both over Firewire with my Pismo without difficulty, but I then tried video editing on my Windows machine with a firewire PCI card. Scrabbling around the back of my computer, I think I somehow managed to get the firewire cable to the camcorder in the socket upside down, reversing the power and data conncectors. Nothing really happened, but the camcorder stopped showing up. I tried it a good few times, then tried my iPod. By some bizarre coincidence, I think I managed to plug the iPod in the same way. Now, my iPod doesn't work on either the Windows machine or the Pismo over firewire, but does over USB2.0 on my Windows machine.
    I measured the power going through the Firewire power pins as around 13.5 volts on my Pismo and the card, but the card also has an auxiliary power connector. This was disconnected when I tested it, but was connected when the iPod and camcorder were.
    The thing I would like to know is whether a voltage spike of this size could fry the firewire controllers on both devices. The iPod's diagnostic mode detects that firewire is connected, but will not show up. Strangely, it still charges over firewire from either machine. Have I permanately damaged the firewire controllers?
    Thanks in advance,
    Rob Johnson

    Rob,
    If you mistakenly inserted the FireWire connector twisted 180 degrees, the power lines can be directly connected to the data lines and can result in a fried PHY (connects the port to the FireWire bridge) or the FireWire bridge itself.
    You can take a look at the voltage specs for FireWire ports and see that your voltage readings are well withing specs:
    http://docs.info.apple.com/article.html?artnum=58207
    I am not sure where you go from here. You could try a known-good FireWire device connected to your Pismo and see if it works. If not, the data-side of the FW port may have failed. I don't know about testing the iPod or camcorder.
    A possible cheap fix for the Pismo FireWire is a FireWire PC card; if running 10.x, it will just be a plug & play affair. However, unlike built-in FireWire ports, FireWire PC cards supply very little bus power. Your camcorder will work since it has it owns power supply (assuming there is no hardware failure) and but am unsure about the iPod. The iPod will not charge, of course, but it may still work in data transfers. There are a few FireWire PC cards that also have their own power supply.

  • File Upload Problem from Linux to Windows and Windows to Linux

    Hi,
    I am a newbie in the flex environment.
    I have faced a problem for file upload from linux to windows and windows to linux
    And I have put crossdomain.xml file in root folder, still this problem is appear.
    Please help me, if anybody know the answer.
    Thanks and Regards,
    Senthil KUmar

    Hi Pauley,
    I thought you are moving from unix to windows. Now I got it.
    Make sure that the folder is shared and have necessary permissions. Please see few suggestions here:
    Re: NFS or FTP for file on Ip 10.x.y.z
    Regards,
    ---Satish

  • Hello Guys. I had problems in the Computer before and changed my HD. I saved in my all files documents in (Time Capsule). How can I put all my files, pictures documents on my new HD? Please Help. Thank You

    Hello Guys.
    I had problems in the Computer before and changed my HD. I saved in my all files documents in (Time Capsule). How can I put all my files, pictures documents on my new HD?
    Please Help.
    Thank You
    Julio Skov

    Hey
    Thank you very much for replay.
    Would you explain to me how can I do?
    I don't really understand these processes.
    Thak you very much
    Julio

  • While opening pdf files the menu bar, navigation bar  cracks unobviously and also close and minimise buttons  goes hidden..Facing the problem for last one month. Please help.

    while opening pdf files the menu bar, navigation bar  cracks unobviously and also close and minimise buttons  goes hidden..Facing the problem for last one month. Please help.

    The latest Kaspersky software version is 15.0.1.415 or 15.0.1.415ab.

  • Problem opening mail attachments...were opening seamlessly on os 7.0...get an error   Filename Office open XML document/presentation File size   Does anyone have a solution? Please help.

    problem opening mail attachments...were opening seamlessly on os 7.0...get an error
    Filename
    Office open XML document/presentation
    File size
    Does anyone have a solution? Please help.

    Hi Charlotte,
    You don't say what your version of Windows you have. Assuming XP, go to Start | Run, type DXDIAG and click OK. Click the Sound tab and run the tests to eliminate a hardware problem first of all. If you don't hear anything, check your cables first of all. Also make sure "Mute" isn't checkmarked in your sound setup. You'll find that in Windows Control Panel.
    Which browser do you use? If you have Firefox 4, sign up to the HTML5 trial @ http://www.youtube.com/html5
    HTML5 is the latest video standard and doesn't require Flash player. Google is in the process of converting all its files to work with the new format. It may solve you problem. If you don't have Firefox 4, you can get it from here: http://www.mozilla.com/en-US/firefox/fx/
    IE8 doesn't support HTML5.
    To clean out your temp files, go to Start | Run, type: CLEANMGR and click OK. Click OK again to start the utility. Tick all the boxes except "Compress old files" because the latter takes too long, and then click OK. You can run this utility any time you wish by the way.
    The above steps will hopefully fix your problem. If not, post here again please.

  • TS4605 Hi, I was working in WORD on a file containing huge data. My machine just hung up one day while working and now I seem to have lost the file how do I get it back.  Please HELP me.

    Hi, I was working in WORD on a file containing huge data. My machine just hung up one day while working and now I seem to have lost the file how do I get it back.  Please HELP me.

    Well, iCloud has nothing to do with this.
    Do you have the built-in backup function Time Machine running on your Mac?
    See: http://support.apple.com/kb/ht1427

  • Is it possible to export contacts  from Outlook 2011 for Mac and importing this file back into Mac Address Book.? please reply me its urgent

    Is it possible to export contacts  from Outlook 2011 for Mac and importing this file back into Mac Address Book.? please reply me its urgent

    Is it possible to export contacts  from Outlook 2011 for Mac and importing this file back into Mac Address Book.? please reply me its urgent

  • Until recently I was able to send images in the body of my Yahoo emails. Now, I am getting the message "This message has been truncated", and the email does not go through. I do not have this problem using IE. Could you please help? Thank you.

    Until recently I was able to send images in the body of my Yahoo emails. Now, I am getting the message "This message has been truncated", and the email does not go through. I do not have this problem using IE. Could you please help? Thank you.

    Try this -> http://support.apple.com/kb/TA38632?viewlocale=en_US

  • My iphone 4s wifi and bluetooth problem after updating ios 8? please help me...

    my iphone 4s wifi and bluetooth problem after updating ios 8? please help me...

    Hey there Abdulrahim0259,
    I would recommend that you use the following 2 article to help troubleshoot the Wi-Fi and bluetooth issues you are seeing, respectively:
    iOS: Troubleshooting Wi-Fi networks and connections - Apple Support
    And:
    iOS: Troubleshooting Bluetooth connections - Apple Support
    Thank you for using Apple Support Communities.
    All the very best,
    Sterling

  • My itunes will not open at all. it occasionally will open but when i plug my iphone into it the program freezes and crashes. please help as soon as possible

    my itunes will not open at all. it occasionally will open but when i plug my iphone into it the program freezes and crashes. please help as soon as possible

    i think i might have a solution... i have windows vista and after i installed to latest itunes update everytime i tried to open it it would freeze. I tried everything, including uninstalling itunes and all of its components and reinstalled it numerous times. So i went to the itunes folder in my folders, not on itunes, and i deleted my itunes library and playlists. After that it worked just fine, all of my music was deleted but luckily i had my files saved elsewhere.
    I hope this helped! I know its frustrating and APPLE/ITUNES NEED TO FIX THE PROBLEM!!!!

  • Itunes will not respond to my ipod touch, i have re-installed countless times and it still is not working. i have also tried different USB's and nothing. please help!

    Itunes will not respond to my ipod touch, i have re-installed countless times and it still is not working. i have also tried different USB's and nothing. please help!

    - Try here:
    iOS: Device not recognized in iTunes for Windows
    - Next try a different computer to help determine if you have a computer or iPod problem.

  • I have an old version of InDesign CS5, have not used in a while..about a year.  It will not load nor allow me to uninstall and reinstall, please help.  I have original discs and serial number.  How can I fix this?

      I have an old version of InDesign CS5, have not used in a while..about a year.  It will not load nor allow me to uninstall and reinstall, please help.  I have original discs and serial number.  How can I fix this?

    CS Cleaner Tool for installation problems | CCM, CS6, CS5.5, CS5, CS4, CS3

Maybe you are looking for

  • Import package status with successful when all the data have been rejected

    Dear all,    We use the import package to import some data files. We check that the status is successful , but all the data are rejected. Is it possible to set the status to error when there are reject records in the data file? Best Regards, Jeff

  • Change the size and style of the menu

    How can I change the size and font on the automatically created menu in iWeb? I cannot select it like other text on the site..

  • Code for CO extension

    Hi all, I am trying to enable/disable column for a standard page, In Self Service responsibility->personal information->phone Number->update By Default Number Column is always editable. here i have to customize page like if I select Home fax then num

  • Adobe Illustrator will not install

    When I try to install it, I keep getting a message prompting me to download adobe download manger. I do not know were to get that I thought I already had it since I have other adobe products. i'm using firefox

  • Textutil broken after Safari 3 update?

    I have some scripts that use textutil to convert html files to rtfs. I tried one today & it didn't work -- tried running textutil filename.html -convert rtf from the command line, and after an unusually long wait I eventually got the message "Error r