【问题标题】:Icefaces 3.0.1 FileEntry: FileEntryListener is never calledIcefaces 3.0.1 FileEntry:永远不会调用 FileEntryListener
【发布时间】:2012-04-10 19:46:43
【问题描述】:

1.1、IceFaces 3.0.1 和 JSF 2.1 并尝试使用 ace:fileentry。我不明白为什么永远不会调用监听器!甚至 IDE 也会向我发送警告“pruebaBean.sampleListener 是未知属性”。 这是我正在做的一个简短示例。单击提交按钮时,没有任何反应。 有人能帮我吗 ??可能是某种错误?

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,我发现问题是将 ice:commandButton 替换为 h:commandButton。但是当我将它应用到原始的完整表格并且没有工作时。永远不会调用 fileEntryListener 方法。有人可以在这里看到错误吗? 逻辑上前面的例子和下面的代码有相同的web.xml、faces-config.xml等。注意提交文件的按钮是h:commandButton,还有一个ice:commandButton代表完整的表单。我已经尝试更改此 por en h:cb。 这是原始表单(显示在弹出/模式窗口中)和 bean:

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 从不调用监听器。 现在,如果我自己输入 URL http://localhost:8084/iTablero/admin/usuariosList.html,页面会像以前一样正确显示,但现在文件输入完美! 我不知道如何解决这个问题,是否必须使用重定向?我认为是 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 的基本页面表单进行测试,但也不起作用。同样,如果我使用重定向,工作正常。我认为这个组件和向前导航存在某种问题。

【问题讨论】:

  • 你能粘贴你的 faces-config.xml 文件和你的 web.xml 以及完整的 java bean 和完整的 xhtml,我现在正在处理 fileEntry 模块,可以提供帮助。

标签: ajax jsf-2 icefaces icefaces-3


【解决方案1】:

你必须使用 JSF 的命令按钮而不是 icefaces 的:&lt;h:commandButton type="submit" value="Subir archivo"/&gt;。这是 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>

【讨论】:

  • 你是对的,这就是发布的示例中的问题!我使用 h:commandButton 并调用 actionListener。但奇怪的是,当我将它应用于完整的表格并且没有工作时。我将发布完整的表格来编辑原始问题。
  • 我猜这与您打开弹出窗口的方式有关。当您删除呈现的属性并只写&lt;ice:panelPopup visible="#{usuariosBean.showPopup}" modal="true" autoCentre="true"&gt;时它会起作用吗?
  • 嗯...我想我找到了问题,但不知道如何解决。用我糟糕的英语很难解释。
  • 能否提供包含导航菜单的admin.html代码?我假设您正在使用带有操作的&lt;h:commandButton/&gt;。在 JSF 中,这将使用 POST 进行转发。当您希望在浏览器中更改页面 URL 时,您可以使用简单的 html 链接,例如 &lt;a href="http://.../usuariosList.html"&gt;MyLink&lt;/a&gt;,或者使用 jsf 2.0 链接,例如 &lt;h:link outcome="usuariosList.html" value="MyLink"/&gt;。如果您需要提交表单数据,您也可以坚持使用 CommandButton 并使用 POST-REDIRECT-GET 方法:&lt;h:commandButton action="usuariosList.html?faces-redirect=true/>。
  • 我有 ice:menuBar 和 ice:menuItem。我认为这类似于 h:commandButton。根据您的建议,添加了&lt;ice:menuItem value="Usuarios" action="usuariosList?faces-redirect=true"/&gt;,并且可以很好地更改 URL,并且 FileEntry 也可以正常工作。但是这个解决方案使浏览器刷新,并不是我想要的。 FileEntry 没有其他解决方法可以在没有重定向的情况下工作吗?对于 FE,URL 是否必须准确指向定义该组件的页面?
猜你喜欢
  • 2012-12-16
  • 1970-01-01
  • 2021-04-15
  • 2014-11-01
  • 2016-07-22
  • 1970-01-01
  • 1970-01-01
  • 2020-11-18
  • 2012-10-27
相关资源
最近更新 更多