0

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);
}

 }
Kukeltje
  • 12,223
  • 4
  • 24
  • 47
  • Where is your form? – Bruno Jun 20 '17 at 16:23
  • 2
    Possible duplicate of [commandButton/commandLink/ajax action/listener method not invoked or input value not updated](https://stackoverflow.com/questions/2118656/commandbutton-commandlink-ajax-action-listener-method-not-invoked-or-input-value) – Kukeltje Jun 20 '17 at 17:34

1 Answers1

1

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)

lastresort
  • 508
  • 3
  • 15
  • 3
    This information is all in the duplicate I referred to. So please mark it as such. This prevents fragmentation and lots and lots of similar Q/A in Stackoverflow. I know this (unfortunately) won't give you 'repuation' points but it is 'good practice' in Stackoverflow. Thanks – Kukeltje Jun 21 '17 at 06:19
  • Oh sorry didn't look at your duplicate thread. I Just saw the mistake and wanted to help. I've flagged the question now. To be honest I don't care about the reputation, I just want to help people :) – lastresort Jun 21 '17 at 06:26
  • Cool thanks for taking it with so much sportsmanship. Same is true for me. Cheers! But you should choose the 'close' button and then 'duplicate'. Just 'upvoting' my (automatically generated) comment is not sufficient. – Kukeltje Jun 21 '17 at 06:27
  • Oh and when you add a good answer to some other question. Adding a 'RTFM' (in a friendly way unless they are stubborn;-)) is good tosince for e.g. for this question it is all in the PF docs – Kukeltje Jun 21 '17 at 06:31
  • I guess you mean "flag" instead of close? Clicked on it and then "duplicate" + upvoted your comment. – lastresort Jun 21 '17 at 07:55