简体   繁体   English

从p:commandButton更新不起作用

[英]update from p:commandButton doesn't work

I search for someone who can help me out with this "small" problem, I searched for hours. 我搜寻了可以帮助我解决这个“小”问题的人,我搜寻了几个小时。 The code below is "broken down", so the real application is huge, I can't move technology at the moment. 下面的代码“已分解”,因此实际应用程序非常庞大,目前我无法转移技术。

So I have primefaces 5.0.10 and MyFaces 2.0.3 and I have to deal with that. 所以我有素数5.0.10和MyFaces 2.0.3,我必须处理。

Here's an XHTML: 这是一个XHTML:

<ui:composition 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"
template="../index.xhtml">
<ui:define name="title">Keyboard Bean Test</ui:define>

<ui:define name="content">
    <h1>Keyboard Bean Test</h1>

    <h:form id="myform">
        <p:panel header="KeyboardBean">
            <p:keyboard value="#{keyboardBean.value}"></p:keyboard>
        </p:panel>

        <h:outputText id="myOutput" value="#{keyboardBean.value}"></h:outputText> <br /><br />

        <p:commandButton value="Setzen" update="myOutput"></p:commandButton>
    </h:form>
</ui:define>

And here's my KeyboardBean.java 这是我的KeyboardBean.java

package de.lippoliv.test.primefaces.beans;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ActionEvent;
import javax.inject.Named;

@Named("keyboardBean")
@ManagedBean
@SessionScoped
public class KeyboardBean {

    private String value;

    public String getValue () {
        System.out.println("KeyboardBean::reading value: " + value);

        return value;
    }

    public void setValue (String newValue) {
        System.out.println("KeyboardBean::write value: " + newValue);

        value = newValue;
    }

}

What I would like to to: Update the outputText on pressing the commandButton. 我要执行的操作:按下commandButton时更新outputText。 QUIET SO SIMPLE! 非常安静!

In the real application the use-case is different, but for start figuring out why it doesn't work in real application, I decided to break it down to this simple think and then make it (step by step) more like the real application. 在实际的应用程序中,用例是不同的,但是为了弄清楚为什么它在实际的应用程序中不起作用,我决定将其分解为这种简单的想法,然后逐步使其变得更像实际的应用程序。

Whatever: This doesn't work. 不管:这行不通。 The outputText just refresh after page-load. 页面加载后,outputText才刷新。 I tryed a lot till now, nothing worked. 到目前为止,我已经尝试了很多,但没有任何效果。 Just switching from MyFaces to original JSF, but that is (as I wrote) not possible for me at the moment. 只是从MyFaces切换到原始JSF,但是(如我所写的那样)目前对我而言是不可能的。

Hopefully someone can help me out here. 希望有人可以在这里帮助我。

update 1 更新1

Here's the Ouput of console: 这是控制台的输出:

26.02.2016 11:58:58 org.apache.myfaces.config.annotation.Tomcat7AnnotationLifecycleProvider newInstance
INFO: Creating instance of de.rac.oliverlippert.test.primefaces.beans.MenuBean
26.02.2016 11:58:58 org.apache.myfaces.config.annotation.Tomcat7AnnotationLifecycleProvider newInstance
INFO: Creating instance of de.rac.oliverlippert.test.primefaces.beans.KeyboardBean
KeyboardBean::reading value: null
KeyboardBean::reading value: null
KeyboardBean::reading value: null
KeyboardBean::reading value: null
26.02.2016 11:59:01 org.apache.myfaces.config.annotation.Tomcat7AnnotationLifecycleProvider newInstance
INFO: Creating instance of de.rac.oliverlippert.test.primefaces.beans.KeyboardBean
26.02.2016 11:59:01 javax.faces.validator._ExternalSpecifications isUnifiedELAvailable
INFO: MyFaces Unified EL support enabled
KeyboardBean::reading value: null
KeyboardBean::write value: sdf

Very interessting: After pressing the commandButton once, the Beans will not be called again... 非常有趣:一次按下commandButton之后,将不会再次调用Beans。

Also I modifyed my bean, it now starts with 我也修改了我的bean,它现在开始于

@ManagedBean
@SessionScoped
public class KeyboardBean {
    ...
}

AND also I modifyed my "update" to use the whole id: 并且我还修改了“更新”以使用整个ID:

<p:commandButton value="Setzen" update=":myform:myOutput"></p:commandButton>

All that doesn't change a thing :/ 一切都不会改变:/

FireFox throws one JS error on pressing the button: FireFox在按下按钮时引发一个JS错误:

TypeError: f is null (javax.faces.resource/primefaces.js.xhtml?ln=primfaces&v=5.0 row 2 col 6868)

Thanks for any reply 感谢您的回复

update 2 OK breaking it down to this XHTML, it work: 更新2可以将其分解为这个XHTML,它可以工作:

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

<h:head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <title>Primefaces Test</title>
</h:head>

<h:body>
    <h1>Keyboard Bean Test</h1>

    <h:form id="myform">
        <h:panelGrid id="grid" cellpadding="5" columns="2" style="margin-bottom:10px">
            <p:panel header="KeyboardBean">
                <p:keyboard value="#{keyboardBean.value}"></p:keyboard>
            </p:panel>
            <h:outputText id="myOutput" styleClass="update" value="#{keyboardBean.value}"></h:outputText>

            <h:outputText id="myOutput2" styleClass="update" value="#{keyboardBean.value}"></h:outputText>
            <h:outputText id="myOutput3" styleClass="update" value="#{keyboardBean.value}"></h:outputText>
        </h:panelGrid>

        <p:commandButton value="Setzen" update="@(.update)"></p:commandButton>
    </h:form>
</h:body>

Now I can move forward step by step. 现在,我可以逐步进行。 Thanks for all :) 谢谢大家:)

Have you tried to remove @ManagedBean annotation and import javax.enterprise.context.SessionScoped instead of javax.faces.bean.SessionScoped? 您是否尝试过删除@ManagedBean批注并导入javax.enterprise.context.SessionScoped而不是javax.faces.bean.SessionScoped?

It seems to me that at this moment you are mixing CDI beans with Backing beans. 在我看来,此刻您正在将CDI bean与Backing bean混合在一起。 Details and differences are provided at this link 此链接提供详细信息和不同之

I tried to reproduce your Problem: 我试图重现您的问题:

Bean 豆角,扁豆

@ManagedBean
@ViewScoped
public class TestBean {

    private String testValue = "a";

    public void setTestValue(final String testValue) {
        this.testValue = testValue;
    }

    public String getTestValue() {
        return testValue;
    }

    public void testAction() {
        setTestValue("b");
    }
}

View 视图

<h:outputText id="testId" value="#{roleEditController.testValue}" />
<p:commandButton update="testId" action="#{roleEditController.testAction}" />

But in my case it is working :/ 但就我而言,它正在工作:/

  • Don't you get any javascript or java errors? 您没有收到任何JavaScript或Java错误?
  • Did you try to use the absolute id to update the component? 您是否尝试使用绝对ID来更新组件?

You can find the absolute id if you inspect the page with your Browser: 如果使用浏览器检查页面,则可以找到绝对ID:

<span id="form:testId">a</span>

In this case the absolute id would be :form:testId 在这种情况下,绝对ID为:form:testId

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM