我有一个带有inputText和commandButton的表单。当我点击buuton时,它会验证inputText的值是否为数字。如果不是,则显示消息。 我想,当单击按钮时,在检查inputText的值是一个数字后,隐藏表单并在其位置,显示“ok”消息。 这是我的xhtml页面表单代码:
<h:form id="formdata" >
<div id="col6-left" class="col-md-6">
<div id="registration" style="padding:10px 40px; ">
<h3 style="text-align: center">Enter your car registration</h3>
<br/>
<span class="car-reg-widget">
<input type="text" id="regnoinput" autofocus="true"/>
</span>
<div style="text-align: center; margin-top:30px;">
<h3 style="text-align: center">Mileage</h3>
<h:inputText style="width:30%; font-size:1.4em; text-align:center; "
id="mileage-text"
value="#{user.number}"
required="true"
label="The value"
requiredMessage="The mileage number is required"
validatorMessage="must be a number."
autocomplete="off">
</h:inputText>
<h:message id="fooMessage" for="mileage-text" style="color:red" />
<br/><br/>
<h:commandButton value="Get Valuation"
action="result.xhtml"
title="Get Valuation"
class="btn btn-orange"></h:commandButton>
<hr/>
</div>
</div>
</div>
</h:form>
这是我的bean文件代码:
package control;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.component.ContextCallback;
import javax.faces.component.UIComponent;
import javax.faces.component.html.HtmlOutputText;
import javax.faces.component.html.HtmlPanelGroup;
import javax.faces.context.FacesContext;
import javax.faces.view.ViewScoped;
@ManagedBean(name = "user")
@ViewScoped
public class UserBean implements Serializable {
private static final long serialVersionUID = 1L;
int number = 0;
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
}