Create Crud of a User that has a collection of books

asked 2013-09-23 16:54:51 +0800

daovallec gravatar image daovallec
11 2

I am trying do an CRUD to add Users, and my problem is that each user has a Collection of Books, and when i create a user i must to add at least one book.

My user has a email, password and role. my zk code is:

<?xml version="1.0" encoding="UTF-8"?>

    <style src="/widgets/grid/inline_row_editing/style.css" />
    <div apply="org.zkoss.bind.BindComposer"
     viewModel="@id('vm')     @init('InplaceEditingViewModel')"

        <grid id="demoGrid"
              model="@load(vm.languageContributions) @template((vm.displayEdit and each.editingStatus) ? 'editable' : 'noneditable')">
                <auxheader colspan="4"
                           label="Create Users">
                        <label />
                        <button label="create" 
                                onClick="@command('onAddNew', languageContributionStatus=each)" />
                        <checkbox checked="@bind(vm.displayEdit)"
                              label="Enable Multiple Inline Row Editing">

                <column width="160px">Email</column>
                <column width="160px">Password</column>
                <column width="160px">Confirm-Password</column>
                <column width="160px">Role</column>
                <column width="160px">Mnos</column>
                <column width="110px" visible="@load(vm.displayEdit)">Edit</column>
                <column width="110px" visible="@load(vm.displayEdit)">Remove</column>
                <template name="editable">
                            value="@load(each.languageContribution.email) @save(each.languageContribution.email, before='confirm')" />
@save(each.languageContribution.password, before='confirm')" />      
@save(each.languageContribution.confirmPass, before='confirm')" />  
@save(each.languageContribution.role, before='confirm')" />

                        <button id="initBtn" label="Books">
                            <attribute name="onClick"><![CDATA[
            if (!loginWin.isVisible())

                        <window id="loginWin" title="Books" width="300px" visible="false" minimizable="true" border='normal'>
                                 <checkbox label="@load(each.mnoList) " forward="onCheck=onModifySelectedList"/>

                            onClick="@command('confirm', languageContributionStatus=each)" />
                            onClick="@command('changeEditableStatus2', languageContributionStatus=each)" />

                 <template name="noneditable">

                        <label value="@load(each.languageContribution.email)" />
                        <label value="@load(each.languageContribution.password)" />
                        <label value="@load(each.languageContribution.password)" />
                        <label value="@load(each.languageContribution.role)" />
                        <button label="Books" />
                            onClick="@command('changeEditableStatus', languageContributionStatus=each)" />
                            <button label="delete"
                                    onClick="@command('onDelete', languageContributionStatus=each)" />




This is the part of my code that return the list of my books:

                    <button id="initBtn" label="Books">
                        <attribute name="onClick"><![CDATA[
        if (!loginWin.isVisible())

                    <window id="loginWin" title="Books" width="300px" visible="false" minimizable="true" border='normal'>
                             <checkbox label="@load(each.languageContribution.mnoList) " forward="onCheck=onModifySelectedList"/>

My problem is that @load(each.languageContribution.mnoList) "

where mnoList is a collection of books return one Collection, with each return each object and I not need each object, I need only an atribute of each book and in a Checkbox List, to add and remove.

Then i need do a query with a checkboxList with all my books of my database, and enable the books that the user has and the oportunity to add or remove books of a user.

Somebody can help me please?

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted

answered 2013-09-24 01:37:00 +0800

rickcr gravatar image rickcr
704 7

updated 2013-09-24 01:37:38 +0800

I assume @load(each.languageContribution.mnoList) is a java util List? you can't assign that to a checkbox. Where is your listbox or grid that shows the books? Just make a listbox of assignableBooks and add the checkmark property to true on listbox.

You then back your listbox with a ViewModel of Set<book> selectedBooks;

Your listbox would look something like...

    <listbox id="autosList" model="@load(vm.assignableBooks)"
         checkmark="true" multiple="true" >
        <listheader label="Name"  />
    <template name="model" var="item">
            <listcell label="@load(item.name)"/>

If you want these books then to be part of your insert of the user in the VM you could just add them at insert/update time...

in your VM

public void createUser() {
link publish delete flag offensive 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

1 follower



Asked: 2013-09-23 16:54:51 +0800

Seen: 15 times

Last updated: Sep 24 '13

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