oncomplete方法中的PrimeFaces属性未更新
PrimeFaces Attribute in oncomplete method not updating
我有这个代码:
<div id="visibleButtons">
<p:commandButton id="hint" action="#{tutorSession.hintRequest}" value="Hint Please" update="@parent" oncomplete="playNextHint(#{tutorSession.giveWarning});">
</p:commandButton>
<p:commandButton id="newType" action="#{tutorSession.newPathRequest}" value="Something Else" update="@parent" oncomplete="playNextHint(#{tutorSession.giveWarning});">
</p:commandButton>
#{tutorSession.giveWarning}<!-- I will remove this line once the buttons are working -->
</div>
现在的情况是,javascript函数playNextHint使用上一次调用中的giveWarning值执行,而不是当前调用。我检查了服务器是否返回了正确的值;事实上,我在底部添加了一点文本输出,以验证是否返回了正确的值,它总是以我期望的方式显示,但javascript仍然使用旧值。
对可能发生的事情有什么想法吗?
javascript方法,如果它是相关的:
function playNextHint(giveWarning){
alert(giveWarning);
}
提前谢谢。
编辑:我找到了一个解决办法,使用一个带值的隐藏字段,然后在javascript中获取该字段的值,但这很混乱,必须有更好的方法,因为我将为这个web应用程序做很多这样的事情。
编辑2:对不起,我留下了一些代码用于演示,这似乎让人们感到困惑。首先,我不想显示giveWarning。这只是为了让我看到它得到了正确的价值。我把它留在里面,这样人们就可以看到正确的价值观在哪里出现,而不是在哪里没有。
编辑3:当按下按钮时,我想做的是在服务器上计算giveWarning的新值(该部分有效),然后将其发送到javascript函数,以根据它进行逻辑处理(警报是一个占位符,用于测试)。问题是,javascript函数得到的值似乎总是比它应该得到的值落后一次,尽管当我只是将值发送到屏幕(div的最后一行)时,它显示了它应该得到什么。抱歉所有的编辑;就像我说的,这是我第一次发帖。
我认为您只是采取了不恰当的方法。我刚刚制作了一个新的<outputLabel>
,并给它一个id
,以便在javascript
方法中使用它,并添加了update="label"
来更新标签,并消除向该js
方法传递任何参数。你可以查看这个
在.xhtml
中
<h:form id="myForm">
<p:commandButton id="hint" action="#{tutorSession.hintRequest}" value="Hint Please" update="label" oncomplete="playNextHint();">
</p:commandButton>
<p:commandButton id="newType" action="#{tutorSession.newPathRequest}" value="Something Else" update="label" oncomplete="playNextHint();">
</p:commandButton>
<p:commandButton id="skip" action="#{tutorSession.giveUp}" value="Skip">
</p:commandButton>
<h:outputLabel value="#{tutorSession.giveWarning}" id="label" />
</h:form>
和您的js
功能
function playNextHint(){
alert($('#myForm'':label').text());
}
以及在您的ManagedBean tutorSession
中
// other stuff here
private String giveWarning;
// setters / getters for giveWarning
public void hintRequest() {
setGiveWarning("hint");
}
public void newPathRequest() {
setGiveWarning("newPath");
}
我知道这是一个老问题,但我遇到了同样的问题,并使用单独的remoteCommand:解决了它
<p:remoteCommand name="playNextHintComplete"
oncomplete="playNextHint(#{tutorSession.giveWarning})"/>
<p:commandButton value="Hint Please"
action="#{tutorSession.hintRequest}"
process="@form"
update="@form"
oncomplete="playNextHintComplete()"/>
- Css order属性不't在Jquery设置时更新
- 通过jQuery添加ng样式属性,angular不更新
- 更新属性工作不正常Meteor/MongoDB
- Es6:能够在设置/更新/删除对象属性时调用自定义方法
- 如何动态更新输入值属性
- 无法使用编程加载的属性更新范围滑块.js
- 使用Angular Directive用$scope属性更新DOM-只要指令运行(无需等待事件)
- 使用 HTML + Javascript 的多项选择测验:回复:使用数组对象和属性更新分数(帮助分析代码)
- 从新对象的属性更新对象的属性,但前提是新对象上的属性不是未定义的
- 浏览器如何从内部HTML属性更新DOM
- 使用计算属性更新 Ember 模型
- 从 AngularJS 中的服务属性更新$scope
- Ember绑定属性没有更新,尽管控制器属性更新得很好
- HTML5自定义属性更新值
- 数据变量没有从Vue.js中的监视器上的计算属性更新
- 使用ajax和data-*属性更新按钮
- 为什么我不能用Javascript innerHTML属性更新HTML列表项?
- 当数组中的任何项被更改时,如何使Ember计算属性更新
- 属性更新以触发对象的另一个方法
- Vue.js计算属性更新数量