我使用的是Primefaces 3.5,当我按下提交按钮时,应清除所有输入文本。问题是实际上只清除了一个输入文本。
<h:form id="form1">
<p:panel id="panel" widgetVar="panel">
<h:panelGrid>
<p:growl id="msgs" showDetail="true" Stiky="true" />
<p:outputLabel value="Nama depan anda : " style="margin-left:550px"/>
<p:inputText id="v1" value="#{bean.baris.username}" style="margin-left:550px"/>
<p:outputLabel value="Nama belakang anda : " style="margin-left:550px"/>
<p:inputText id="v2" value="#{bean.baris.belakang}" style="margin-left:550px"/>
<p:outputLabel value="Password anda : " style="margin-left:550px"/>
<p:password id="v3" value="#{bean.baris.password}" style="margin-left:550px"/>
<p:commandButton value="Submit"
update="display msgs"
actionListener="#{bean.tambah}"
style="margin-left:550px">
</p:commandButton>
</h:panelGrid>
</p:panel>
答案 0 :(得分:0)
在你的支持bean方法上:
public void tambah() {
serviceObject.saveMethod(baris);
baris.username = "";
baris.belakang = "";
baris.password = "";
}
由于我们在清除表单之前调用了save方法,它将满足您的需要,首先它会将数据保存在数据库中,然后清除表单。
答案 1 :(得分:-1)
更改如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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">
<f:view transient="true" />
<h:form id="form1">
<p:panel id="panel" widgetVar="panel">
<h:panelGrid>
<p:growl id="msgs" showDetail="true" Stiky="true" />
<p:outputLabel value="Nama depan anda : " style="margin-left:550px" />
<p:inputText id="v1"
value="#{bean.baris.username}" style="margin-left:550px" />
<p:outputLabel value="Nama belakang anda : "
style="margin-left:550px" />
<p:inputText id="v2" value="#{bean.baris.belakang}"
style="margin-left:550px" />
<p:outputLabel value="Password anda : " style="margin-left:550px" />
<p:password id="v3" value="#{bean.baris.password}"
style="margin-left:550px" />
<p:commandButton value="Submit" update="form1"
actionListener="#{bean.tambah}"
style="margin-left:550px"></p:commandButton>
</h:panelGrid>
</p:panel>
</h:form>
</html>
您的tambah
方法应该是这样的:
public void tambah() {
username = "";
belakang = "";
password = "";
}