1.1、IceFaces 3.0.1 和 JSF 2.1,并尝试与 ace:fileentry 一起使用。我不明白为什么监听者永远不会被调用!甚至 IDE 也会向我发送警告“pruebaBean.sampleListener 是未知属性”。
这是我正在做的事情的一个简短示例。当单击提交按钮时,没有任何反应。
有人能帮我吗 ??可能是某种错误?
普鲁巴.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
}
}
Update 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
}
}
Update 2
我想我找到了为什么不起作用,但需要一些帮助来修复。我按照 @fischermatte 的建议进行了更正,但没有成功。
要使用表单到达此页面,首先必须导航并抛出主页/admin/admin.html
,如果浏览器中出现 URLhttp://localhost:8084/iTablero/admin/admin.html
。该页面有一个菜单,该菜单选项之一将我带到有问题表单的页面。但是,因为是 AJAX 调用(如果我没记错的话),浏览器中的 URL 不会改变,它会保留http://localhost:8084/iTablero/admin/admin.html
。并且 fileEntry 永远不会调用侦听器。
现在,如果我自己输入 URLhttp://localhost:8084/iTablero/admin/usuariosList.html
,页面像以前一样正确显示,但现在文件条目工作完美!
我不知道如何解决这个问题,必须使用重定向吗?我认为是关于 AJAX 的问题......请帮忙! :-D
Update 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>
With action="usuariosList?faces-redirect=true"
工作正常。
已经测试过向前导航到仅具有 FileEntry 的基本页面表单,但也不起作用。同样,如果我使用重定向,效果很好。我认为这个组件和前向导航存在某种问题。