You /do/ realize that Thiago has already spent considerable time trying to help 
you?

In any event, your conceptual understanding of Tapestry seems a bit off. Not 
trying to be mean, just stating fact. For instance:

"Basically, is there is a way for a component to "inherit" properties of
child component (page)?  "

This suggests that you're thinking of the page as the child component. But the 
page isn't the child component. The page is the parent component.

You've also referred to pages "inheriting" from components:

"pages, like Index, are not inheriting layout etc, from component Layout? 
What am I missing?  "


There's no inheritance involved. Tapestry pages and components are generally 
built by composition, not inheritance.

Consider:
class Person {
   private String firstName;
   private String lastName;
}

Person is /composed/ of two String objects. But Person does not /inherit/ 
anything from String. It's not a String, it's a Person with two String 
properties. Likewise, String is not in any way tied specifically to Person.  
Imagine if the String object in java had some code like:

  if (containingObject.firstName.equals("George")) {...}

It's a bit preposterous, don't you think? :)

Yet, this is precisely what you're proposing.  Your Page is like the Person. It 
is composed of components, in an analogous way to how Person is composed of two 
String properties. 

Making your Components depend on specific details of the page (like whether it 
has a specific property) is a recipe for brittle components with no potential 
for reuse. Which is a shame because the point of components is reuse. 

All of that said, it's normal to adjust the behavior of the component to the 
requirements of the container. The two normal ways to do this are component 
parameters and the Environment service. Both of these solutions have been 
mentioned multiple times (3? 4?), but it appears that you are unfamiliar with 
the concepts, eg:

"I am not sure what the "Environment" solution referred really is. "

A good place to start is the documentation. :)
See:

http://tapestry.apache.org/component-parameters.html

For starters on component parameters, and:

http://tapestry.apache.org/environmental-services.html

For information on using the "Environment" solution.

Finally, you can accomplish directly what you're trying to do as:

Index.java:

public class Index implements MyInterface {

  public Object getSomeProperty() {..}//defined by MyInterface

}

Index.tml:
<t:layout/>

Layout.java:

@Inject
private ComponentSource cs;

@Inject
private ComponentResources resources;

@Cached
public MyInterface getMyInterfaceInstance() {
  Object o = cs.getPage(resources.getPageName());
  if (o instanceof MyInterface) {
     return (MyInterface) o;
  } else {
     return /* something else here, some reasonable value. null? Default 
implementation of MyInterface?*/;
  }
}

Layout.tml:
  ${myInterfaceInstance.someProperty}

But that's an awful lot of work for something that could be accomplished as:

public Class Index {
  public Object getSomeProperty() {...}
}

Index.tml:
  <t:layout parameterName="someProperty"/>

Layout.java:
  @Parameter
  private Object parameterName;

Layout.tml:
  ${parameterName}

You didn't have to create the interface. Layout can be used on any page. And 
any property can be used to satisfy the need for "parameterName". 

Cheers,

Robert

On May 3, 2012, at 5/31:49 PM , netdawg wrote:

> Good grief.  O well, that is probably more oxygen for others.  Thanks for you
> inputs nevertheless - the ones with substance, anyway.   As for "wink, wink,
> we are already doing magic" - it borders on delusional - suggesting some
> sort of inside clique that is bullying everyone else - helping some and not
> others - you have perfect right to do that, but that there will more
> footsteps out the door than in....possibly mine too.  Good bye. 
> 
> --
> View this message in context: 
> http://tapestry.1045711.n5.nabble.com/Can-Component-Template-be-Informed-by-Page-Class-tp5681397p5684049.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to