Icefaces 3.0.1 FileEntry:FileEntryListener永远不会被调用

问题描述:

1.1,IceFaces 3.0.1和JSF 2.1,并试图与ace:fileentry一起工作。我不明白为什么听众永远不会被叫到!即使IDE发给我一个警告“pruebaBean.sampleListener是一个未知属性”。 这是我正在做的一个简短的例子。当点击提交按钮时什么也没有发生。 有人可以帮助我吗?可能是某种错误?Icefaces 3.0.1 FileEntry:FileEntryListener永远不会被调用

prueba.xhtml:

<?xml version="1.0" encoding="UTF-8"?> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org /TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml" 
     xmlns:h="http://java.sun.com/jsf/html" 
     xmlns:ice="http://www.icesoft.com/icefaces/component" 
     xmlns:ace="http://www.icefaces.org/icefaces/components"> 

<h:head> 
</h:head> 
<h:body> 
    <ice:form id="usuarioForm"> 
     <ice:panelGrid columns="2"> 
      <ace:fileEntry id="fileEntryImage" absolutePath="c:\iTablero\imagenes" 
          useSessionSubdir="false" useOriginalFilename="false" 
          fileEntryListener="#{pruebaBean.sampleListener}"/> 
      <ice:commandButton type="submit" value="Subir archivo"/> 
     </ice:panelGrid> 
     <ice:messages/> 
    </ice:form> 
</h:body> 

PruebaBean.java:

package com.itablero.backingbeans; 

import java.io.Serializable; 
import javax.annotation.ManagedBean; 
import javax.faces.bean.RequestScoped; 
import org.icefaces.ace.component.fileentry.FileEntry; 
import org.icefaces.ace.component.fileentry.FileEntryEvent; 
import org.springframework.stereotype.Controller; 

@ManagedBean 
@Controller 
@RequestScoped 
public class PruebaBean implements Serializable { 

    public void sampleListener (FileEntryEvent e) { 
     System.out.println("it work!"); 
     FileEntry fe = (FileEntry) e.getComponent(); 
     //some others operations 
    } 
} 

更新1

感谢@fischermatte我发现这个问题是代替冰:的commandButton对于h:commandButton。但是,当我将这个应用到原始的完整形式,并没有工作。 fileEntryListener方法永远不会被调用。有人可以在这里看到错误吗? 逻辑上,前面的示例和下面的代码具有相同的web.xml,faces-config.xml等。注意提交文件的按钮是h:commandButton,并且存在完整形式的ice:commandButton。我已经试图改变这个por en h:cb。 这里是原始形式(即在弹出显示/模式窗口)和豆:

usuariosList.xhtml

   <ice:panelPopup rendered="#{usuariosBean.showPopup}" 
          visible="#{usuariosBean.showPopup}" 
          modal="true" 
          autoCentre="true"> 

       <f:facet name="header"> 
        <h:panelGroup> 
         <h:panelGroup style="float: left;"> 
          Usuario 
         </h:panelGroup> 
         <h:panelGroup style="float: right;"> 
          <ice:form> 
          <h:commandButton image="/resources/images/popup-close.png" 
              alt="Cerrar" title="Cerrar" 
              style="height: 11px; width: 11px; border: 0;" 
              action="#{usuariosBean.closePopup}"/> 
          </ice:form> 
         </h:panelGroup> 
        </h:panelGroup> 
       </f:facet> 
       <f:facet name="body"> 
        <ice:form id="usuarioForm"> 
         <ice:panelGrid columns="2"> 
          <p>Nombre:</p> 
          <ice:inputText id="nombre" label="nombre" value="#{usuariosBean.usuario.nombre}" size="40" /> 
          <p>Imagen:</p> 
          <ice:graphicImage value="#{usuariosBean.usuario.imagen}"/> 
          <ace:fileEntry id="fileEntryImage" absolutePath="c:\iTablero\imagenes" 
              useSessionSubdir="false" useOriginalFilename="false" 
              fileEntryListener="#{usuariosBean.formListener}"/> 
          <h:commandButton type="submit" value="Subir archivo"/> 
         </ice:panelGrid> 
         <ice:messages for="usuarioForm"/> 
         <ice:commandButton value="Guardar" action="#{usuariosBean.save()}" /> 
        </ice:form> 
       </f:facet>      
      </ice:panelPopup> 

UsuariosBean.java

package com.itablero.backingbeans; 

import com.itablero.excepciones.DAOException; 
import com.itablero.modelo.Usuario; 
import com.itablero.servicios.AdminService; 
import java.io.Serializable; 
import java.util.List; 
import java.util.logging.Level; 
import java.util.logging.Logger; 
import javax.faces.bean.ManagedBean; 
import javax.faces.bean.ViewScoped; 
import org.icefaces.ace.component.fileentry.FileEntry; 
import org.icefaces.ace.component.fileentry.FileEntryEvent; 
import org.icefaces.ace.component.fileentry.FileEntryResults; 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.stereotype.Controller; 

@ManagedBean 
@Controller 
@ViewScoped 
public class UsuariosBean implements Serializable { 

@Autowired 
private AdminBean adminBean; 
@Autowired 
private AdminService adminService; 
private Usuario usuario = new Usuario(); 
private boolean showPopup; 

//getter and setters 

public boolean isShowPopup() { 
    return showPopup; 
} 

public void setShowPopup(boolean showPopup) { 
    this.showPopup = showPopup; 
} 


public void openPopup() { 
    this.showPopup = true; 
} 

public void closePopup() { 
    this.showPopup = false; 
    this.usuario = new Usuario(); 
} 

public String edit(Usuario usuario) { 
    this.usuario = usuario; 
    this.showPopup = true; 
    return "usuariosList"; 
} 

public String delete(Usuario usuario) { 
    adminService.delete(usuario); 
    return "usuariosList"; 
} 

public String save() { 
    try { 
     usuario.setTutor(adminBean.getLoggedTutor()); 
     adminService.save(usuario); 
    } catch (DAOException ex) { 
     Logger.getLogger(TutoresBean.class.getName()).log(Level.SEVERE, null, ex); 
    } 
    usuario = new Usuario(); 
    this.showPopup = false; 
    return "usuariosList"; 
} 

public void formListener(FileEntryEvent e) { 
    System.out.println("Entro"); 
    FileEntry fe = (FileEntry)e.getComponent(); 
    FileEntryResults results = fe.getResults(); 
    //other stuff 
} 

} 

更新2

我想我想出了为什么不能正常工作,但需要一些帮助。我作了@fischermatte的更正,建议我,但没有奏效。

要使用表单访问此页面,首先必须导航抛出主页面/admin/admin.html,如果在浏览器中看到URL,则出现http://localhost:8084/iTablero/admin/admin.html。这个页面有一个菜单,其中一个菜单选项将我带到问题表单的页面。但是,因为是AJAX调用(如果我没有错)浏览器中的URL不会改变,它会保留http://localhost:8084/iTablero/admin/admin.html。而fileEntry从不会调用监听器。 现在,如果我自己输入网址http://localhost:8084/iTablero/admin/usuariosList.html,页面会像以前一样正确显示,但现在FILEENTRY完美地工作了! 我不知道如何解决这个问题,将不得不使用重定向?我想是围绕AJAX的东西.......帮助请! :-D


更新3

这是菜单,无需重定向不能正常工作。

 <h:form> 
      <ice:menuBar orientation="horizontal"> 
       <ice:menuItem value="Tutores" action="tutoresList"/> 
       <ice:menuItem value="Usuarios" action="usuariosList"/> 
       <ice:menuItem value="Tableros" action="tablerosList"/> 
       <ice:menuItem value="Simbolos" action="simbolosList"/> 
       <ice:menuItem value="Estadisticas" action="estadisticas"/> 
       <ice:menuItem value="Salir" action="#{adminBean.logout()}"/> 
      </ice:menuBar> 
     </h:form> 

随着action="usuariosList?faces-redirect=true"工作正常。 已经使用向导导航到只有FileEntry的基本页面表单并且不起作用。再次,如果我使用重定向,工作正常。我认为这个组件和转发导航是一些问题。

+0

可以粘贴您的faces-config.xml文件和你的web.xml,也完整的java bean和完整的xhtml,我现在正在处理fileEntry模块,并可以提供帮助。 – Rachel 2012-04-10 20:41:38

您必须使用JSF的commandbutton而不是icefaces的:<h:commandButton type="submit" value="Subir archivo"/>。这是ICEFaces中的一个已知问题,请参阅ace:fileEntry wiki

更新1

另外,你要么喜欢在这里打开它时,删除渲染属性,在弹出的或更新弹出:

<h:form> 
    <h:commandButton value="Show Popup" action="#{usuariosBean.showPopupAction}"> 
     <f:ajax render=":popupPanelGroup"/> 
    </h:commandButton> 
</h:form> 
<h:panelGroup id="popupPanelGroup"> 
    <ice:panelPopup visible="#{usuariosBean.showPopup}" rendered="#{usuariosBean.showPopup}" modal="true" autoCentre="true"> 
    ... 
    </ice:panelPopup> 
</h:panelGroup> 
+0

你是对的,那是在发布的例子中的问题!我使用h:commandButton并调用actionListener。但奇怪的是,当我将其应用于完整的表单并且无法使用时。我将发布编辑原始问题的完整表单。 – Fisu 2012-04-10 21:25:23

+0

这与你如何打开弹出窗口有关。它会工作,当你删除呈现的属性,只是写''? – fischermatte 2012-04-10 22:51:42

+0

看到我的更新1 – fischermatte 2012-04-10 23:02:06