Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binding of @Command is too lenient #1863

Open
nytro77 opened this issue Jan 15, 2020 · 1 comment
Open

Binding of @Command is too lenient #1863

nytro77 opened this issue Jan 15, 2020 · 1 comment

Comments

@nytro77
Copy link

nytro77 commented Jan 15, 2020

If i have specified a @Command annotated method in a view model with a @BindingParam annotated method parameter then i would expect ZK to complain if i dont specify any value for the parameter.
It does not.

See this fiddle
http://zkfiddle.org/sample/3o4acj4/1-Command-binding-too-lenient-for-parameters

@Yobyn
Copy link

Yobyn commented Jan 10, 2024

In ZK, when a method in a ViewModel is annotated with @Command, and it expects a parameter annotated with @BindingParam, ZK is designed to be quite flexible. If you don't provide the expected parameter from the .zul file, ZK will not raise an error. Instead, it will pass null to the parameter in the method.

This behavior allows for more dynamic and flexible UI interactions. It means that the same command can be used in different contexts, with or without specific parameters, allowing your ViewModel to adapt accordingly.

However, if your application logic strictly requires a parameter, you might want to add a check within your command method to handle cases where the parameter is null. For instance:

@Command
public void myCommand(@BindingParam("theParameter") String param) {
    if (param == null) {
        // Handle the absence of the parameter
        Messagebox.show("Parameter is required.");
    } else {
        // Proceed with the normal operation
        Messagebox.show("The parameter is " + param);
    }
}

This approach ensures that your application behaves correctly and predictably, even when the parameter is not provided. I hope this explanation clarifies the behavior of ZK with @BindingParam.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants