Pass javascript code to Custom Control

前端 未结 2 951
小鲜肉
小鲜肉 2020-12-18 15:45

I need to pass javascript code (server-side and client-side) to a custom control which should then get executed on click on button inside the custom control.

For thi

相关标签:
2条回答
  • 2020-12-18 16:23

    If you want to use a method binding this way, you have to create a method binding as parameter for the custom control:

    <xc:ccMethod>
       <xc:this.codessjs>
          <![CDATA[#{javascript:
             var app = facesContext.getApplication();
             app.createMethodBinding("#{javascript:print('HELLO!');}", null);
           }]]>
       </xc:this.codessjs>
    </xc:ccMethod>
    

    Then, your button inside the custom control is able to invoke the method. In this case, the button will print HELLO! to the server console.

    EDIT:
    The type of the CSJS property is string. To execute CSJS code you can modify your button in your custom control to something like this:

    <xp:button value="Label" id="button1">
       <xp:eventHandler event="onclick" submit="false">
          <xp:this.script><![CDATA[#{javascript:compositeData.codecsjs}]]></xp:this.script>
       </xp:eventHandler>
    </xp:button>
    

    In your XPage, the custom control property can be filled this way:

    <xc:ccCSJS>
       <xc:this.codecsjs>
          <![CDATA[alert("ABC");]]>
       </xc:this.codecsjs>
    </xc:ccCSJS>
    

    Hope this helps

    Sven

    0 讨论(0)
  • 2020-12-18 16:34

    Have you tried the JavaScript eval function? It works for serverSide JS.

    0 讨论(0)
提交回复
热议问题