PDA

View Full Version : Create a view "wrapper"


DataSmithy
06-07-2006, 04:45 PM
What is the easiest way in openLaszlo to do something like this:

<class name="box" >
<view name="wrapper" x="10" y="10">
${classroot.myNodes}
</view>
</class>

Called like this:

<box>
<view name="one"></view>
<view name="two"></view>
<view name="three"></view>
</box>

I want the contents of "box" (views 1,2,3) to be wrapped inside of the "wrapper" view.

I want do do this using a class.

The effect should be similar to using the ".innerHTML" property in javascript.

l0gin
06-07-2006, 05:59 PM
Hi DataSmithy,

OpenLaszlo offers great mechanisms about replication.
As far as I understood, you can create a view tag, attaching its datapath to a dataset.
Then when attached to a dataset which has multiple values, a LzReplicationManager will be created which will instantiate as many objects as needed with same class as you written (and you written once only - see this: http://www.laszlosystems.com/lps-3.3/docs/guide/databinding.html#databinding.lazy-replication and this lzx ref http://www.laszlosystems.com/lps-3.3/docs/reference/lzlazyreplicationmanager.html).
Then, in another view, you could have a listbox mapped to the datapath of the view's data view.datapath
http://www.laszlosystems.com/lps-3.3/docs/reference/replicationmanager.html#attr-datapath. You can also use the same mechanism to show in it as many items as there is in the mapped dataset.

DataSmithy
06-07-2006, 09:39 PM
I found what I was looking for. I was missing the concept of a "defaultplacement" view.

http://localhost:8080/lps-3.3/docs/guide/classes-tutorial.html

Seems like this subject deserves a litte more comprehsive coverage in the docs, as well as a few examples. One of the first things I wanted to do was create classes to wrap functionality and design elements around other elements.

Comming from the perspective of ColdFusion (another xml/tag based language) this seemed like it should have been easier and more obvious to figure out.

This concept is core to creating components that extend the language.

Shelby
06-08-2006, 06:01 AM
I'm not entirely certain I understand what you are asking, but your box example in the first post will actually wrap those views.


<class name="box"/>


Given a class box, you can wrap views in it like so:


<box>
<view1/>
<view2/>
<view3/>
</box>


Or, if the contents of the wrapper are static:


<class name="box">
<view1/>
<view2/>
<view3/>
</class>


Of course, there are many ways to go about this. Default placement really allows you to have one parent and display the view in a different. For example, you want a view's parent to be some sort of controller class. Within that class, there is an embedded content view where you want the new view to be placed.

DataSmithy
06-11-2006, 12:01 PM
My original example should have had multiple view to better show the problem. The question I had was "where in the class will the views in the instance be wrapped inside.

Here is a better example that describes the basic problem I was having. Also, it answers the question "What is the default defaultplacement?"

Answer: after all of the class views.

DataSmithy
06-11-2006, 12:14 PM
Here is the output of the test file.

l0gin
06-11-2006, 01:59 PM
Perhaps you can add a property to class things, then use :
view.searchSubviews()
LzView.searchSubviews(prop, val)
Search all subviews for a named property. For now, returns when it finds the first one. This is a width first search.

Parameters
Name Type Desc
prop String named property
val value for that property
Returns
Type Desc
LzView the first subview whose property prop is set to val 'val' or null if none is found

The problem is : It will return only one view..
Don't know if this can help.
Perhpas you can create your own function returning array of view using source code :)