【问题标题】:JSF h:message or p:message does not workJSF h:message 或 p:message 不起作用
【发布时间】:2011-05-02 06:46:24
【问题描述】:

我的应用程序在 glassfish 中运行。我没有看到任何 h:message 或 h:messages (或 primefaces 消息)...是否有任何配置,我必须在 web.xml 或 faces-config.xml 中指定? 目前我无法查看是否有任何验证失败,即使 required="true" 和 requiredMessages="Some Value" 也不起作用..

【问题讨论】:

  • 你能添加一些代码吗?当您使用 primefaces 时,我假设您使用的是 jsf 2.0。
  • 你能检查你的日志吗?是否显示“FacesMessage(s) 已入队,但可能未显示”?
  • @Matt,这里有一些例子,
  • @radkrish,这是最新版本 3,不,我在日志文件中没有看到它们
  • @user644745,我不确定,但我怀疑 是否可以一起使用。与他们中的任何一个一起尝试,看看它是否有效。

标签: validation jsf


【解决方案1】:

JSF

咆哮-> id="咆哮"

commandButton -> update="growl"

<?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>

支持豆

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();
    }
}

【讨论】:

  • @edze 谢谢。问题是,它甚至没有在 #{userPageBacking.updateUser} 中点击 updateUser .. bean 在 vi​​ewScoped 中,我无法弄清楚为什么......我将 actionListener 更改为 action,但它仍然没有进入函数 updateUser。我将支持 bean 的范围从 viewScoped 更改为 requestScoped,但这也没有帮助。此外,我将 updateuser 更改为一些垃圾值,它没有抛出任何错误......它应该说找不到函数/属性..
  • 我用@ViewScoped 试了一下,效果很好。你使用
    吗?请发布您的代码。
  • 我尝试了 ViewScoped,但对我不起作用.. 最有趣的是,我所有的代码库都在使用这种 actionListener 调用,但这个不起作用.. 我还有另一个 commandButton,它适用于同一页。如果您知道任何调试技术,请告诉我。
  • 我只看到一个警告,“无法在视图中找到 ID 为 bankLoc 的组件。”...我看到“bankLoc”非常存在...
  • :-) 谢谢。但尽管如此,它似乎不起作用..我在日志中又收到一条消息,这与 glassfish 有关吗? ---- "无法从上下文将请求字符编码设置为 UTF-8,因为请求参数已经被读取,或者 ServletRequest.getReader() 已经被调用"
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-11
  • 2014-02-26
  • 1970-01-01
  • 1970-01-01
  • 2013-11-08
  • 1970-01-01
  • 2012-09-30
相关资源
最近更新 更多