You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Anitha <aa...@sbc.com> on 2005/06/23 22:37:46 UTC

Tacos Tree : Conditional selection of class for node label

Hi,
 I've been able to successfully use the tacos tree component for the most part, 
to implement a tree design for our application. However, I am running into the 
issue of not being able to conditionally select the class (style) to use for 
displaying the node label. 

The implementation is very similar to the tacos file tree demo. However, the 
condition "node==selectedNode" always evaluates to false. I have also tried 
the "node.equals(selectedNode)", but that doesn't work either. Any pointers, 
suggestions would be greatly appreciated.

Thanks!
-Anitha.

Code snippets are as follows.

.page
-----

<property-specification name="node" type="<package>.TreeNode"/>

<property-specification name="selectedNode" type=<packae>.TreeNode" 
persistent="yes"/>

<component id="nodeLabel" type="Insert">
  <binding name="value" expression="node.name"/>
  <binding name="class" 
expression="node==selectedNode ? 'selected' : 'notSelected'"/> 
</component>


.html
-----
<div id="tree" jwcid="campaignTree"><a jwcid="nodeLink"><img jwcid="icon" 
align="absbottom"/><span jwcid="nodeLabel"/></a>
</div>

.java - Page class
-----
public abstract TreeNode getSelectedNode();
public abstract void setSelectedNode(TreeNode node);

public void select(IRequestCycle cycle) 
{
		
Object[] parameters = cycle.getServiceParameters();
String name = (String) parameters[0];
String id = (String) parameters[1];
		
TreeNode node = new TreeNode(name, id);
setSelectedNode(node);		
		
}

.css
----
#tree {
    background-color:#FFFFFF;
    position: absolute;
    top: 140px;
    bottom: 0;
    left: 50px;
    width: 500px;
    overflow: auto;
    height: 350px;
    border:solid;
    margin-left: 2px;
    margin-bottom: 1em;
}

#tree a {
	text-decoration: none;
}

#tree a:hover {
	background-color: #aaaaaa;
}

#tree .selected {
	font-weight:bold; 
	color:#0000CC;
	font-size:90%;
	text-decoration: underline;
}

#tree .notSelected {
	font-weight:normal; 
	color:#000000;
	font-size:90%;
	text-decoration: none;
}



---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Tacos Tree : Conditional selection of class for node label

Posted by Viktor Szathmary <ph...@gmail.com>.
On 6/24/05, Jijoe <pu...@yahoo.com> wrote:
> Viktor Szathmary <phraktle <at> gmail.com> writes:
> 
> >
> > first of all i see that in your implementation you have a TreeNode
> > class.. do you really need this? the idea is that your ContentProvider
> > implementation should directly expose your domain objects (so you dont
> > have to create a TreeNode class)...
> 
> Does anyone know why the FileTree.page (in Tacos FileTree demo) declares the
> selectedFile property as persistent = yes?

The demo tries to keep things relatively simple. In case your domain
object is not serializable, you will need instead store some sort of
ID as a persistent property, and make your listener set that. I feel
like people who have a good enough understanding of the issue you have
described above, should certainly not have difficulty implementing
this two-liner change.. :)

 viktor

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Tacos Tree : Conditional selection of class for node label

Posted by Jijoe <pu...@yahoo.com>.
Viktor Szathmary <phraktle <at> gmail.com> writes:

> 
> first of all i see that in your implementation you have a TreeNode
> class.. do you really need this? the idea is that your ContentProvider
> implementation should directly expose your domain objects (so you dont
> have to create a TreeNode class)...

Your question brings up a deeper question (in my mind, at least). I'm guessing
most people look to the FileTree demo as a template on using the Tacos Tree
component. Hence, they are bound to mimic the organization of that demo.

Does anyone know why the FileTree.page (in Tacos FileTree demo) declares the
selectedFile property as persistent = yes?

<property-specification name="selectedFile" type="java.io.File" 
persistent="yes"/>

The way I understand Tapestry's handling of persistent page properties, it
serializes persistent objects and stores them into HTTP session. And therein
lies the problem with using domain objects directly. 

If I have a domain model with a Parent class that can be composed of many Parent
or Child classes (a hierarchy stored as a private List within Parent, perhaps),
making this Parent class a "selectedParent" (mimicing the demo) and declaring it
persistent would cause a potentially large object graph to be stored into HTTP
session. Using simple domain objects directly would work I guess.

As you can see, this argument hinges on the apparent necessity for declaring a
"selectedFoo" as persistent.

Thoughts/comments appreciated.

Jijoe


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Tacos Tree : Conditional selection of class for node label

Posted by sj <my...@gmail.com>.
Hi Anitha,

I have a similar situation. Will be great if you can share your code

Ty

On 6/23/05, Anitha <aa...@sbc.com> wrote:
> Viktor Szathmary <phraktle <at> gmail.com> writes:
> 
> >
> > On 6/23/05, Anitha <aa1596 <at> sbc.com> wrote:
> > >
> > > The implementation is very similar to the tacos file tree demo. However, the
> > > condition "node==selectedNode" always evaluates to false. I have also tried
> > > the "node.equals(selectedNode)", but that doesn't work either. Any pointers,
> > > suggestions would be greatly appreciated.
> >
> > first of all i see that in your implementation you have a TreeNode
> > class.. do you really need this? the idea is that your ContentProvider
> > implementation should directly expose your domain objects (so you dont
> > have to create a TreeNode class)...
> >
> > regardless, how does your domain object (TreeNode in this case)
> > implement the equals() method? since you're creating a new instance in
> > your select() listener, you must ensure that the equals(..) is
> > overriden and will return true for a different object instance that's
> > identical...
> >
> >  viktor
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tapestry-user-unsubscribe <at> jakarta.apache.org
> > For additional commands, e-mail: tapestry-user-help <at> jakarta.apache.org
> >
> >
> 
> Thanks Viktor. It works great now that I've overriden the equals
> implementation.
> 
> The TreeNode class is used for traversing the tree and is a light weight
> alternative to the actual domain object . The idea was to delay populating the
> actual domain object data only when it needs to be viewed / modified.
> 
> -Anitha.
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Tacos Tree : Conditional selection of class for node label

Posted by Anitha <aa...@sbc.com>.
Viktor Szathmary <phraktle <at> gmail.com> writes:

> 
> On 6/23/05, Anitha <aa1596 <at> sbc.com> wrote:
> > 
> > The implementation is very similar to the tacos file tree demo. However, the
> > condition "node==selectedNode" always evaluates to false. I have also tried
> > the "node.equals(selectedNode)", but that doesn't work either. Any pointers,
> > suggestions would be greatly appreciated.
> 
> first of all i see that in your implementation you have a TreeNode
> class.. do you really need this? the idea is that your ContentProvider
> implementation should directly expose your domain objects (so you dont
> have to create a TreeNode class)...
> 
> regardless, how does your domain object (TreeNode in this case)
> implement the equals() method? since you're creating a new instance in
> your select() listener, you must ensure that the equals(..) is
> overriden and will return true for a different object instance that's
> identical...
> 
>  viktor
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe <at> jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help <at> jakarta.apache.org
> 
> 

Thanks Viktor. It works great now that I've overriden the equals 
implementation. 

The TreeNode class is used for traversing the tree and is a light weight 
alternative to the actual domain object . The idea was to delay populating the 
actual domain object data only when it needs to be viewed / modified.

-Anitha.  



---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Tacos Tree : Conditional selection of class for node label

Posted by Viktor Szathmary <ph...@gmail.com>.
On 6/23/05, Anitha <aa...@sbc.com> wrote:
> 
> The implementation is very similar to the tacos file tree demo. However, the
> condition "node==selectedNode" always evaluates to false. I have also tried
> the "node.equals(selectedNode)", but that doesn't work either. Any pointers,
> suggestions would be greatly appreciated.

first of all i see that in your implementation you have a TreeNode
class.. do you really need this? the idea is that your ContentProvider
implementation should directly expose your domain objects (so you dont
have to create a TreeNode class)...

regardless, how does your domain object (TreeNode in this case)
implement the equals() method? since you're creating a new instance in
your select() listener, you must ensure that the equals(..) is
overriden and will return true for a different object instance that's
identical...

 viktor

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org