[JBoss Seam] - Re: iceFaces inputFile component
by buddy1974
Ok, I have come a bit closer.
I have created my own Stateful SessionBean, which exposes all the necessary methods...
| package de.ellumination.share.sb;
|
| import java.util.EventObject;
|
| import javax.ejb.Remove;
| import javax.ejb.Stateful;
| import javax.ejb.Stateless;
| import javax.faces.application.FacesMessage;
| import javax.faces.event.ActionEvent;
|
| import org.jboss.seam.annotations.Destroy;
| import org.jboss.seam.annotations.Name;
| import org.jboss.seam.annotations.In;
| import org.jboss.seam.annotations.Logger;
| import org.jboss.seam.log.Log;
| import org.jboss.seam.core.FacesMessages;
|
| import com.icesoft.faces.component.inputfile.InputFile;
| import com.icesoft.faces.webapp.xmlhttp.PersistentFacesState;
| import com.icesoft.faces.webapp.xmlhttp.RenderingException;
|
| @Stateful
| @Name("upload")
| public class UploadBean implements UploadHome
| {
|
| @Logger
| private Log log;
|
| private PersistentFacesState state = null;
|
| @In
| FacesMessages facesMessages;
|
| private int percent = -1;
|
| public UploadBean()
| {
| state = PersistentFacesState.getInstance();
| }
|
| // seam-gen method
| public String uploadPicture()
| {
| // implement your business logic here
| log.info("upload.uploadPicture() action called");
| facesMessages.add("uploadPicture");
| return "success";
| }
|
| public void action(ActionEvent event)
| {
| InputFile inputFile = (InputFile) event.getSource();
| // file has been saved
| if(inputFile.getStatus() == InputFile.SAVED)
| {
| String fileName = inputFile.getFileInfo().getFileName();
| String contentType = inputFile.getFileInfo().getContentType();
| FacesMessages.createFacesMessage(FacesMessage.SEVERITY_FATAL,
| "File uploaded successfully name: #0 content/type: #1", fileName, contentType);
| }
|
| // invalid file, happens when clicking on upload without selecting a
| // file, or a file with no contents.
| if(inputFile.getStatus() == InputFile.INVALID)
| {
| inputFile.getFileInfo().getException().printStackTrace();
| FacesMessages.createFacesMessage(FacesMessage.SEVERITY_FATAL, "Please select a File");
| }
|
| // file size exceeded the limit
| if(inputFile.getStatus() == InputFile.SIZE_LIMIT_EXCEEDED)
| {
| inputFile.getFileInfo().getException().printStackTrace();
| FacesMessages.createFacesMessage(FacesMessage.SEVERITY_FATAL, "File too big");
| }
|
| // indicate that the request size is not specified.
| if(inputFile.getStatus() == InputFile.UNKNOWN_SIZE)
| {
| inputFile.getFileInfo().getException().printStackTrace();
| FacesMessages.createFacesMessage(FacesMessage.SEVERITY_FATAL, "Filesize unknown");
|
| }
| }
|
| @Destroy
| @Remove
| public void destroy()
| {
| }
|
| public String getPercent()
| {
| return Integer.toString(percent);
| }
|
| public void progress(EventObject event)
| {
| InputFile file = (InputFile) event.getSource();
| percent = file.getFileInfo().getPercent();
| try
| {
| if(state != null)
| {
| state.render();
| }
| }
| catch (RenderingException e)
| {
| log.error("Unable to render progress", e);
| }
| }
|
| // add additional action methods
|
| }
|
and configuring my facelet page like so:
| <h:form>
| <table border="5" cellpadding="15">
| <tr>
| <td>
| <ice:inputFile style="border:none; width:400px; height:70px;" progressListener="#{upload.progress}" actionListener="#{upload.action}" label="lads hoch"/>
| </td>
| </tr>
| <tr>
| <td>
| <ice:inputFile/>
| </td>
| </tr>
| <tr>
| <td>
| <ice:outputProgress id="pro" value="#{upload.percent}"/>
| </td>
| </tr>
| </table>
| </h:form>
|
the second input item, and the borders ar just fpr debugging purposes. But the problem is, that the inputfile component tries to create an iframe, which should be loaded from uploadHtml of course there is no such page.
Is there something I am missing?
Here is the generated html code
| <form action="iceSubmit('_id18');" context_type="class com.icesoft.faces.context.BridgeFacesContext" enctype="application/x-www-form-urlencoded" id="_id18" method="post" onsubmit="return false;" style="">
| <input name="_id18" type="hidden" value="_id18"></input>
| <input name="icefacesCssUpdates" type="hidden" value=""></input>
| <input name="viewNumber" type="hidden" value="1"></input>
| <input name="icefacesID" type="hidden" value="zvus_a9YRw5_dCgr8r_kzQ"></input>
| <table border="5" cellpadding="15">
| <tr>
| <td>
| <table id="_id18:_id22" style="border:none; width:400px; height:70px;">
| <tbody>
| <tr>
| <td id="uploadTd" style="height:60px;">
| <iframe class="iceFileUpload" frameborder="0" height="60" name="fileUpload_id18:_id22" src="/share/uploadHtml?fileUploadComponentId=fileUpload_id18:_id2211008164&disabled=false&inputTextClass=iceFileUploadText&buttonClass=iceFileUploadButton&label=lads hoch&uniqueFolder=true&cssFile=./xmlhttp/css/xp/xp.css" style="border:none; width:400px; height:70px;" width="400">
| </iframe>
| </td>
| </tr>
| <tr>
| <td id="detailTd" style=""></td>
| </tr>
| </tbody>
| </table>
| </td>
| </tr>
| <tr><td><table id="_id18:_id25" style="border:none; width:400px; height:50px; padding-top:0px;"><tbody><tr><td id="uploadTd" style="height:60px;"><iframe class="iceFileUpload" frameborder="0" height="60" name="fileUpload_id18:_id25" src="/share/uploadHtml?fileUploadComponentId=fileUpload_id18:_id256115998&disabled=false&inputTextClass=iceFileUploadText&buttonClass=iceFileUploadButton&label=Upload&uniqueFolder=true&cssFile=./xmlhttp/css/xp/xp.css" style="border:none; width:400px; height:50px; padding-top:0px;" width="400"></iframe></td></tr>
| <tr><td id="detailTd" style=""></td></tr></tbody></table></td></tr>
| <tr><td><table border="0" cellpadding="0" cellspacing="0" class="iceOutputProgress" id="_id18:pro" style=""><tbody><tr><td><div class="iceOutputProgressBackground" style="position:relative;"><div class="iceOutputProgressFill" id="_id18:probar" style="position:absolute;width:0%;"></div>
| <div class="iceOutputProgressText" style="text-align:center;position:relative;background-color:transparent;width:100%;z-index:1;">0 %</div></div></td></tr></tbody></table></td></tr></table>
| <input command_link_hidden_field="command_link_hidden_field" name="focus_hidden_field" type="hidden"></input></form>
|
Kind regards
Juergen Hoffmann
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3996905#3996905
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3996905
17 years, 8 months