2017-06-20 38 views
0

我是新手在jsf網絡應用程序, 我創建一個jsf頁面與一個命令按鈕, 但它不會工作我不知道爲什麼? 我給actionlistener,行動後,但它不會工作, 所以請幫助我?p:commandbutton不工作或不叫

HTML代碼

<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" /> 

管理的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); 
} 

} 
+0

你的表格在哪裏? – BrunoDM

+2

[commandButton/commandLink/ajax動作/偵聽器方法未被調用或輸入值未更新]的可能重複(https://stackoverflow.com/questions/2118656/commandbutton-commandlink-ajax-action-listener-method-not-invoked - 或 - 輸入值) – Kukeltje

回答

1

的ActionListener的沒有一個類型= 「按鈕」 的commandButton工作。所以你需要刪除type =「button」。

您需要的類型是「提交」,但是因爲它是默認類型,所以不需要聲明它。

<p:commandButton id="call" value="Call" 
    actionListener="# GenerateOtp.buttonAction(actionEvent)}" 
    process="@this" icon="ui-icon-check" /> 

如果更改像這樣的按鈕將工作,如果你的代碼的其餘部分是正確的(EQ作爲BrunoDM說你需要一個形式,如果你沒有一個按鈕仍然無法工作)

+3

這些信息全部都在我提到的副本中。所以請標記爲這樣。這可以防止Stackoverflow中的碎片和大量類似的Q/A。我知道這個(不幸的是)不會給你'repuation'點,但它是在Stackoverflow中的'很好的做法'。謝謝 – Kukeltje

+0

對不起,沒有看到你的重複線程。我剛剛看到了錯誤,並希望提供幫助。我現在標記了這個問題。說實話,我不在乎名譽,我只是想幫助人們:) – lastresort

+0

酷炫的感謝,帶着這麼多體育精神。對我來說也是如此。乾杯!但你應該選擇'關閉'按鈕然後'重複'。只是'提高'我的(自動生成的)評論是不夠的。 – Kukeltje