サーバーサイドの値変更イベント/リスナーの実装

コード 1 - ChangeRequestBean.java
 
package com.ibm.xsp.beans;
 
import javax.faces.component.UIComponent;
import javax.faces.event.ValueChangeEvent;
 
/*
 * @author Tony McGuckin, IBM
 */
public class ChangeRequestBean { 
   
  public ChangeRequestBean (){}
   
  public void valueChangeListener(ValueChangeEvent valueChangeEvent){
     
    // Note: valueChangeListener's are fired during the PROCESS_VALIDATIONS phase
    // but only after any binded validator(s) on the component succeeds...
    UIComponent c = valueChangeEvent.getComponent();
    System.out.println("Value changed component: " + c.getId());
    System.out.println("Old value: " + valueChangeEvent.getOldValue());
    System.out.println("New value: " + valueChangeEvent.getNewValue());
     
    // do something useful...
    //    perform second level check with a service...
    //    order a pizza using REST... whatever!
    /*
    if(ChangeRequestService.doesNotApproveThisNewlyValidatedValue(c.getId(), valueChangeEvent.getNewValue()){
      FacesContext context = FacesContext.getCurrentInstance();
      context.addMessage(
        c.getClientId(context), new FacesMessage(
          FacesMessage.SEVERITY_ERROR,
          ChangeRequestService.getMessage(),
          ChangeRequestService.changeRequest.getSummary()
        )
      );
      // failover to the RENDER_RESPONSE phase...
      FacesContext.getCurrentInstance().renderResponse();
    }
    */
  }
   
} // end ChangeRequestBean
 
 
コード 2 - faces-config.xml
 
<?xml version="1.0" encoding="UTF-8"?>
<faces-config>
  <managed-bean>
    <managed-bean-name>changeRequestBean</managed-bean-name>
    <managed-bean-class>com.ibm.xsp.beans.ChangeRequestBean</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
  </managed-bean>
</faces-config>
 
 
コード 3 - XSP Markup
 
<xp:inputText id="inputText3" validator="#{validationBean.validate}"
  valueChangeListener="#{changeRequestBean.valueChangeListener}">
</xp:inputText>
<xp:message id="message3" for="inputText3"></xp:message>





このサンプルではマネージドBeanの方法で valueChangeListener の利用方法を説明しています。

XPages
katoman
July 21, 2015 1:13 PM
Rating
0





No comments yetLogin first to comment...