0

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"?>

<zk>
    <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')">
            <auxhead>
                <auxheader colspan="4"
                           label="Create Users">
                    <hlayout>
                        <label />
                        <button label="create" 
                                onClick="@command('onAddNew', languageContributionStatus=each)" />
                        <checkbox checked="@bind(vm.displayEdit)"
                              label="Enable Multiple Inline Row Editing">
                        </checkbox>
                    </hlayout>
                </auxheader>
            </auxhead>

            <columns>
                <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>
            </columns>
            <rows>
                <template name="editable">
                    <row>
                        <textbox
                            value="@load(each.languageContribution.email) @save(each.languageContribution.email, before='confirm')" />
                        <textbox
                            value="@load(each.languageContribution.password) 
@save(each.languageContribution.password, before='confirm')" />      
                        <textbox
                            value="@load(each.languageContribution.password) 
@save(each.languageContribution.confirmPass, before='confirm')" />  
                        <textbox
                            value="@load(each.languageContribution.role) 
@save(each.languageContribution.role, before='confirm')" />


                        <button id="initBtn" label="Books">
                            <attribute name="onClick"><![CDATA[
            if (!loginWin.isVisible())
                loginWin.setVisible(true);
            loginWin.doHighlighted();
        ]]></attribute>
                    </button>

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


                        <button
                            label="save"
                            onClick="@command('confirm', languageContributionStatus=each)" />
                        <button
                            label="cancel"
                            onClick="@command('changeEditableStatus2', languageContributionStatus=each)" />

                    </row>
                </template>
                 <template name="noneditable">
                        <row>

                        <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" />
                        <button
                            label="edit"
                            onClick="@command('changeEditableStatus', languageContributionStatus=each)" />
                            <button label="delete"
                                    onClick="@command('onDelete', languageContributionStatus=each)" />

                    </row>
                </template>

            </rows>


        </grid>
    </div>
</zk>

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())
            loginWin.setVisible(true);
        loginWin.doHighlighted();
    ]]></attribute>
                </button>

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

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
0

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)"
         selectedItems="@bind(vm.selectedBooks)"
         checkmark="true" multiple="true" >
    <listhead>
        <listheader label="Name"  />
    </listhead>
    <template name="model" var="item">
        <listitem>
            <listcell label="@load(item.name)"/>
        </listitem>
    </template>
</listbox>

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

@Command
public void createUser() {
     user.setBooks(selectedAssignableBooks);
     myUserService.insertUser(user);
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

Follow
1 follower

RSS

Stats

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