Topic
  • 1 reply
  • Latest Post - ‏2012-03-12T15:49:23Z by SystemAdmin
saharmohamed
saharmohamed
1 Post

Pinned topic Fileupload with ajax

‏2012-03-12T13:59:00Z |
I am using JSF framework with AJAX technology to upload files to database. I use the "invoke ajax behaviour" on the RAD 7.5 IDE but the value of the file uploaded is always null. Note that eveything works fine without AJAX.

this is the code :

jsp:

<f:view>
<body>
<hx:scriptCollector id="scriptCollector1">
<h:form styleClass="form" id="form1">
<hx:fileupload styleClass="fileupload" id="fileupload1"
value="#{pc_Newattachement.attachfile}">
<hx:fileProp name="fileName" />
<hx:fileProp name="contentType" />
</hx:fileupload>
<hx:commandExButton type="submit" value="add attachement"
styleClass="commandExButton" id="button1" action="#{pc_Newattachement.doButton1Action}">
<hx:behavior event="onclick" id="behavior1" behaviorAction="get" targetAction="group1" onActionFunction="return func_2(this, event);"></hx:behavior>
</hx:commandExButton>

</h:form>
<h:panelGroup styleClass="panelGroup" id="group1"></h:panelGroup>
<hx:ajaxRefreshSubmit onstart="return doSubmitIframe();" target="group1" id="ajaxRefreshSubmit1"></hx:ajaxRefreshSubmit>
</hx:scriptCollector>
</body>
</f:view>

page code for the button:

try {

System.out.println("****************");

System.out.println("getAttachedFile : " + getAttachedFile());
} catch (Exception e) {
e.printStackTrace();
}

return " ";

console :

SystemOut O ****************
SystemOut O getAttachedFile : null
Thanks and regards,
Updated on 2012-03-12T15:49:23Z at 2012-03-12T15:49:23Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    6420 Posts

    Re: Fileupload with ajax

    ‏2012-03-12T15:49:23Z  
    AJAX doesn't support file upload (you cannot submit a file as part of an ajax submit).

    People usually workaround this limitation of AJAX using iframes (which has been discussed before in this forum).