2012-04-10 210 views
0

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

回答

0

您必須使用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

相關問題