I have a form with an inputText and a commandButton. When I click the buuton, it validates if the value of the inputText is a number. If not, a message is shown. I want, when the button is click, after checking that the value of the inputText is a number, to hide the form and at its position, to show a "ok" message. Here is my xhtml page form code:
<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>
and here is my bean file code:
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;
}
}