【发布时间】:2016-02-26 07:53:32
【问题描述】:
我寻找可以帮助我解决这个“小”问题的人,我搜索了几个小时。下面的代码是“分解”的,所以真正的应用是巨大的,我暂时不能移动技术。
所以我有 primefaces 5.0.10 和 MyFaces 2.0.3,我必须处理它。
这是一个 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>
这是我的 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;
}
}
我想要做的:在按下 commandButton 时更新 outputText。安静如此简单!
在实际应用程序中,用例是不同的,但是为了弄清楚为什么它在实际应用程序中不起作用,我决定将其分解为这个简单的想法,然后(逐步)使它更像真正的应用。
随便:这行不通。 outputText 只是在页面加载后刷新。到目前为止我尝试了很多,没有任何效果。只是从 MyFaces 切换到原始 JSF,但目前(正如我所写)对我来说是不可能的。
希望有人可以在这里帮助我。
更新 1
这是控制台的输出:
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
非常有趣:按下commandButton一次后,Beans就不会再被调用了……
我还修改了我的 bean,它现在以
开头@ManagedBean
@SessionScoped
public class KeyboardBean {
...
}
我还修改了我的“更新”以使用整个 id:
<p:commandButton value="Setzen" update=":myform:myOutput"></p:commandButton>
一切都不会改变:/
FireFox 在按下按钮时抛出一个 JS 错误:
TypeError: f is null (javax.faces.resource/primefaces.js.xhtml?ln=primfaces&v=5.0 row 2 col 6868)
感谢您的回复
更新 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>
现在我可以一步一步往前走。谢谢大家:)
【问题讨论】:
-
你的标题大错特错。它表明它适用于 PrimeFaces 5.1 或 Mojarra 甚至 myfaces 2.1。非常了不起的是,像这样的问题在 2 小时内获得了 2 个赞成票和 2 个收藏夹。很可疑
-
嘿 Kukeltje,我指定了版本号,因为我必须使用这些数字。我没有尝试过更新的版本,因为我无法迁移。一个是我的最爱,另一个我不知道。
-
把它们放在你的问题中,而不是标题中
-
请从开发中退后一步......你的注释是错误的......创建一个minimal reproducible example(例如删除模板)
标签: jsf primefaces cdi