You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Thomas Cucchietti <th...@gmail.com> on 2010/05/11 14:05:17 UTC
[T5]Inject a component not used in a page
Hi everybody!
I'm getting a silly problem while trying to get a component from the
componentSource.
For dynamic layout purposes, i'm trying to recover a component that is not
used in any page but it seems impossible as the getComponent method of the
componentSource requires a completeId in which a page is required.
is there another way to get this component than creating a page that will be
never be displayed?
Thanks in advance!
Thomas.
Re: [T5]Inject a component not used in a page
Posted by Thomas Cucchietti <th...@gmail.com>.
Ok, Thanks for the suggestions, I'll do that (layout.tml) !
2010/5/11 Robert Zeigler <ro...@scazdl.org>
> Alternatively, if different pages need different blocks, you can declare a
> parameter to your layout of type "block":
>
> Layout.java:
> @Parameter(requred=true)
> @Property
> private Block customBlock;
>
> Layout.tml
>
> <t:delegate to="customBlock"/>
>
> Page.tml:
>
> <t:container xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"
> xmlns:p="tapestry:parameter">
> <t:layout>
> <p:customBlock>
> Here is my custom, page-specific content that will be rendered wherever
> the layout deems fit.
> </p:customBlock>
> </t:layout>
> </t:container>
>
> Otherwise, if all pages use the same markup, put the block inside of
> Layout.tml, as Thiago suggested.
>
> Robert
>
>
> On May 11, 2010, at 5/119:20 AM , Thiago H. de Paula Figueiredo wrote:
>
> On Tue, 11 May 2010 11:09:29 -0300, Thomas Cucchietti <
>> thomas.cucchietti@gmail.com> wrote:
>>
>> Hi Thiago,
>>>
>>
>> Hi!
>>
>> I can't declare it into my page as I'm using it in the Layout component
>>> and not in a page.
>>>
>>
>> In this case, you can declare the blocks in Layout itself. Take a look at
>> http://tapestry.apache.org/tapestry5.1/cookbook/switch.html to see an
>> example of using blocks and Delegate.
>>
>> Actually, I should declare the different templates (Blocks) in my
>>> Layout.tml. I don't like it very much as the templates may be quite
>>> numerous.... But it seems that I don't have other possibilities.
>>>
>>
>> You could do that too.
>>
>> For the easier way, I knew this one : efficient but I don't know why, I
>>> feel it quite dirty :p
>>>
>>
>> It's not dirty. Tapestry is just trading off a little convenience for more
>> performance and way less memory use than JSF, for example.
>>
>> --
>> Thiago H. de Paula Figueiredo
>> Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
>> and instructor
>> Owner, Ars Machina Tecnologia da Informação Ltda.
>> http://www.arsmachina.com.br
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
Re: [T5]Inject a component not used in a page
Posted by Robert Zeigler <ro...@scazdl.org>.
Alternatively, if different pages need different blocks, you can
declare a parameter to your layout of type "block":
Layout.java:
@Parameter(requred=true)
@Property
private Block customBlock;
Layout.tml
<t:delegate to="customBlock"/>
Page.tml:
<t:container xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd
" xmlns:p="tapestry:parameter">
<t:layout>
<p:customBlock>
Here is my custom, page-specific content that will be rendered
wherever the layout deems fit.
</p:customBlock>
</t:layout>
</t:container>
Otherwise, if all pages use the same markup, put the block inside of
Layout.tml, as Thiago suggested.
Robert
On May 11, 2010, at 5/119:20 AM , Thiago H. de Paula Figueiredo wrote:
> On Tue, 11 May 2010 11:09:29 -0300, Thomas Cucchietti <thomas.cucchietti@gmail.com
> > wrote:
>
>> Hi Thiago,
>
> Hi!
>
>> I can't declare it into my page as I'm using it in the Layout
>> component and not in a page.
>
> In this case, you can declare the blocks in Layout itself. Take a
> look at http://tapestry.apache.org/tapestry5.1/cookbook/switch.html
> to see an example of using blocks and Delegate.
>
>> Actually, I should declare the different templates (Blocks) in my
>> Layout.tml. I don't like it very much as the templates may be quite
>> numerous.... But it seems that I don't have other possibilities.
>
> You could do that too.
>
>> For the easier way, I knew this one : efficient but I don't know
>> why, I feel it quite dirty :p
>
> It's not dirty. Tapestry is just trading off a little convenience
> for more performance and way less memory use than JSF, for example.
>
> --
> Thiago H. de Paula Figueiredo
> Independent Java, Apache Tapestry 5 and Hibernate consultant,
> developer, and instructor
> Owner, Ars Machina Tecnologia da Informação Ltda.
> http://www.arsmachina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: [T5]Inject a component not used in a page
Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Tue, 11 May 2010 11:09:29 -0300, Thomas Cucchietti
<th...@gmail.com> wrote:
> Hi Thiago,
Hi!
> I can't declare it into my page as I'm using it in the Layout component
> and not in a page.
In this case, you can declare the blocks in Layout itself. Take a look at
http://tapestry.apache.org/tapestry5.1/cookbook/switch.html to see an
example of using blocks and Delegate.
> Actually, I should declare the different templates (Blocks) in my
> Layout.tml. I don't like it very much as the templates may be quite
> numerous.... But it seems that I don't have other possibilities.
You could do that too.
> For the easier way, I knew this one : efficient but I don't know why, I
> feel it quite dirty :p
It's not dirty. Tapestry is just trading off a little convenience for more
performance and way less memory use than JSF, for example.
--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: [T5]Inject a component not used in a page
Posted by Thomas Cucchietti <th...@gmail.com>.
Hi Thiago,
I can't declare it into my page as I'm using it in the Layout component and
not in a page.
Here is the Layout.java :
@Inject
private ComponentSource componentSource;
@Inject
private ComponentResources componentResources;
/** The page title, for the <title> element and the <h1> element. */
@Property
@Parameter(required = true, defaultPrefix = BindingConstants.LITERAL)
private String title;
/** The template name, for the structure of the layout. */
@Property
@Parameter(required = true, defaultPrefix = BindingConstants.LITERAL)
private String template;
public Object getSelectedTemplate(){
try {
Component selectedTemplate =
componentSource.getPage("internal/templates");
return
selectedTemplate.getComponentResources().getBlock(template+"_template");
}
catch (BlockNotFoundException e) {
return useDefaultTemplate(e);
}
catch (IllegalArgumentException e) {
return useDefaultTemplate(e);
}
}
private Object useDefaultTemplate(Throwable e) {
getLogger().error("Template ["+template+"] cannot be found, using
default instead",e);
return componentResources.getBlock("default_template");
}
Actually, I should declare the different templates (Blocks) in my
Layout.tml. I don't like it very much as the templates may be quite
numerous.... But it seems that I don't have other possibilities.
For the easier way, I knew this one : efficient but I don't know why, I feel
it quite dirty :p
Anyway, thanks for the help!
Thomas.
2010/5/11 Thiago H. de Paula Figueiredo <th...@gmail.com>
> On Tue, 11 May 2010 10:34:52 -0300, Thomas Cucchietti <
> thomas.cucchietti@gmail.com> wrote:
>
> So, I have to create a page only for internal use in order to follow this
>> philosophy.
>>
>
> You don't need to create a page just for holding your component. Just
> create a Block inside your page and declare you component there. Then you
> can use the Delegate component to render the component or not.
>
>
> How can I prevent user to access this page ?
>>
>
> Easier way: add this method to that page:
>
> Object onActivate() {
> return Index.class;
> }
>
> --
> Thiago H. de Paula Figueiredo
> Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
> and instructor
> Owner, Ars Machina Tecnologia da Informação Ltda.
> http://www.arsmachina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
Re: [T5]Inject a component not used in a page
Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Tue, 11 May 2010 10:34:52 -0300, Thomas Cucchietti
<th...@gmail.com> wrote:
> So, I have to create a page only for internal use in order to follow this
> philosophy.
You don't need to create a page just for holding your component. Just
create a Block inside your page and declare you component there. Then you
can use the Delegate component to render the component or not.
> How can I prevent user to access this page ?
Easier way: add this method to that page:
Object onActivate() {
return Index.class;
}
--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: [T5]Inject a component not used in a page
Posted by Thomas Cucchietti <th...@gmail.com>.
Hi Kristian,
Thanks for you answer : it confirms what I understood.
So, I have to create a page only for internal use in order to follow this
philosophy.
How can I prevent user to access this page ?
Is it based on package name ? ("internal" ?)
Should I use a service based on URL to block users attempting to access this
page ?
Thanks for you help!
Thomas.
2010/5/11 Kristian Marinkovic <kr...@porsche.co.at>
> hi thomas,
>
> tapestry 5 follows the "static structure, dynamic behaviour" philoshophy.
> essentially this means that you cant use a component that is not declared
> anywhere. in your case i'd create a block with the component inside and
> display this block if necessary.
>
> please see the mailing list for more on "static structure, dynamic
> behaviour"
> there. you can take a look at the BeanEditor that dynamically creates a
> input field for every field in a POJO. From the outside it appears as if
> the
> components are configured dynamically but under the covers it is
> reassembling existing blocks as needed (type, ...)
>
> g,
> kris
>
>
>
> Von: Thomas Cucchietti <th...@gmail.com>
> An: Tapestry users <us...@tapestry.apache.org>
> Datum: 11.05.2010 14:05
> Betreff: [T5]Inject a component not used in a page
>
>
>
> Hi everybody!
>
> I'm getting a silly problem while trying to get a component from the
> componentSource.
>
> For dynamic layout purposes, i'm trying to recover a component that is not
> used in any page but it seems impossible as the getComponent method of the
> componentSource requires a completeId in which a page is required.
>
> is there another way to get this component than creating a page that will
> be
> never be displayed?
>
> Thanks in advance!
>
> Thomas.
>
>
Re: [T5]Inject a component not used in a page
Posted by Kristian Marinkovic <kr...@porsche.co.at>.
hi thomas,
tapestry 5 follows the "static structure, dynamic behaviour" philoshophy.
essentially this means that you cant use a component that is not declared
anywhere. in your case i'd create a block with the component inside and
display this block if necessary.
please see the mailing list for more on "static structure, dynamic
behaviour"
there. you can take a look at the BeanEditor that dynamically creates a
input field for every field in a POJO. From the outside it appears as if
the
components are configured dynamically but under the covers it is
reassembling existing blocks as needed (type, ...)
g,
kris
Von: Thomas Cucchietti <th...@gmail.com>
An: Tapestry users <us...@tapestry.apache.org>
Datum: 11.05.2010 14:05
Betreff: [T5]Inject a component not used in a page
Hi everybody!
I'm getting a silly problem while trying to get a component from the
componentSource.
For dynamic layout purposes, i'm trying to recover a component that is not
used in any page but it seems impossible as the getComponent method of the
componentSource requires a completeId in which a page is required.
is there another way to get this component than creating a page that will
be
never be displayed?
Thanks in advance!
Thomas.