相关疑难解决方法(0)

h:按下p:commandButton时,消息不显示消息

我在JSF中的h:messages标签有一个问题,它根本不显示任何消息.单击按钮时,Glassfish日志中没有错误.设置如下:

test.xhtml:

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui" 
    xmlns:j="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
    <title>test</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</h:head>
<h:body>
    <h:messages globalOnly="true"/>
    <h:form id="loginform">         
        <p:commandButton id="testButton" value="Test"
          action="#{loginSessionBean.test()}" />
    </h:form>
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)

使用SessionScopedBean:

@ManagedBean
@SessionScoped
public class LoginSessionBean implements Serializable {

private static final long serialVersionUID = 1L;
...
public String test(){
     FacesContext fc = FacesContext.getCurrentInstance();
     fc.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "Test!", null)); 
    return "";
}
Run Code Online (Sandbox Code Playgroud)

jsf messages primefaces

10
推荐指数
1
解决办法
2万
查看次数

强制JSF无论如何都要处理,验证和更新只读/禁用的输入组件

我正在创建一个计算器,用户可以通过单击虚拟小键盘来执行各种操作.现在我想限制用户只通过点击按钮选择各种字符,他/她不应该使用键盘输入值.我尝试使用readonly="true"但是当我们点击任何按钮时它既不验证输入也不设置bean中的值.

我们在jsf中有这样的限制吗?

在此输入图像描述

validation jsf

10
推荐指数
1
解决办法
2025
查看次数

在JSF中不调用action方法

这是我的阶段监听器

public class AdminPhaseListener implements PhaseListener {

private static final long serialVersionUID = -1161541721597667238L;

    public void afterPhase(PhaseEvent e) {
        System.out.println("after Phase " + e.getPhaseId());
    }

    public void beforePhase(PhaseEvent e) {
        System.out.println("before Phase " + e.getPhaseId());
        if(e.getPhaseId()== PhaseId.RESTORE_VIEW)
        {

        }

    }

    public PhaseId getPhaseId() {
        return PhaseId.ANY_PHASE;
    }
}
Run Code Online (Sandbox Code Playgroud)

单击我页面中的命令按钮,我调用一个动作方法并进行一些处理,但是根本没有调用动作方法,但是在服务器日志中,我可以看到我的PhaseListener为所有阶段打印的消息.

如果我的视图没有改变,它会在RESTORE_VIEW阶段之后停止吗?

有什么想法吗?

添加如何显示命令按钮的代码:

<table width="100%">
    <h:column rendered="#{adminBean.displayResultsSize > 0}">

        <tr>
            <td colspan="14" height="5" nowrap="nowrap" class="WhiteRow"></td>
        </tr>
        <tr>
            <td colspan="14" height="1" nowrap="nowrap" align="center"
                bgcolor="#999999"></td>

        </tr>
        <h:inputHidden  id="removeUserId" value="#{adminBean.removeUserId}"/>
        <h:inputHidden  id="removeIBD" value="#{adminBean.removeIBD}"/>
        <h:inputHidden …
Run Code Online (Sandbox Code Playgroud)

jsf

8
推荐指数
2
解决办法
3万
查看次数

如何在JSF bean中发送表单输入值并调用方法

我正在构建一个JSF应用程序.我定义了GUI并使用select语句对select语句进行查询.

现在我必须执行insert语句,但我不知道如何读取valueJSF输入组件<h:inputText>,并将其发送到执行插入的bean.

应该<h:inputText>映射值faces-config.xml,所以我可以在我的Java代码中使用它吗?

jsf input facelets submit managed-bean

8
推荐指数
1
解决办法
4万
查看次数

单击h:commandLink会导致未捕获的ReferenceError:未定义mojarra

我知道这篇文章,我仔细检查了那里的所有可能性.

我在Glassfish 3上使用JSF 2.0和Mojarra实现.

我正在尝试使用两个简单的<h:commandLink>标签来更改应用程序语言.这是.xhtml页面:

<!DOCTYPE html>
<html lang="en"  xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html">
<h:head>
    <title>
        <h:outputText value = "#{appMessage['page.welcome']}" />
    </title>

    <f:metadata>
        <f:event type = "preRenderView" listener = "#{sessionController.changeLanguage}" />
    </f:metadata>
</h:head>

<h:body>
    <h1><h:outputText value = "#{appMessage['text.slide.welcome']}" /></h1>

    <h:form id = "fm-language">
        <h:commandLink action = "#{sessionController.changeLanguage('en')}" value = "#{appMessage['link.english']}" />
        <h:commandLink action = "#{sessionController.changeLanguage('de')}" value = "#{appMessage['link.german']}" />
    </h:form>

</h:body>
Run Code Online (Sandbox Code Playgroud)

这是HTML代码:

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>The Maze Project</title>
    </head>
    <body>
        <h1>Welcome</h1>
        <form id="fm-language" …
Run Code Online (Sandbox Code Playgroud)

javascript jsf undefined commandlink mojarra

8
推荐指数
1
解决办法
8913
查看次数

@SessionScoped bean会丢失范围并一直重新创建,字段变为null

我在JSF 2.0项目中使用SessionScoped bean时遇到了一个非常奇怪的问题.使用Netbeans 6.9.1,Glassfish 3服务器和PrimeFaces 3作为JSF组件库.

这是一些代码:

package com.hia.jsf;

import com.hia.netlabel.jpa.Genre;
import com.hia.netlabel.jpa.Label;
import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;

@ManagedBean
@SessionScoped
public class LabelDetailJSF implements Serializable{

@ManagedProperty("#{genreLabelListJSF}")
private GenreLabelListJSF genreLabelListJSF;
private List<Genre> DetailLabelGenreList;
private Label DetailLabel;
/** Creates a new instance of LabelDetailJSF */
public LabelDetailJSF() {
}
@PostConstruct
public void init(){
           System.out.print("Running init LabelDetailJSF");
           if(genreLabelListJSF.getSelectedLabel()!=null)
           {
                System.out.print("genreLabelListJSF was not null");
                this.DetailLabelGenreList=genreLabelListJSF.getSelectedLabel().getGenreList();
                this.DetailLabel= (genreLabelListJSF.getSelectedLabel());
           }
           if(this.DetailLabelGenreList==null){
               System.out.println("Bloody thing became null");

           }
}






/**
 * …
Run Code Online (Sandbox Code Playgroud)

jsf postconstruct primefaces

7
推荐指数
1
解决办法
8910
查看次数

p:commandbutton action在p:dialog中不起作用

我有ap:对话框,里面有一个面板.问题是"保存"按钮的操作方法不起作用.它甚至不调用该方法.我可以达到方法def.使用ctrl + lm,因此方法名称没有问题.

<h:body>
    <h:form id="createAppUserForm" prependId="false">
      ....
      <p:dialog id="newRoleDialogId"
                  header="Add New Role"
                  resizable="true"
                  draggable="true"
                  widgetVar="newRoleDetailsDialog"  
                  appendToBody="true"
                  >
            <p:panel id="newRoleDialogPanel">
                <p:panelGrid id="newRoleDialogPanelGrid" columns="2" style="width: 100%" styleClass="panelGridWithoutBorder">
                    <h:outputText value="Role Name :"/>
                    <p:inputText value="#{createAppUserController.selectedRole.name}"/>
                    <h:outputText value="Role Desc :"/>
                    <p:inputText value="#{createAppUserController.selectedRole.description}"/>
                </p:panelGrid>
                <center>
                    <p:commandButton value="Save"
                                     update="roleListDataTable newRoleDialogPanelGrid growlCreateAppUser"
                                     oncomplete="if (!args.validationFailed) newRoleDetailsDialog.hide()"                                     
                                     action="#{createAppUserController.saveNewRole()}"/>
                    <p:commandButton value="Cancel"                                         
                                     immediate="true"
                                     onclick="newRoleDetailsDialog.hide()" />
                </center>
            </p:panel>
        </p:dialog>
       </h:form>
    </h:body>
Run Code Online (Sandbox Code Playgroud)

jsf dialog primefaces commandbutton

7
推荐指数
1
解决办法
2万
查看次数

JSF ajax请求中的异常处理

在处理JSF ajax请求时抛出异常时,如何处理异常并访问堆栈跟踪?现在,当JSF项目阶段设置为Development时,我只在JavaScript警报中获取异常类名称和消息.更糟糕的是,当JSF项目阶段设置为Production时,没有任何视觉反馈,并且服务器日志不显示有关异常的任何信息.

如果这是相关的,我在Netbeans中使用GlassFish.

ajax jsf exception-handling jsf-2.2

7
推荐指数
1
解决办法
9256
查看次数

在commandLink和commandButton上导航的JSF 2.0不起作用

我正在使用JSF 2.0,我在commandLink和commandButton之后遇到导航问题.我使用以下代码:

<h:commandLink action="login?faces-redirect=true" 
    value="#{showElementBean.showElement()}"> Login </h:commandLink>  

<h:commandButton action="login?faces-redirect=true" value="Move to login.xhtml" />
Run Code Online (Sandbox Code Playgroud)

这些标签在表单内,登录只是一个例子.单击渲染控件的结果始终是POST并刷新当前页面.我错了什么?

编辑: 根据BalusC的评论我添加了真正的代码片段:

<h:commandLink actionListener="#{showElementBean.showElement(element)}" 
    value="View" > </h:commandLink>
Run Code Online (Sandbox Code Playgroud)

我有一个包含元素列表的页面,我想添加指向元素视图页面的链接.因此,我需要将此元素传递给显示页面.我是JSF的初级读者,例如在Rails中我使用GET和URL参数,但我不知道如何用JSF方式做到这一点.

jsf jsf-2

6
推荐指数
1
解决办法
4万
查看次数

命令按钮调用第二次按下时的动作(jsf)

我的应用程序出现了奇怪的行为.命令按钮开始在第二次命中时调用操作.首先 - 什么都没发生.它对firefox和chrome有效,但在顿悟中照常工作.

我的环境: - ubuntu 11.04 - glassfish 3.1.1 - jsf 2.X - primefaces 3.2 - firefox 12.0 - 顿悟2.30.6

代码示例:

    <ui:define name="content">
       <h:form id="form">
            <h:panelGrid id="panelGrid" columns="3">

                <h:outputText value="#{msg.fieUserName}:"/>
                <h:inputText  id="name"  value="#{userBb.editedUser.username}" />
                <h:message    for="name" styleClass="error_msg"/>

                <h:outputText value="#{msg.fieUserDescription}:"/>
                <h:inputText  id="description"  value="#{userBb.editedUser.description}" />
                <h:message    for="description" styleClass="error_msg"/>

                <h:outputText   value="#{msg.fieUserPassword}:"/>
                <h:inputSecret  id="password" value="#{userBb.editedUser.password}" redisplay="true"/>
                <h:message      for="password" styleClass="error_msg"/>

                <h:outputText value="#{msg.fieUserRights}:"/>
                <p:selectOneMenu id=       "rights"
                                 value=    "#{userBb.editedUserGroup}"
                                 converter="#{pGroupOfUsersConverter}">
                    <f:selectItems
                        value    ="#{groupDao.findAll()}"
                        var      ="row"
                        itemLabel="#{groupDao.rightsDescription(row.id)}"
                        itemValue="#{row.groupname}" 
                        >
                    </f:selectItems>
                </p:selectOneMenu>
                <h:message for="rights" styleClass="error_msg"/>

                <h:outputText value="#{msg.fiePorofolioName}:" rendered="#{userBb.chosenNew}"/> …
Run Code Online (Sandbox Code Playgroud)

jsf submit primefaces jsf-2

6
推荐指数
1
解决办法
1万
查看次数