[jboss-user] [JBoss Seam] - Need an advice to improve Seam-ICEfaces fileUpload Session b
gus888
do-not-reply at jboss.com
Tue May 29 15:58:40 EDT 2007
Hi all,
I reviewed the Seam-ICEfaces fileUpload demo codes (as follows), and I want to change the SFSB to conversation bean. In addition, the codes seem a little hard to follow, anybody can give some advice on how to simplify them? I really appreciate it. Thank you very much in advance. The demo codes are listed as follows:
| /**
| * <p>The InputFileBackerBean class is the backing bean for the inputfile showcase
| * demonstration. It is used to store the state of the file uploading
| * operation.</p>
| *
| * @since 0.3.0
| */
| @Stateful
|
| @Name("inputFileBackerBean")
| @Scope(ScopeType.SESSION)
| public class InputFileBackerBean implements InputFileBacker, Renderable, Serializable {
|
| private int percent = -1;
| private File file = null;
| private transient PersistentFacesState state;
|
| private String fileName = "";
| private String contentType = "";
|
| private InnerProgressMonitor pmImpl;
|
| private static Log log =
| LogFactory.getLog(InputFileBackerBean.class);
|
| public InputFileBackerBean() {
| pmImpl = new InnerProgressMonitor();
| state = PersistentFacesState.getInstance();
| }
|
| public PersistentFacesState getState() {
| return state;
| }
|
| public void renderingException (RenderingException re) {
| log.error("Rendering exception " , re);
| }
|
|
| public void setPercent(int percent) {
| this.percent = percent;
| }
|
| public int getPercent() {
| return percent;
| }
|
| public void setFile(File file) {
| this.file = file;
| }
|
| public File getFile() {
| return file;
| }
|
| public InnerProgressMonitor getProgressMonitor() {
| return pmImpl;
| }
|
| public InnerProgressMonitor getActionMonitor() {
| return pmImpl;
| }
|
|
| public void setFileName(String fileName) {
| this.fileName = fileName;
| }
|
| public String getFileName() {
|
| return fileName;
| }
|
| public void setContentType(String contentType) {
| this.contentType = contentType;
| }
|
| public String getContentType() {
| return contentType;
| }
|
| @Remove
| @Destroy
| public void destroy() {
| }
|
|
| /**
| * Inner class to handle updates and action. Do this to keep the
| * render call from triggering concurrent access problems in the Bean.
| */
| public class InnerProgressMonitor implements
| Serializable {
|
|
|
| public void progress(EventObject event) {
|
| com.icesoft.faces.component.inputfile.InputFile file =
| (com.icesoft.faces.component.inputfile.InputFile) event.getSource();
| int percent = file.getFileInfo().getPercent();
| InputFileBackerBean.this.setPercent( percent );
| InputFileBackerBean.this.setFile( file.getFile() );
|
| if (log.isDebugEnabled()) {
| log.debug("Progress - Percent: " + percent);
| }
| try {
| // execute the lifecycle to initialize Seam to prevent
| // IllegalStateExceptions, and render.
| state.execute();
| state.render();
|
| } catch (RenderingException re ) {
| System.out.println("Rendering exception : " + re);
| re.printStackTrace();
| }
| }
|
|
|
|
| public String action(ActionEvent event) {
|
| com.icesoft.faces.component.inputfile.InputFile inputFile = (com.icesoft.faces.component.inputfile.InputFile) event.getSource();
| if (inputFile.getStatus() == com.icesoft.faces.component.inputfile.InputFile
| .SAVED) {
| InputFileBackerBean.this.setFileName(inputFile.getFileInfo().getFileName());
| InputFileBackerBean.this.setContentType(inputFile.getFileInfo().getContentType());
| InputFileBackerBean.this.setFile(inputFile.getFile());
|
| if (log.isDebugEnabled()) {
| log.debug("File uploaded: " + inputFile.getFileInfo().getFileName());
| }
| }
|
| if (inputFile.getStatus() == com.icesoft.faces.component.inputfile.InputFile
| .INVALID) {
| inputFile.getFileInfo().getException().printStackTrace();
| }
|
| if (inputFile.getStatus() == com.icesoft.faces.component.inputfile.InputFile
| .SIZE_LIMIT_EXCEEDED) {
| inputFile.getFileInfo().getException().printStackTrace();
| }
|
| if (inputFile.getStatus() == com.icesoft.faces.component.inputfile.InputFile
| .UNKNOWN_SIZE) {
| inputFile.getFileInfo().getException().printStackTrace();
| }
| return null;
| }
| }
|
| }
| and also the jsp codes:
<ice:panelGrid
| styleClass="componentLayoutRootTable"
| columns="1">
| <ice:panelGroup styleClass="formBorderHighlight"
| style="text-align:left">
| <ice:inputFile
| progressListener="#{inputFileBackerBean.progressMonitor.progress}"
| actionListener="#{inputFileBackerBean.actionMonitor.action}"/>
| <ice:outputProgress id="pro"
| value="#{inputFileBackerBean.percent}"/>
| <ice:outputText
| value="File Name: #{inputFileBackerBean.fileName}"/>
| <br/>
| <ice:outputText
| value="Content Type: #{inputFileBackerBean.contentType}"/>
| <ice:messages/>
| </ice:panelGroup>
| </ice:panelGrid>
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4049516#4049516
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4049516
More information about the jboss-user
mailing list