Why is the getElement().getProperty("value") function not functioning properly?

I am facing an issue with reading a property in my web component. I am puzzled as to why it is not working correctly. I created a simple example, and after clicking the button, I expect to retrieve the value of the property, but it returns null. I am unsure of what might be causing this issue. In my other tests, the setProperty method works fine, but when I try to getProperty, it always retrieves the same value that was set using setProperty. Additionally, I attempted to change the property in the browser itself, but the PropertyChangeListener never gets triggered after changing the value on the client side. I have spent a considerable amount of time troubleshooting this problem. Can anyone shed some light on what might be happening here?

HelloWorld.class

import com.vaadin.flow.component.DomEvent;
import com.vaadin.flow.component.Tag;
import com.vaadin.flow.component.dependency.JsModule;
import com.vaadin.flow.component.littemplate.LitTemplate;

@Tag("hello-world")
@JsModule("./components/hello-world.ts")
public class HelloWorld extends LitTemplate {
    @DomEvent("click")
    public static class ClickEvent extends ComponentEvent<HelloWorld> {
        public ClickEvent(HelloWorld source, boolean fromClient) {
            super(source, fromClient);
        }
    }

    public HelloWorld() {
        setId("hello-world");
        getElement().addPropertyChangeListener("value", "change", e -> {
            System.out.println("change value: " + e.getValue());
        });
        addListener(ClickEvent.class, e -> System.out.println("getValue(): " + getValue()));
    }
    public void setValue(String value) {
        getElement().setProperty("value", value);
    }

    public String getValue() {
        return getElement().getProperty("value");
    }
}

hello-world.ts

import { LitElement, html, property} from 'lit-element';

export class HelloWorld extends LitElement {
    @property({type: String}) value = 'unset';

    render() {
        return html`
            <div>${this.value}</div>
            <button @click=${this._click}>Button</button>
        `;
    }

    _click() {
        this.value = 'Clicked';
        let click = new Event('click');
        this.dispatchEvent(click);
    }
}
customElements.define("hello-world", HelloWorld);

Answer №1

The synchronization of the property value back to the server is configured to be triggered by a change event in the client, but unfortunately, this event is not being fired. On the bright side, there is a click event that is being triggered, so perhaps consider updating the code to utilize the click event instead of addPropertyChangeListener.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having trouble removing objects from a map results in having to invoke the function three times

I am facing an issue with the function findPrice where I need to call it multiple times to delete objects that match a specific price. The problem arises when dealing with large maps and two functions. Here is the JSON format: [ { _id: 5c6c408dbec3ab457c ...

How can I restrict the draggable space? It is only working on the top and left sides, but I want to disable it on the right and bottom

Attempting to prevent the draggable items from overflowing beyond the body. Succeeded in limiting movement on the top and left sides. Encountering difficulty restricting motion on the right side and bottom. e.pageX -= e.offsetX; e.pageY -= e.offsetY; ...

New to Java, exploring comparison of strings within a nested for loop

Consider the following challenge: Develop a function that analyzes two strings and determines if they contain the same letters, regardless of their order. The function should return true if the letters match and false if they do not. I am struggling to co ...

Persist entity bean data in the database before finalizing the transaction

I am currently utilizing GlassFish v2ur1 (the specific version mandated by our company, and unfortunately, I am unable to upgrade it at this time). The scenario involves an EJB (ejbA) that is periodically invoked by a timer. Within this call, I read a file ...

What is the best way to create a nullable object field in typescript?

Below is a function that is currently working fine: export const optionsFunc: Function = (token: string) => { const options = { headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}`, } ...

Confirming the Hindi text present within a button using selenium

Just starting out with selenium and I have a challenge - how can I verify Hindi text within a button using the gettext() method? Need some guidance on this, appreciate any help! ...

Invoke servlet functions depending on the user's selections in the JSP page

On my JSP page, there are 2 input fields: 1) Amount to deposit. 2) Amount to withdraw. Due to Javascript validation, users can input values in either of the boxes. However, calling the correct servlet method based on the inputs has proven to be a frustr ...

The error states that the type '() => string | JSX.Element' cannot be assigned to the type 'FC<{}>'

Can someone help me with this error I'm encountering? I am fairly new to typescript, so I assume it has something to do with that. Below is the code snippet in question: Any guidance would be greatly appreciated. const Pizzas: React.FC = () => { ...

Dealing with Typescript in Node.js: Handling the error 'Property not found on type Global & typeof globalThis'

I recently encountered an issue with my NodeJS app that is built with typescript and global.d.ts file. The strange part is that everything works fine in my old application, but when I try to run the new one using ts-node-dev ts-main-file.ts, I encounter an ...

What is the procedure for accessing a namespace when declaring it globally?

Website Project Background Currently, I am working on a simple website where users can update their pictures. To achieve this functionality, I am utilizing the Multer library along with Express in Typescript. Encountered Issue I am facing a challenge re ...

What causes the error "property does not exist on type" when using object destructuring?

Why am I encountering an error in TypeScript when using Object destructuring? The JavaScript code executes without any issues, but TypeScript is showing errors. fn error: This expression is not callable. Not all elements of type '(() => void) | ...

Having trouble retrieving text from input element using selenium

In my Java/Spring application, I have created an HTML file with radio buttons populated from a database. Now, I am working on writing a Selenium test case to click the radio button. The values for these radio buttons are stored in an Excel sheet that I am ...

A TypeScript function that returns a boolean value is executed as a void function

It seems that in the given example, even if a function is defined to return void, a function returning a boolean still passes through the type check. Is this a bug or is there a legitimate reason for this behavior? Are there any workarounds available? type ...

Why does android.text.BoringLayout have several JSON fields with the same name, mPaint?

Does anyone have any idea what is happening here? 02-06 09:51:41.609: E/ACRA(15955): com.goosesys.dta_pta_test fatal error : Unable to start service com.goosesys.dta_pta_test.BGCollectorProc@4232c178 with Intent { flg=0x4 cmp=com.goosesys.dta_pta_test/.BG ...

Angular's observable data fail to show on the screen

I am facing an issue with passing the data of an Observable fetched via an API request to a component variable for display. I have been trying but unable to make it work successfully. Any assistance would be greatly appreciated. Here is my code. Thank you. ...

Combining and mapping arrays in Javascript to form a single object

I am using the following firebase function this.sensorService.getTest() .snapshotChanges() .pipe( map(actions => actions.map(a => ({ [a.payload.key]: a.payload.val() }))) ).subscribe(sensors => { ...

Leverage the power of zustand actions in your axios queries!

In my React application, I have implemented Zustand for creating a store: import { create } from 'zustand'; interface IAuth { username: string; isAuthentificated: boolean; updateAuth: (isAuth: boolean) => void; } export const useAuth = ...

Best practice for importing pipeable RxJs operators in Angular CLI/WebPack rollup

In the earlier versions of Angular CLI, specifically those before 1.5.0, it was common practice to import all RxJs operators and statics into a single file for easy usage throughout the application. For example: rxjs-operators.ts // Statics import &apos ...

Troubleshooting React child problems in TypeScript

I am facing a coding issue and have provided all the necessary code for reference. Despite trying numerous solutions, I am still unable to resolve it. export class JobBuilderOptimise extends React.Component<JobBuilderOptimiseProps & JobBuilderOptim ...

Java - Wireless Fidelity Interface

I've been on the hunt for a Wifi API that can be used with Java. This would allow me to connect to Wifi networks and scan them in order to find devices. Unfortunately, my search has been unsuccessful so far. Are there any recommendations or suggestion ...