# BoundVariableExpression activation

**URL:** <https://forum.inductiveautomation.com/t/boundvariableexpression-activation/45282>\
**Category:** Module Development\
**Created:** [April 5, 2021, 8:54pm UTC](https://forum.inductiveautomation.com/t/boundvariableexpression-activation/45282 "2021-04-05T20:54:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![damien.boissat](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@damien.boissat](https://forum.inductiveautomation.com/u/damien.boissat)\
**Post date:** [April 5, 2021, 8:54pm UTC](https://forum.inductiveautomation.com/t/boundvariableexpression-activation/45282/1 "2021-04-05T20:54:33Z")

</div>

Hello,

I am configuring my `property adapter` (`binding expression`) through code, and I have no issues at all with any kind of `FunctionExpression` except `BoundVariableExpression`.

It does not activate, if I have any `BoundVariableExpression` in my expression then I must open the binding windows of the property and click `save` . Then the whole expression is working properly, I didn’t even need to touch the expression at all.

I am creating and adding the properties adapter in the `onStartup()` method of the components.

Do you have any idea how to do this?

Thank you,

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 5, 2021, 10:11pm UTC](https://forum.inductiveautomation.com/t/boundvariableexpression-activation/45282/2 "2021-04-05T22:11:47Z")

</div>

Please re-read my comment in this other thread--I believe you've misunderstood:

> [@Add binding and scripting to vision component](http://forum.inductiveautomation.com/t/add-binding-and-scripting-to-vision-component/44650/4):
>
> Some implementation notes for built-in functionality: The designer’s mouse events, key events, and propertyChange listeners simply implement the corresponding java listeners. Your components would implement built-in functionality directly in java, and add them to the component either at creation or in the startup method. Property bindings you wish to implement would simply be listeners of the appropriate types for all of the relevant source data. If the source data is on a different comp…

` ************************** `

> [@damien.boissat](#):
>
> Do you have any idea how to do this?

You are struggling because components are not intended to be making their own bindings. For built-in functionality, your components should be doing the equivalent with runtime listeners. Your component classes should have nested classes implementing the appropriate listener types and overriding the event message methods to distribute the arriving data. This is how **internal** bindings are constructed.

Property Adapters and related bindings are how the **designer** adds _ **user-supplied** _ functionality at _ **configuration** _ time.

---

<div class="post-metadata">

**Author:** ![damien.boissat](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@damien.boissat](https://forum.inductiveautomation.com/u/damien.boissat)\
**Post date:** [April 6, 2021, 9:57am UTC](https://forum.inductiveautomation.com/t/boundvariableexpression-activation/45282/3 "2021-04-06T09:57:47Z")

</div>

Thank you for your reply!

I have read and checked carefully but without success, it still doesn’t bind immediately without opening the binding windows and clicking **save**. Here is my piece of code that run during the **onStartup()**

```auto
...
String path = GetComponentPath(c, n);
...
BoundVariableExpression bve1 = new BoundVariableExpression();
bve1.setType(Boolean.class);
bve1.setPath(MessageFormat.format("{0}.Highlight", path));
bve1.setPropertyListener(new PropertyListenerDescriptor(
		c, epa, "Highlight", new BasicQualifiedValue(c.getPropertyValue("Highlight"))));
c.addPropertyChangeListener(bve1.getPropertyListener());
...
...

```

Should I create the **BoundVariableExpression** differently?

When the property `Highlight` is changed, it should the `FunctionExpression` in which it is used, for example `new NotExpression(bve1)`

Of course it is inside a `var epa = new ExpressionPropertyAdapter();` which is then added to the main `setPropertyAdapter(c, "BorderState", epa);`

As long as I don’t use any **BoundVariableExpression** in my `FunctionExpression`, then it works immediately without issues.

Thank you,

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 6, 2021, 10:09am UTC](https://forum.inductiveautomation.com/t/boundvariableexpression-activation/45282/4 "2021-04-06T10:09:10Z")

</div>

You should not be using FunctionExpression or BoundVariableExpression or any form of PropertyAdapter. You should be implementing [PropertyChangeListener](https://docs.oracle.com/javase/8/docs/api/java/beans/PropertyChangeListener.html) in your receiving components and attaching them to your source components. Along with any other [low-level listeners](https://docs.oracle.com/javase/8/docs/api/javax/swing/event/package-summary.html) you might need.

If you are using setPropertyAdapater() in your code, you are screwing up.

---

<div class="post-metadata">

**Author:** ![damien.boissat](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@damien.boissat](https://forum.inductiveautomation.com/u/damien.boissat)\
**Post date:** [April 6, 2021, 10:27am UTC](https://forum.inductiveautomation.com/t/boundvariableexpression-activation/45282/5 "2021-04-06T10:27:09Z")

</div>

I will try to see how I can do it, I am using the xml generated by the **FPMIWindow** and the components to figure out what code to write. At the end my code generated exactly the same XML as if I was doing the changes manually via the designer, and it was working well, so I thought it was the proper way to go…

But yes with **BoundVariableExpression** then it stopped working as expected…

Well I am bit confused now to be honest, I have to figure things out

Thank you,
