[Laszlo-user] Seemingly difficult dataset updating problem

James Howe openlaszlo at wingspread.imap-mail.com
Wed Apr 5 18:24:59 EDT 2006


Suppose I have the following application which creates an editor for some  
XML data:

<?xml version="1.0" encoding="UTF-8" ?>
<canvas height="100%" width="100%" bgcolor="#EEEEEE" debug="true">
	<dataset name="data">
		<items>
			<item name="first">
				<categories/>
			</item>
		</items>
	</dataset>

	<dataset name="categories">
		<categories>
			<category name="All"/>
			<category name="Cat 1"/>
			<category name="Cat 2"/>
		</categories>
	</dataset>

	<simplelayout axis="y"/>
	<view id="itemDisplay" datapath="data:/items/item">
		<simplelayout axis="y" spacing="3"/>
		<view name="nameEditor">
			<simplelayout axis="x" spacing="3"/>
			<text width="200">Name</text>
			<edittext datapath="@name"/>
		</view>
		<view>
			<simplelayout axis="x" spacing="3"/>
			<text width="200">Categories</text>
			<view id="checkboxes">
				<simplelayout axis="y" spacing="2"/>
				<view name="category" datapath="categories:/categories/*">
					<checkbox text="$path{'@name'}" name="$path{'@name'}"/>
				</view>					
			</view>		
		</view>		
	</view>
	<button>Save...
		<method event="onclick">
			itemDisplay.datapath.updateData();
			Debug.write("Data: " + itemDisplay.datapath.dupePointer().serialize());
		</method>
	</button>			
</canvas>

When run, this program will display an editext associated with the name  
attribute for the <item> element in the 'data' dataset.  It will also  
display a series of checkboxes whose names come a second XML dataset.  I  
want the user to be able to select one or more checkboxes, and when the  
Save button is hit, I want the XML associated with the 'data' dataset to  
be updated to reflect the selected categories.  As given above, suppose  
the user entered 'first-edited' in the edittext box and selected three of  
the checkboxes.  Upon completion of the Save operation, I would want the  
XML to look like this:

<items>
	<item name="first - edited">
		<categories>
			<category name="All"/>
			<category name="Cat 1"/>
			<category name="Cat 2"/>
		</categories>
	</item
</items>

As written, I can get the newly edited name value, but I don't know how to  
go about replacing the <categories> element of the original dataset with a  
new one based on the selected values in the 'checkboxes' view.  Using  
LzDataElement, I can create a proper <categories> tag with appropriate  
children, but I don't know how to update the 'data' dataset.  Can someone  
help me out on this?

Thanks!

-- 
James Howe


More information about the Laszlo-user mailing list