0

MVVM @validator and @command in grid

asked 2020-10-30 17:54:44 +0800

Arsen gravatar image Arsen
384 5

I have list of User objects and I want to output them in Grid with editable inputs like this

<grid model="@load(vm.users)">
      <columns>
        <column label="Login" width="250px"/>
        <column label="Name" width="300px"/>
        <column label="Active" hflex="min"/>
        <column label=" " hflex="min"/>
      </columns>
      <template name="model" var="user">
        <row >
          <textbox value="@load(user.login) @save(user.login, before='save') @validator(vm.loginValidator)" hflex="1" />
          <textbox value="@load(user.person.fullName)"/>
          <checkbox checked="@bind(user.enabled)"/>
          <toolbarbutton label="Save" onClick="@command('save', user=user)"/>
        </row>
      </template>
    </grid>

The first column has textbox with validator and the last one has button Save. The problems is when I press Save button in current row, the validator is called textboxes in every row. I need it to be called to the textbox in the same row as pressed Save button. How can I do it?

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
-1

answered 2020-10-30 18:57:18 +0800

MDuchemin gravatar image MDuchemin
2560 1 6
ZK Team

To trigger them separately, you will need to make separate command names. A decent option to do that automatically would be to append either the row index, or the user ID to both the @save and the @command in your template.

most likely the easiest will be with EL expressions

<?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c"?>
<textbox value="@load(user.login) @save(user.login, before=c:cat('save',user.id)) @validator(vm.loginValidator)" hflex="1" />
...
 <toolbarbutton label="Save" onClick="@command(c:cat('save',user.id), user=user)"/>
link publish delete flag offensive edit

Comments

of course, assuming that your user has an id field. if it has not, just use any unique value that make sense, or just index

MDuchemin ( 2020-10-30 18:57:55 +0800 )edit

And how should I declare corresponding java method? I have @Command public void save(@BindingParam("userRole") UserRole userRole) {...} now. I can't declare "save1", "save2" etc as User list is dynamic

Arsen ( 2020-10-30 19:12:33 +0800 )edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2020-10-30 17:54:44 +0800

Seen: 4 times

Last updated: Oct 30 '20

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More