相关疑难解决方法(0)

最初在disable ="true"时<p:commandButton>不工作

这是我的ManagedBean:

@Named(value = "mrBean")
@RequestScoped
public class MrBean {

   public void laugh() {
      System.out.println("HAHAHA");
   }

   public void prepareToLaugh() {
      System.out.println("Drink water.");
   }

}
Run Code Online (Sandbox Code Playgroud)

这是我的commandButton的工作版本:

<p:commandButton actionListener="#{mrBean.laugh}" widgetVar="laughtButton"
                 value="Laugh" oncomplete="laughButton.disable();"  />
Run Code Online (Sandbox Code Playgroud)

当我点击上面的按钮时,我看到HAHAHA了按钮被禁用.但是,当我将laughButton的disable属性设置为时true,该按钮不再起作用:

<p:commandButton actionListener="#{mrBean.laugh}" widgetVar="laughtButton"
                 value="Laugh" disabled="true" oncomplete="laughButton.disable();"  />

<p:commandButton actionListener="#{mrBean.prepareToLaugh}"
                 value="Prepare to laugh" oncomplete="laughButton.enable();" />
Run Code Online (Sandbox Code Playgroud)

当我点击第二个按钮时,我看到Drink water并启用了第一个按钮.但是,当我点击第一个按钮时,没有任何反应.

如果有人能就如何解决这个问题给我一个建议,我将非常感激.我正在使用PrimeFaces 3.0 RC2.

jsf button primefaces

3
推荐指数
1
解决办法
8554
查看次数

javax.el.MethodNotFoundException:找不到方法:TableBeanDetail@bd4053.onRowSelect()

当我单击每行中出现的数据表中的命令按钮时,我收到以下错误.通过查看示例,我了解到一旦单击了commandbutton,就会首先执行以下代码

 <f:setPropertyActionListener value="#{detailRow}" target="#{tableBeanDetail.selectedEntry}" />  
Run Code Online (Sandbox Code Playgroud)

然后是与以下bean方法关联的代码

  <p:commandButton id="detailsButton" actionListener="#{tableBeanDetail.onRowSelect}" icon="ui-icon-
      search" title="View Details">  
Run Code Online (Sandbox Code Playgroud)

在我的onRowSelect中我试图做以下事情:

  public String onRowSelect(ActionEvent event) throws Exception {


    // Get key fields from row data and set the parameters that needs to be passed w
             .....
 }
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

jsf jsp primefaces

3
推荐指数
1
解决办法
6695
查看次数

有没有简单的JSF commandButton样本?

我一直在努力尝试让我的commandButtons执行一个动作(但奇怪的是,我没有问题从bean中提取数据以包含在我的页面中).甚至在其他地方发布了我的代码并由其他人审核过.到目前为止,没有运气.所以,我想也许是一个不同的机智.任何人都可以向我指出一个项目的非常简单/基本的示例代码,该代码具有能够成功调用动作的commandButton吗?

java jsf java-ee-6 jsf-2

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

从Javascript调用commandlink操作

我试图用javascript调用bean,使用啊:commandLink.

我有一个commandLink

                <h:commandLink action="#{bean.go()}"
                    styleClass="simple-submit-button" id="uLink">
                    <f:param name="userId" value="#{param['userId']}" />
                </h:commandLink>
Run Code Online (Sandbox Code Playgroud)

它叫我的豆子.

并希望从javascript调用此commandLink,如下所示:

document.getElementById('uLink').click();
Run Code Online (Sandbox Code Playgroud)

但我总是得到错误:document.getElementById('uLink')为空.

我试过这个:

  • 设置h:commandLink immediate ="false"而不是document.getElementById('uLink').click()我使用了document.getElementById('uLink').immediate = true;
  • 使用h:commandButton代替.
  • 使用document.getElementById('formId:uLink').click();

有谁知道我是如何得到这项工作的?

javascript jsf java-ee

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

继续按两次按钮

昨天我发布了一个关于必须按两次按钮才能使其工作的问题.我收到了很好的帮助,这是stackoverflow的标志,但问题仍然存在.我将我的代码减少到最低限度,问题仍然存在.我仔细阅读了BalusC的建议,希望我能在表格中找到一个表格.我肯定没有什么可以看到所以我会发布我的代码,希望额外的双眼会看到一些东西.

我有一个模板,我从welcome(登录部分)调用.这将转到userInfo,它有一个命令按钮.这是我神秘地要按两次的命令按钮.在第二次按下命令按钮将我带到userPhoto.一切都被削减到最小,以便我可以发布它.

master.xthml:

<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!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:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Master template</title>
</h:head>
<h:body>
<p:layout fullPage="true" >
    <p:layoutUnit position="north" size="254">
        Top
    </p:layoutUnit>

    <p:layoutUnit position="east" size="50" resizable="true">
        Hello
    </p:layoutUnit>

    <p:layoutUnit position="south" size="30">
        south
    </p:layoutUnit>

    <p:layoutUnit position="center">
        <ui:insert name="AreaOne">Default text</ui:insert>
    </p:layoutUnit>
</p:layout>

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

welcome1.xhtml:

<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this …
Run Code Online (Sandbox Code Playgroud)

ajax jsf primefaces

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

Spring Security 4和PrimeFaces 5 AJAX请求处理

美好的一天。

我已经创建了一个使用Spring Security 4的PrimeFaces 5项目(JSF 2.2)。我试图使用启用了单选的p:dataTable控件,该控件通过ajax调用来更新ap:pickList控件。

问题与Spring Security有关。如果我停用页面控件所在页面的安全性(admin.faces),则ajax行为可以正常工作。但是,如果我激活安全性,则会得到403状态代码,而pickList不会得到更新。我必须在此处指出,在激活安全性的情况下,如果我尝试进入管理页面而不先登录,则将我重定向到登录页面。

这是用于Spring Security的配置。为了简单起见,删除了一些代码:

<beans:beans xmlns="http://www.springframework.org/schema/security"
    xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
                    http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
                    http://www.springframework.org/schema/security 
                    http://www.springframework.org/schema/security/spring-security.xsd">

    <http pattern="/*.css" security="none" />
    <http pattern="/*.js" security="none" />

    <http use-expressions="true">
        <intercept-url pattern="/login.faces" access="permitAll" />
        <intercept-url pattern="/javax.faces.resource/**" access="permitAll"/>
        <intercept-url pattern="/admin.faces" access="hasRole('Administrator')" />

        <form-login
            login-page="/login.faces"
            authentication-failure-url="/login.faces" />
        <logout />
    </http>

    <authentication-manager alias="authManager">
        <authentication-provider ref="daoAuthenticationProvider"/>
    </authentication-manager>
</beans:beans>
Run Code Online (Sandbox Code Playgroud)

登录页面:

<!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:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui">

<h:head>
    <title>Reports</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="_csrf" content="#{_csrf.token}"/>
    <meta name="_csrf_header" content="#{_csrf.headerName}"/> …
Run Code Online (Sandbox Code Playgroud)

jsf spring-security primefaces

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

检查是否在p:fileUpload中选择了一个文件

我正在使用PrimeFaces的简单fileUpload和自定义提交按钮,如下所示:

<h:form enctype="multipart/form-data">

    <p:fileUpload value="#{fileController.file}"
                  mode="simple"
                  skinSimple="true"
                  label="choose file"/>

    <p:commandButton value="upload"
                     ajax="false"
                     label="upload"
                     icon="fa fa-upload"
                     actionListener="#{fileController.upload}"/>
</h:form>
Run Code Online (Sandbox Code Playgroud)

在backing bean中,file是一个类型的属性UploadedFile.

现在我想要upload在没有选择文件的情况下禁用该按钮,但是我无法获得信息,无论用户是否选择了文件,file属性都会保留,null直到upload单击该按钮为止.我试过valueChangeListener的上<p:fileUpload>部件,但是当我点击上传按钮的事件仅触发(但后来为时已晚)

有人有建议吗?

jsf file-upload primefaces

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

JSF 2:ajax 调用后页面重定向

我陷入了与此类似的导航案例问题。简而言之,我正在尝试使用 ajax 渲染将导航从一个页面重定向到另一个页面h:commandLink。这是支持 bean

@ManagedBean
public class StartBean {

    public void search(){
        FacesContext
            .getCurrentInstance()
            .getExternalContext()
            .getFlash()
            .put("result", "hooray!")
        ;
    }

    public String showResult(){
        return "result?faces-redirect=true";
    }
}
Run Code Online (Sandbox Code Playgroud)

和起始页

<h:body>
    <h:form prependId="false">
        <h:commandButton value="Click" action="#{startBean.search}">
            <f:ajax execute="@this" render="@form"/>
        </h:commandButton>
    
        <br/>
         
        <h:commandLink 
            action="#{startBean.showResult()}" 
            rendered="#{flash.result != null}" 
            value="#{flash.result}"
        />
    
    </h:form>
</h:body>
Run Code Online (Sandbox Code Playgroud)

result页面只是显示一条消息。这两个页面都位于 Web 模块上下文根上。恰好h:commandLinkajax提交后显示正确,但是点击却导致页面刷新。它不会result像预期的那样重定向到该页面。之后,如果重新加载页面(F5),result则会显示页面。这似乎是渲染周期的问题。

有什么建议吗?

提前致谢。

navigation ajax jsf-2

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

不能将隐藏的commandButton与@RequestScoped支持bean一起使用

我有以下示例代码.最初,只有commandButton Two可见.当我单击此按钮时,commandButton One也可见.但是当我单击One时,后备bean方法click1不会被触发.

以下是我的代码:

XHTML

<h:form id="form1">
    <h:inputHidden id="show" value="#{bean.show1}" />
    <h:commandButton id="button1" value="One" action="#{bean.click1}"
        rendered="#{bean.show1}" />
</h:form>
<h:form id="form2">
    <h:inputHidden id="show" value="#{bean.show1}" />
    <h:commandButton id="button2" value="Two" action="#{bean.click2}" />
</h:form>
Run Code Online (Sandbox Code Playgroud)

支持bean

@RequestScoped
@Named("bean")
public class JsfTrial implements Serializable {

    private static final long serialVersionUID = 2784462583813130092L;

    private boolean show1; // + getter, setter

    public String click1() {
        System.out.println("Click1()");
        return null;
    }

    public String click2() {
        System.out.println("Click2()");
        setShow1(true);
        return null;
    }

}
Run Code Online (Sandbox Code Playgroud)

我找到了BalusC提供的非常丰富的答案.

如果我理解正确,我的问题是由于这个答案的 …

jsf-2

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

JSF按钮不会在托管bean中调用方法

我有一个视图和一个bean,这是我的问题?我尝试做一些jsf导航?并添加返回导航链接的方法?但当我点击按钮它发送请求但方法永远不会被调用.我想我犯了很简单的错误,但无法理解请帮助我的地方.

这是我的观看代码:

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets">

<ui:composition template="include/template/Layout.xhtml">
    <ui:define name="body">
        <h:outputText value="Test text"/>
        <h:outputText value="#{navigationBean.test}"/>
        <div/>
        <p:commandLink value="About Page" action="#{navigationBean.goToAbout}"/>
    </ui:define>
</ui:composition>

</html>
Run Code Online (Sandbox Code Playgroud)

我们的bean代码:

@ManagedBean(name = "navigationBean")
@SessionScoped
public class NavigationBean implements Serializable {

    public String goToAbout(){
        return "About?faces-redirect=true";
    }

    public  String getTest(){
        return "test";
    }

}
Run Code Online (Sandbox Code Playgroud)

这是我的输出页面:

Test texttest
About Page
Run Code Online (Sandbox Code Playgroud)

jsf primefaces

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