[英]Primefaces commandButton not working properly
我想在按下CommandButton时刷新我的页面(所有inputText框,所有复选框都为空,就好像重新加载了页面一样。我尝试使用update =“ @ requestForm”,update =“:requestForm”,update = “ @all” ajax =“ false”,update =“ @([id $ = requestForm])”“,但没有成功...
这是我的commandButton的代码:
<h:commandButton value="Save" id="saveBtn"
actionListener="#{requestBean.addRequest()}" ajax="false" />
我的表单具有id =“ requestForm”。 有任何想法吗?
有很多方法可以实现它。
null
。 p:ajax
组件的resetValues
(设置为true
)属性。 p:commandButton
使用p:resetInput
组件 RequestContext.getCurrentInstance().reset("reference to the component to reset")
。 在Primefaces-ShowCase上有这些方法的示例, ResetInput
在“其他”下搜索ResetInput
。
对于JSF
当我们在输入字段中输入一些文本并将输入字段与back bean映射时,UI-Page将在UI-page上显示backing bean值的当前值。
示例 :如果您在java类中具有firstName
字段,并且正在通过<p:inputText />
设置名称,然后单击按钮Save
那么该值将一直存在,直到对象处于活动状态。 因此,您必须在actionListener="#{requestBean.addRequest()}"
方法中单击save
按钮后,在firstName
提供null值。 并使用update =“ @ form”。 如果两者都不起作用,那么您必须为此编写JavaScript。 如果没有工作,请告诉我。
我不认为primefaces更新可与#id选择器一起使用,请尝试使用style类:
<h:form styleClass="form-selector">
<p:commandButton update="@(.form-selector)" />
试试这些;
<p:commandButton value="Clear" process="@this" type="reset" update="requestForm">
<p:resetInput target="requestForm"/>
</p:commandButton>
如果它是一个对象,则需要将其设置为null并添加带有update的ajax侦听器。
resetForm(){obj=null;}
然后;
<p:ajax event="change" update="requestForm" listener="${resetForm()}"/>
这就是我必须这样做的方式-谁知道原因:
<p:commandButton value="Reset" icon="ui-icon-refresh" process="@this" update=":form">
<p:resetInput target=":form" clearModel="true" />
</p:commandButton>
根据您的需要,可能不需要clearModel。 请参阅关于resetInput的clearModel的PrimeFaces文档(默认为false):“启用后,重置输入还会将空值设置为绑定值,以便重置输入值和模型值。”
正如有人在这里告诉我们:
万一有人遇到同样的问题...
p:resetInput不接受@form作为目标。 您必须提供要清除的表单/命名容器的实际ID。 我已经看到了使用@form作为目标的在线代码示例(我认为在StackOverflow上的某个地方)-不要被愚弄,这是行不通的。
这就是为什么我使用target=":form"
原因,因为我的根NamingContainer是<h:form id="form">
。 有对NamingContainers选择的东西的信息加载在这里 。
另外,请注意,您可以执行以下操作以首先具有确认对话框:
<p:commandButton value="Reset" icon="ui-icon-refresh" process="@this" update=":form">
<p:resetInput target=":form" clearModel="true" />
<p:confirm header="Confirm Reset" message="Are you sure you want to reset all changes?" icon="ui-icon-help" />
</p:commandButton>
<p:confirmDialog global="true" closable="true" closeOnEscape="true" showEffect="fade" hideEffect="fade">
<p:commandButton value="No" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
<p:commandButton value="Yes" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
</p:confirmDialog>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.