PDA

View Full Version : Menu Label Attribute


andy_k_scott
10-28-2003, 12:53 PM
Hi,

I'm trying to build a Laszlo menubar dynamically from an XML dataset. I can't seem to find a way to either set the label attribute on the menu using a value from the dataset, nor change the label in script. Am I missing something, or is this not possible right now?

Thanks,
andy

antun
10-28-2003, 01:00 PM
What you're doing sounds a little weird - could you post some code?

Are you trying to build the entire menu structure from an XML dataset, or are you just replicating a menuitem several times based on the XML data?

If its the latter, that sounds pretty reasonable to me.

-Antun

andy_k_scott
10-28-2003, 01:34 PM
Antun,

Thanks for your reply. I'll try to provide more info to clear things up:

I'm actually doing the former with a simple two-level navigation hierarchy as my dataset, something like:

<nav>
<category label="cat1" link="linkCat1">
<item label="item1-1" link="linkItem1-1">
<item label="item1-2" link="linkItem1-2">
</category>
<category label="cat2" link="linkCat2">
.
.
.
</nav>

So far, I've got the menubar up and can get the menu's replicated (one for each category) as needed using the datapath attribute, but can't figure out how to set the label attribute using the label from the dataset.

My lzx looks like:

<menubar datapath="nav">
<menu datapath="category" hasbutton="true" label="Test"/>
</menubar>

(This just has the menu label set to 'Test'. Also, I haven't tried to add the menuitem's yet since I couldn't get the menu's working.)

Hopefully this clarifies my question, but let me know if you need more info.

Thanks,
andy

antun
10-28-2003, 02:21 PM
I think that the menu items might not be able to replicated because of the way they are coded. I'm not 100% sure about this, but that's my best guess. Here's what I tried:


<canvas debug="true" width="800">
<debug x="100" y="45" />

<dataset name="nav">
<nav>
<category label="cat1" link="linkCat1">
<item label="item1-1" link="linkItem1-1" />
<item label="item1-2" link="linkItem1-2" />
</category>

<category label="cat2" link="linkCat2">
<item label="item3" link="linkItem1-1" />
<item label="item4" link="linkItem1-2" />
</category>

<category label="cat3" link="linkCat2">
<item label="item3" link="linkItem1-1" />
<item label="item4" link="linkItem1-2" />
</category>
</nav>
</dataset>

<menubar width="200" height="25" datapath="nav:/nav">
<menu datapath="category"
hasbutton="true" width="100">
<method event="ondata">
var d = this.datapath.getXPath( '@label' );
debug.write( "Setting label to: " + d );
this.setAttribute( "label", d );
</method>

<menuitem label="Item 1" onclick="canvas.whichOne(this);"/>
<menuitem label="Item 2" onclick="canvas.whichOne(this);"/>
<menuitem label="Item 3" onclick="canvas.whichOne(this);"/>
<menuseparator/>
<menuitem label="Item 4" onclick="canvas.whichOne(this);"/>
</menu>
</menubar>
</canvas>


As you can see, the debugger spits out the correct label attributes, but they do not appear correctly. In fact the third one has the correct attribute from the first.

I'll let you know if I come up with anything.

Was there a reason you wanted to replicate them, instead of just code the menu structure from scratch?

-Antun

andy_k_scott
10-28-2003, 02:41 PM
Antun,

Thanks for checking into this. I made similar attempts at this with the ondata event and setAttribute method, but without success. I'd appreciate it if you kept this thread up-to-date with anything you find.

The reason I'm interested in generating the menu structure from xml data is that I'm currently doing some prototyping with our existing app's xml output during our evaluation process. I was hoping to just directly convert our existing xml nav hierarchy into a menu hierarchy in Laszlo, though I'm sure there are ways we could work around this if necessary.

Thanks for your help,
andy

antun
10-28-2003, 03:07 PM
I see what you mean - you want to be able to request the XML data at runtime from some existing XML source.

I'll keep you posted on what I find out.

-Antun

pruch
04-20-2005, 07:13 AM
We have a international Laszlo application and we need to change dynamically the labels of menus, when the language is changed by the user. So I was quite annoyed seeing that there is no possibility to give a datapath to a menu tag, updating automatically from the dataset.
I was so annoyed that I looked deeper into the Laszlo code and saw after a minute why it was not updated at all. I inserted a simple "ontext" event to the "menu"-class in the "menu.lzx" file and what did I see ? The menu button updates the way he should.

The event I inserted is the following:

<method event="ontext">
if (this._menubutton!=null) {
this._menubutton.setAttribute('text', this.text);
}
</method>

Now my question: Is this solution too simple ? It works fine for me and does everything I expect of it.

rachel
05-30-2005, 03:04 PM
Your tip about altering menu's ontext event does seem to work - I made a new class that extended menu, instead of altering the menu source code. It also solves the problem with using a datapath to set the text for a menu item:
e.g.:
<dyn_menu datapath="loginsubmit:/items/access/username/text()" />

pruch
05-30-2005, 11:16 PM
Obviously the better way to do it. I should have had the idea by myself. But it's a shame that you still have to worry about this, the guys of Laszlo should have fixed the problem since years. It is a very basic component!
By the way, be careful when you try to replicate the menu item, there are problems too.

Good luck!

mjconnolly
06-03-2005, 07:28 AM
Can one of you guys give an absolute newbie in Laszlo some examples of how this solution looks in detail? My problem is this:
I have a number of grids which pull data from XML datasets. The datasets are sets of values which change every week. I want to be able to show the possible weeks (dates) in a menu or set of radio buttons, and then pass that as a search criterion into those grid datasets. Does that make sense?
If I can figure out how to create either menuitems or radiobuttons on the fly from the list of possible dates I will through the rest myself, but that first step is eluding me...
Thanks
Martin

rachel
06-03-2005, 10:30 AM
I think you want to set a query parameter for the dataset and then do the request.

You would put this code into the event handler for when the person uses your menu or radio buttons.

mydataset.setQueryParams({param1: value1});
mydataset.doRequest();

That should refresh your datasets. Hope that helps.

mjconnolly
06-04-2005, 09:08 AM
OK, thanks, that makes sense. I can see how to get the datasets updated now. But how can I create the menu (for example) dynamically from XML returned from a database query? A pointer to an example would be v.helpful.
Thanks!