我正在使用Primefaces和微调器组件。我想检测单击spinner的changEvent方法。我希望我能得到oldValue和newValue但ValueChangeEvent为null。我是Java EE的新手。可以帮助我一些身体。我的英语也不太好。
这是我的index.xhtml的一部分:
<h:form>
<h:panelGrid columns="2" cellpadding="5" styleClass="ui-grid">
<h:outputLabel for="ajaxSpinner" value="Ajax Spinner: " />
<p:outputPanel>
<p:spinner id="ajaxSpinner" value="#{spinnerView.number5}" >
<p:ajax event="valueChange" update="ajaxSpinnerValue" process="@this" listener="#{spinnerView.changeEvent(event)}" />
</p:spinner>
<h:outputText id="ajaxSpinnerValue" value="#{spinnerView.number5}" style="padding-left: 10px" />
</p:outputPanel>
</h:panelGrid>
</h:form>
这是Bean类
package test.ctrl;
import java.io.Serializable;
import javax.enterprise.context.SessionScoped;
import javax.faces.event.AjaxBehaviorEvent;
import javax.faces.event.ValueChangeEvent;
import javax.inject.Named;
@Named("spinnerView")
@SessionScoped
public class WebBean implements Serializable{
private int number1;
private int number2;
private int number3;
private int number4;
private int number5;
public int getNumber1() {
return number1;
}
public void setNumber1(int number1) {
this.number1 = number1;
}
public int getNumber2() {
return number2;
}
public void setNumber2(int number2) {
this.number2 = number2;
}
public int getNumber3() {
return number3;
}
public void setNumber3(int number3) {
this.number3 = number3;
}
public int getNumber4() {
return number4;
}
public void setNumber4(int number4) {
this.number4 = number4;
}
public int getNumber5() {
return number5;
}
public void setNumber5(int number5) {
this.number5 = number5;
}
public void callBean(){
System.out.println("Ausgabe" + number5);
}
public void changeEvent(ValueChangeEvent ev){
System.out.println("Ausgabe:"+ev.getOldValue() +"--" +ev.getNewValue());
}
}
答案 0 :(得分:0)
我将p:spiner和p:ajax标签更改如下:
<p:spinner id="ajaxSpinner" value="#{spinnerView.number5}" valueChangeListener="#{spinnerView.changeEvent}" >
<p:ajax update="@form" process="@this, ajaxSpinner" />
</p:spinner>