问题描述
完全编辑:也许我是混合PTED问题和misinter $ P $。简化我的$ C $后c中的问题可以简化为:我哪有prevent的<电话号码:的commandButton>
从执行它在页面刷新的操作方法(比如当你按F5键内的浏览器窗口)?
JSF code:
< 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:UI =http://java.sun.com/jsf/facelets
的xmlns:P =http://primefaces.org/ui>
< H:身体GT;
< H:形式GT;
< H:的outputText值=#{bugBean.number}/>
< H:的outputText值=#{bugBean.isComplete()}/>
<电话号码:身份证的commandButton =entryCommand值=加上
行动=#{bugBean.increase()}更新=@形的onComplete =#{bugBean.complete()}/>
< /小时:形式GT;
< / H:身体GT;
< / HTML>
支持bean code:
包huhu.main.managebean;
的Bean;
进口javax.enterprise.context.SessionScoped;
进口javax.inject.Named;
@Named
@SessionScoped
公共类BugBean实现Serializable {
私有静态最后长的serialVersionUID = 1L;
私人诠释数目;
私人布尔isComplete = FALSE;
公共无效增加(){
数量++;
}
公共无效结束(){
isComplete = TRUE;
}
公众诠释getNumber(){
返回数;
}
公共无效setNumber(INT编号){
this.number =号;
}
公共布尔isComplete(){
返回isComplete;
}
公共无效的setComplete(布尔isComplete){
this.isComplete = isComplete;
}
}
更新:即使我删除的onComplete
这样的东西一点击<电话号码:的commandButton>
只有一次,柜台去每次上刷新页面。
< H:形式GT;
< H:的outputText值=#{bugBean.number}/>
<电话号码:身份证的commandButton =entryCommand值=加上
行动=#{bugBean.increase()}更新=@形式/>
< /小时:形式GT;
该结构是缺乏Ajax的支持,由于缺少头部的定义,因为它似乎。在这种情况下,我只是增加了< H:头/>
正上方的< H:身体GT;
- 标签,一切运行良好。
感谢所有贡献者!
Completely edited:Maybe I was mixing problems and misinterpreted. After simplifying my code the question simplifies to: How can I prevent the <p:commandButton>
from executing it's action method on page refresh (like when you hit F5 inside browser window)?
JSF Code:
<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:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:body>
<h:form>
<h:outputText value="#{bugBean.number}" />
<h:outputText value="#{bugBean.isComplete()}" />
<p:commandButton id="entryCommand" value="add"
action="#{bugBean.increase()}" update="@form" oncomplete="#{bugBean.complete()}"/>
</h:form>
</h:body>
</html>
backing bean code:
package huhu.main.managebean;
import java.io.Serializable;
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;
@Named
@SessionScoped
public class BugBean implements Serializable {
private static final long serialVersionUID = 1L;
private int number;
private boolean isComplete = false;
public void increase(){
number++;
}
public void complete(){
isComplete = true;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public boolean isComplete() {
return isComplete;
}
public void setComplete(boolean isComplete) {
this.isComplete = isComplete;
}
}
Update:Even if I remove the oncomplete
stuff like this an click the <p:commandButton>
just once, the counter goes up on every page refresh.
<h:form>
<h:outputText value="#{bugBean.number}" />
<p:commandButton id="entryCommand" value="add"
action="#{bugBean.increase()}" update="@form"/>
</h:form>
The construct was lacking Ajax-support due to a missing head definition as it seems. In this case I just added <h:head/>
right above the <h:body>
-tag and everything worked fine.
Thanks to all contributors!
这篇关于Primefaces的commandButton在页面刷新调用动作方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!