2011-05-02 115 views
2

我的應用程序在glassfish中運行。我沒有看到任何h:消息或h:消息(或primeface消息)......是否有任何配置,我必須在web.xml或faces-config.xml中指定? 目前我也沒有辦法,看看是否有驗證失敗,甚至需要=「真」與requiredMessages =「一些價值」不工作..JSF h:消息或p:消息不起作用

+0

你可以添加一些代碼嗎?當您使用primefaces時,我假設您使用的是jsf 2.0。 – 2011-05-02 06:58:44

+0

你可以檢查你的日誌嗎?它顯示「FacesMessage(s)已被排隊,但可能沒有顯示」? – 2011-05-02 07:03:09

+0

@馬特,這裏是一些例子,\t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t user644745 2011-05-02 07:17:58

回答

3

JSF

咆哮 - > ID =「咆哮「

的commandButton - >更新=」 咆哮」

<?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:p="http://primefaces.prime.com.tr/ui" 
     xmlns:h="http://java.sun.com/jsf/html"> 
    <h:head> 
     <title>Facelet Title</title> 
    </h:head> 
    <h:body> 
     <h:form> 
      <p:growl id="growl" showDetail="false" sticky="true" /> 

      <p:commandButton value="Update" update="growl" actionListener="#{userPageBacking.updateUser}"/> 
     </h:form> 
    </h:body> 
</html> 

輔助Bean

import javax.faces.application.FacesMessage; 
import javax.faces.bean.ManagedBean; 
import javax.faces.bean.RequestScoped; 
import javax.faces.component.UIComponent; 
import javax.faces.context.FacesContext; 
import javax.faces.event.ComponentSystemEvent; 

/* 
* To change this template, choose Tools | Templates 
* and open the template in the editor. 
*/ 
/** 
* 
* @author ezehrt 
*/ 
@ManagedBean 
@RequestScoped 
public class UserPageBacking { 

    public void updateUser() { 
     FacesContext fc = FacesContext.getCurrentInstance(); 

     if (fc.isValidationFailed()) { 
      return; 
     } 


     FacesMessage msg = new FacesMessage("fehlermeldung", "fehlermeldung"); 

     msg.setSeverity(FacesMessage.SEVERITY_ERROR); 

     fc.addMessage("fehlermeldung", msg); 

     fc.renderResponse(); 
    } 
} 
+0

@edze謝謝。問題是,它甚至沒有在#{userPageBacking.updateUser}中觸及updateUser ..該bean在viewScoped中,我無法弄清楚爲什麼......我將actionListener更改爲操作,但它仍然不在updateUser函數中。我將backing bean的範圍從viewScoped更改爲requestScoped,但這也沒有幫助。此外,我更新updateuser到一些垃圾值,它沒有拋出任何錯誤...應該說,功能/財產沒有找到.. – user644745 2011-05-02 11:46:42

+0

我試用@ViewScoped它工作正常。你使用?請發佈您的代碼。 – edze 2011-05-02 12:14:14

+0

我試過ViewScoped,不適合我......最有趣的部分是,我所有的代碼庫都使用這種actionListener調用,但是這個不起作用。我還有另一個commandButton,它在同一頁面中工作。如果你知道任何調試技術,請讓我知道。 – user644745 2011-05-02 12:35:20