hub.eb?material_id=401&track_id=429

Accessing a Server-side Component Context from outside of a Client-side Component Context


Passing a component prefix to $eb.executeFunction() will execute the Client Callable Function within the Server-side Component Context of that component.

The component prefix can be accessed using $eb.getComponentPrefix() from within the Client-side Component Context.

This is useful when writing custom jQuery event handlers or using JavaScript Promises.

Steps


1

Create a Part-Page Component called myComponent. Add a Button Control with text content “Alert” . Create a field called name and drag it onto the page.

2

Create a Server-side script with the following code:

function setName(myName){
  fields.name.value = myName;
}

Add this script to the Client Callable Functions of myComponent. 

3

Add the sweetalert.js library to myComponent -

<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>

.

4

Add a jQuery click event handler to the Button Control with the following code:

Swal("Hello").then(function(){
  $eb.executeFunction("setName", "Brian", true, false, null);
})
5

Create a Form myForm and add myComponent to it.

6

Run myForm and click the Alert button. Then click the OK button to dismiss the sweetalert.

The name field will not have been populated because $eb.executeFunction() did not execute from within the Client-side Component Context.

7

Modify the jQuery click event handler on the Button Control:

var pfx = $eb.getComponentPrefix();
Swal("Hello").then(function(){
  $eb.executeFunction("setName", "Brian", true, false, null, pfx);
});
8

Now deploy myComponent to myForm then run the form. Click the Alert button. Then click the OK button to dismiss the sweetalert.

This time you will see the name field has been populated because $eb.executeFunction() executed from within the Client-side Component Context. 

Current Module

Related