Reputation: 43
i am newbie in jsf web app , i create one jsf page with one commandButton , but it will not worked I dont know why ? i give actionlistener , after action but it will not worked, so please help me ?
html code
<p:panelGrid columns="2" id="display" columnClasses="label,value">
<h:outputText value="Mobile Number" />
<p:inputMask id="phoneWithExt" value="#{GenerateOtp.EVD}" mask="(999) 999-9999" maxlength="10"/>
<h:outputText value="Mpin" />
<p:inputMask id="mpin" value="#{GenerateOtp.MPin}" mask="9-9-9-9" maxlength="4"/>
<h:outputText value="Imei Number" />
<p:inputText id="imei" alt="Imei Number" value="#{GenerateOtp.IMEI}"/>
<h:outputText value="User Agent" />
<p:inputText id="useragent" alt="User Agent" value="#{GenerateOtp.useragent}"/>
</p:panelGrid>
<p:commandButton id="call" type="button" value="Call"
actionListener="#{GenerateOtp.buttonAction(actionEvent)}"
process="@this"
icon="ui-icon-check" />
managed bean :
@ManagedBean(name = "GenerateOtp")
@ViewScoped
public class GenerateOtp extends MasterRequest {
@SerializedName("EVD")
@Expose
private String eVD;
@SerializedName("mPin")
@Expose
private String mPin;
public String getEVD() {
return eVD;
}
public void setEVD(String eVD) {
this.eVD = eVD;
}
public String getMPin() {
return mPin;
}
public void setMPin(String mPin) {
this.mPin = mPin;
}
public void callOtp() {
System.out.println("evd" + getEVD());
}
public void buttonAction(ActionEvent actionEvent) {
addMessage("evd" + getEVD());
}
public void addMessage(String summary) {
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, summary, null);
FacesContext.getCurrentInstance().addMessage(null, message);
}
}
Upvotes: 0
Views: 165
Reputation: 552
The actionListener doesn't work for a type="button" commandButton. So you need to remove the type="button".
The type you need is "submit" but as it is the default type you don't need to declare it.
<p:commandButton id="call" value="Call"
actionListener="# GenerateOtp.buttonAction(actionEvent)}"
process="@this" icon="ui-icon-check" />
If you change it like this the button will work, if the rest of your code is correct (e.q. as BrunoDM said you need a form, if you don't have one the button still won't work)
Upvotes: 1