2016-04-22 17 views
0

javascript関数から属性を渡そうとしていますが、作業はしていますが、最初に「previous value」と表示し、2回目に正しい値を表示します。ここでADFからjavascriptに動的属性を渡します。

私のコードは

ADFです:

<af:form id="f1" binding="#{backingBeanScope.backing_js_page.f1}"> 
     <af:inputText label="Name" id="it1" binding="#{backingBeanScope.backing_js_page.it1}" value="#{backingBeanScope.backing_js_page.name}" 
         autoSubmit="true" partialTriggers="it1"> 

     </af:inputText> 
     <af:button text="Say Hello" id="b1" binding="#{backingBeanScope.backing_js_page.b1}"> 
       <af:clientAttribute name="name" value="#{backingBeanScope.backing_js_page.it1.value}"/> 

      <af:clientListener method="sayHello" type="click"/> 
     </af:button> 
     <af:resource type="javascript" source="/resources/js/hello.js"/> 
    </af:form> 

Javascriptコード:

function sayHello(evt) { 
var comp = evt.getSource(); 
alert(comp.getProperty('name')); 
evt.cancel(); 
} 

答えて

0

あなたのADF豆の内部でJavaScript関数を実行することができます。

jsff:

<af:button text="Say Hello" id="b1" actionListener="#{Scope.Bean.onClick}"> 
    </af:button> 

ADFビーン:

public void onClick(ActionEvent actionEvent) { 
    String myJavaVariable = "hello World"; 
    String jsCode="alert('"+myJavaVariable+"');"; //YOUR JS SCRIPT WITH JAVA VARIABLES EMBEDED 
    this.executeJavaScript(jsCode); 
    } 

public static void executeJavaScript(String jsCode) { 
    FacesContext context = FacesContext.getCurrentInstance(); 
    ExtendedRenderKitService erks = Service.getRenderKitService(context, ExtendedRenderKitService.class); 
    erks.addScript(context, jsCode); 
} 
+0

executeJavaScript機能はADFバインディングを扱うための便利な一連の機能から取得さ:ADFUtils http://jdeveloper-adf.googlecode.com/svn/trunk/TGPrototype2/ViewController /src/com/tgslc/defaultManagement/utils/ADFUtils.java – MrAdibou

関連する問題