Pass javascript code for Custom Control

I need to pass the javascript code (server side and client side) to a user control, which then has to be executed when a button is clicked inside a custom control.

To do this, I created a property in a user control, say codessjs , with type javax.faces.el.MethodBinding and an editor as a method binding editor. When I clicked the button (inside the user control), I wrote the code as follows:

compositeData.codessjs.invoke(facesContext, null)

But this causes the 'compositeData.codessjs' is null error, even though the code is present in the XPage source. How can I get the code to execute?

For client-side javascript code, I can find the Client side script editor in user control properties, but what should the property type be? And how can I execute csjs code in a user control?

+1
source share
2 answers

If you want to use a method binding this path, you need to create a method binding as a parameter for a 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 can call the method. In this case, the button will print HELLO! to the server console.

EDIT:
The CSJS property type is a string. To execute CSJS code, you can change your button in your user control 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 XPage, a custom control property can be populated as follows:

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

Hope this helps

Sven

+5
source

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

0
source

All Articles