0

Two collection on zul page returning null when both of them becomes empty.

asked 2012-06-11 05:12:52 +0800

elvin gravatar image elvin
66

updated 2012-06-11 05:15:46 +0800

I have this form that has two collection for adding bank and contact info, the user can add or delete them within in the form. Playing around with one of the collection like deleting all of them and adding new ones work for both collection, the weird part is if both of them become empty and you try to add more or delete, the zul page throws a nullpointer exception. I'm not sure why both of them affects each other since there are both independent collections. I hope someone here can help me trace where the problem is because this code works perfectly if there is only one collection within the zul page and it seems like the zul page is the one throwing the error.


zul page:

		<!-- insert contact info here -->
			<groupbox>
				<caption label="Contact Information" ></caption>
				<listbox id="clist" model="@load(vm.clientContacts) @save(vm.client.clientContacts)">
					<listhead>
				        <listheader label=""></listheader>
				        <listheader label="" width="30px"></listheader>
				    </listhead>
					<template name="model" var="contact">
					<listitem>
						<listcell hflex="1">
							<n:table width="100%" cellspacing="5" border="0">
							<n:tr>
							<n:td>
								Title<n:br></n:br>
								<combobox model="@bind(vm.salutationList)" width="70px" selectedItem="@bind(contact.salutation)">
									<template name="model" var="title">
										<comboitem label="@bind(title)"></comboitem>
									</template>
								</combobox>
							</n:td>
							<n:td>
							<!-- constraint="/.+@.+\.+/: Invalid e-mail address" remove for now -->
							Name<n:br></n:br><textbox value="@bind(contact.name)" width="90%"></textbox>
							</n:td>
							<n:td>
							Telephone<n:br></n:br><textbox value="@bind(contact.phone)"></textbox>
							</n:td>
							<n:td>
							Mobile<n:br></n:br><textbox value="@bind(contact.mobile)" ></textbox>
							</n:td>
							<n:td>
							Fax<n:br></n:br><textbox value="@bind(contact.fax)" ></textbox>
							</n:td>
							</n:tr>
							<n:tr>							
							<n:td>
							Email<n:br></n:br><textbox value="@bind(contact.email)" width="90%"></textbox>
							</n:td>
							<n:td>
							MSN ID<n:br></n:br><textbox value="@bind(contact.msnId)"></textbox>
							</n:td>
							<n:td>
							Skype ID<n:br></n:br><textbox value="@bind(contact.skypeId)"></textbox>
							</n:td>
							<n:td colspan="3">
							Remarks<n:br></n:br><textbox width="70%" value="@bind(contact.remarks)"></textbox>
							</n:td></n:tr>
							</n:table>
						</listcell>
						<listcell>
						<hlayout><image src="/resources/images/cancel.png" onClick="@command('removeContact', index=clist.getSelectedIndex(), comp=savebtn)" ></image></hlayout>
						</listcell>
					</listitem>
					</template>
					<listfoot>
		            <listfooter id="footerContact" span="8" align="right"><button onClick="@command('addMoreContact')" label="add more contact"></button></listfooter>
       				</listfoot>	
				</listbox>			
			</groupbox>
			<!--  insert bank info here -->	
			<groupbox>
				<caption label="Bank Information"></caption>
				<listbox id="bankList" model="@load(vm.bankInfos) @save(vm.client.bankinfos)">
					<listhead>
				        <listheader label=""></listheader>
				        <listheader label="" width="30px"></listheader>
				    </listhead>
					<template name="model" var="bankInfo">
					<listitem>
						<listcell>
							<n:table width="100%" cellspacing="5" border="0">
							<n:tr>
							<n:td>Bank Client Name<n:br></n:br><textbox value="@bind(bankInfo.bankClientName)" width="90%"></textbox></n:td>
							<n:td>Bank Type<n:br></n:br>
								<combobox readonly="true" model="@bind(vm.bankType)" selectedItem="@bind(bankInfo.bankType)">
									<template name="model" var="item">
									<comboitem label="@bind(item)"></comboitem>
									</template>
								</combobox>
							</n:td>
							<n:td>Bank Name<n:br></n:br><textbox value="@bind(bankInfo.bankName)" width="90%"></textbox></n:td>
							<n:td>Bank Address<n:br></n:br><textbox value="@bind(bankInfo.bankAddress)" width="90%"></textbox></n:td>
							<n:td>Account Number<n:br></n:br><textbox value="@bind(bankInfo.accountNumber)" width="90%"></textbox></n:td>
							</n:tr>
							<n:tr>
							<n:td>Swift Code<n:br></n:br><textbox value="@bind(bankInfo.swiftCode)"></textbox></n:td>
							<n:td>Iban<n:br></n:br><textbox value="@bind(bankInfo.iban)"></textbox></n:td>
							<n:td>Reference<n:br></n:br><textbox value="@bind(bankInfo.reference)"></textbox></n:td>
							<n:td>Remarks<n:br></n:br><textbox value="@bind(bankInfo.remarks)" width="90%"></textbox></n:td>
							</n:tr>
							</n:table>						
						</listcell>
						<listcell>
						<hlayout><image src="/resources/images/cancel.png" onClick="@command('removeBankInfos', index=bankList.getSelectedIndex(), comp=savebtn)" ></image></hlayout>
						</listcell>						
					</listitem>
					</template>
					<listfoot>
		            <listfooter id="footerBankInfos" span="8" align="right"><button onClick="@command('addMoreBankInfos')" label="add more bank information"></button></listfooter>
       				</listfoot>						
				</listbox>
			</groupbox>"]			

VM:
client entity has zero or more Contacts
client entity has zero or more Bank info

List<ClientContact> clientContacts = new ArrayList<ClientContact>();
List<BankInformation> bankInfos = new ArrayList<BankInformation>();

    @Command @NotifyChange("clientContacts")
    public void addMoreContact(){
    	clientContacts.add(new ClientContact());
    }

    @Command @NotifyChange("bankInfos")
    public void addMoreBankInfos(){
    	bankInfos.add(new BankInformation());
    }
    
    @Command @NotifyChange("clientContacts")
    public void removeContact(@BindingParam("index") int index, @BindingParam("comp") Component comp){
    	clientContacts.remove(index);
    	client.getClientContacts().clear();
    	client.getClientContacts().addAll(clientContacts);
	    Clients.showNotification("Click save to permanently delete this contact","warning", comp, "end_center",2000);
    }
    
    @Command @NotifyChange("bankInfos")
    public void removeBankInfos(@BindingParam("index") int index, @BindingParam("comp") Component comp){
    	bankInfos.remove(index);
    	client.getBankinfos().clear();
    	client.getBankinfos().addAll(bankInfos);
	    Clients.showNotification("Click save to permanently delete this bank information","warning", comp, "end_center",2000);
    }

delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest

answered 2012-06-11 06:29:15 +0800

dennis gravatar image dennis
3679 1 6
http://www.javaworld.com....

Can you post to tracker (http://tracker.zkoss.org/), then we can trace this issue.
thanks.

link publish delete flag offensive edit

answered 2012-06-11 06:38:47 +0800

elvin gravatar image elvin
66

Thanks for the reply and posted to tracker.

link publish delete flag offensive edit
Your reply
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

RSS

Stats

Asked: 2012-06-11 05:12:52 +0800

Seen: 206 times

Last updated: Jun 11 '12

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