You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Izak Wessels <po...@gmail.com> on 2006/02/12 17:10:47 UTC

How to inject components?

Hello all,

I was wondering, how do one inject a component into a page?
For example, when the user clicks on a link, I want to pass the
id of the link that they clicked to my custom component.

// Trying to inject the page, so that I can set the id, so that the correct
details can be
// displayed on the following page
------------------------------------------------------------------------------------------------------------
@InjectPage("CementSupplierProductSpecificationComponent")
public abstract CementSupplierProductSpecificationComponent
getCementSupplierProductSpecificationComponent();

// When clicking the link, set the id on the page -> Line 4
------------------------------------------------------------------------
1.    public QuotationSupplierProductDetailsPage
onShowQuotationSupplierProductDetails(Integer supplierProductID) {
2.
3.        if
(getAgentSession().getCategory().getCategoryName().equals("Cement")) {
4.
getCementSupplierProductSpecificationComponent().setSupplierProductID(supplierProductID);
5.        }
6.        return getQuotationSupplierProductDetailsPage();
7.    }


Thanks,

-- Izak

Re: How to inject components?

Posted by Izak Wessels <po...@gmail.com>.
Not a problem, got it working on my page :)

I used the @InjectComponent annotation.

Problem now is, that I am looping through a loop and I want to display each
product's specs. Will e-mail you a bit later.

Thanks

On 2/13/06, Alan Chandler <al...@chandlerfamily.org.uk> wrote:
>
> On Sunday 12 February 2006 21:35, Izak Wessels wrote:
> > Alan,
> >
> >
> > Hehe, not sure it it's appropriate but a chat via msn messenger might be
> > quicker and more
> > productive. Ok if I mail it to you privately?
> >
>
> Sure, whatever you want.
>
> Try mail first, and then I can do a msn chat after if you want (although
> not
> tonight)
>
>
> --
> Alan Chandler
> http://www.chandlerfamily.org.uk
> Open Source. It's the difference between trust and antitrust.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>

Re: How to inject components?

Posted by Alan Chandler <al...@chandlerfamily.org.uk>.
On Sunday 12 February 2006 21:35, Izak Wessels wrote:
> Alan,
>
>
> Hehe, not sure it it's appropriate but a chat via msn messenger might be
> quicker and more
> productive. Ok if I mail it to you privately?
>

Sure, whatever you want.

Try mail first, and then I can do a msn chat after if you want (although not 
tonight)


-- 
Alan Chandler
http://www.chandlerfamily.org.uk
Open Source. It's the difference between trust and antitrust.

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


Re: How to inject components?

Posted by Izak Wessels <po...@gmail.com>.
Alan,


Hehe, not sure it it's appropriate but a chat via msn messenger might be
quicker and more
productive. Ok if I mail it to you privately?

Izak

On 2/12/06, Alan Chandler < alan@chandlerfamily.org.uk> wrote:
>
> On Sunday 12 February 2006 18:21, Izak Wessels wrote:
> > Ok, let me describe my problem in a bit more detail via an analogy.
> >
> > Let's say I have a html table, called ComputerPartTable, in a file -
> > ComputerPart. This table
> > has the following columns : partID, partName,partDesc. Now the user
> > can click on the partID column and that will forward them to another
> page,
> > ComputerPartDetails, that displays the details of the selected computer
> > part.
>
> so this is a table inside some form of @For loop?
>
> <table>
> <tr jwcid="@For" source="ognl:listOfParts" value="ognl:thisPart"
> element="tr">
> <td><a jwcid="@DirectLink" listener="listener:doShowPartDetails"
> parameters="ognl:thisPart.id"><span jwcid="@Insert"
> value="ognl:thisPart.id"> ...</span></a></td>
> ... other columns
> </tr>
> </table>
>
>
>
> >
> > Now, each part has different attributes. CPU has clockspeed, fsb speed,
> > etc.
> >
> > RAM has size, speed, etc.
> >
>
> So in the java for the ComputerPart.jave
>
> InjectPage("PartDetails")
> public abstract IPage getPartDetailsPage();
>
> public IPage doShowPartDetails (int partId) {
>         IPage pd = getPartDetailsPage();
>         pd.setPartId();
>         return pd;
> }
>
>
> > Ok, so I have created a custom component, called CPUComponentPart.jwcthat
> > lists the relevant details of a CPU component. But what I want to do is,
> I
> > want to pass
> > the partID to the CPUComponentPart.java so that I can lookup the correct
> > details of
> > the selected part.
> >
> > So in my ComputerPart I have
>
> I think you are doing this backwards maybe
> >
> > @Parameter
> > public abstract CPUComponentPart getCPUComponentPart();
>
> where does this form action get called from, is this after the user has
> filled
> stuff in?
> >
> > public void onFormAction(Integer partID) {
> >   getCPUComponentPart().setPartID(partID); // this is the line where i
> am
> > getting an exception
> > }
>
>
> What you seem to be missing is the PartDetailsPage
>
> public class PartDetails extends BasePage implements PageRenderListener {
>
> public abstract void setPartId(int id):
> public abstract int getPartId();
>
> public abstract void setComponentPart (CPUComponentPart cp);
>
>
> public void pageBeginRender (PageEvent event) {
>
>                 if(!event.getRequestCycle().isRewinding()) {
>
>                         setComponentPart(someFunctionToGetComponentFromPartID(getPartId());
> ....
> }
>
> and then in
>
> PartDetails.html
>
> <span jwcid="@ComponentPart" CPUComponentPart="ognl:componentPart" />
>
>
>
>
> I've probably still totally missunderstood what you are trying to do - but
> thats how I would do what you seem to be trying to do.  NOTE:  I tend to
> avoid specification files and specify everything in-line.  You can
> obviously
> move it out to specification files if you want.
>
>
> --
> Alan Chandler
> http://www.chandlerfamily.org.uk
> Open Source. It's the difference between trust and antitrust.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>

Re: How to inject components?

Posted by Alan Chandler <al...@chandlerfamily.org.uk>.
On Sunday 12 February 2006 18:21, Izak Wessels wrote:
> Ok, let me describe my problem in a bit more detail via an analogy.
>
> Let's say I have a html table, called ComputerPartTable, in a file -
> ComputerPart. This table
> has the following columns : partID, partName,partDesc. Now the user
> can click on the partID column and that will forward them to another page,
> ComputerPartDetails, that displays the details of the selected computer
> part.

so this is a table inside some form of @For loop?

<table>
<tr jwcid="@For" source="ognl:listOfParts" value="ognl:thisPart" element="tr">
<td><a jwcid="@DirectLink" listener="listener:doShowPartDetails" 
parameters="ognl:thisPart.id"><span jwcid="@Insert" 
value="ognl:thisPart.id"> ...</span></a></td>
... other columns
</tr>
</table>



>
> Now, each part has different attributes. CPU has clockspeed, fsb speed,
> etc.
>
> RAM has size, speed, etc.
>

So in the java for the ComputerPart.jave

InjectPage("PartDetails")
public abstract IPage getPartDetailsPage();

public IPage doShowPartDetails (int partId) {
	IPage pd = getPartDetailsPage();
	pd.setPartId();
	return pd;
}


> Ok, so I have created a custom component, called CPUComponentPart.jwc that
> lists the relevant details of a CPU component. But what I want to do is, I
> want to pass
> the partID to the CPUComponentPart.java so that I can lookup the correct
> details of
> the selected part.
>
> So in my ComputerPart I have

I think you are doing this backwards maybe
>
> @Parameter
> public abstract CPUComponentPart getCPUComponentPart();

where does this form action get called from, is this after the user has filled 
stuff in?
>
> public void onFormAction(Integer partID) {
>   getCPUComponentPart().setPartID(partID); // this is the line where i am
> getting an exception
> }


What you seem to be missing is the PartDetailsPage

public class PartDetails extends BasePage implements PageRenderListener {

public abstract void setPartId(int id):
public abstract int getPartId();

public abstract void setComponentPart (CPUComponentPart cp); 


public void pageBeginRender (PageEvent event) {
		
		if(!event.getRequestCycle().isRewinding()) {
			setComponentPart(someFunctionToGetComponentFromPartID(getPartId());
.... 
}

and then in 

PartDetails.html

<span jwcid="@ComponentPart" CPUComponentPart="ognl:componentPart" /> 




I've probably still totally missunderstood what you are trying to do - but 
thats how I would do what you seem to be trying to do.  NOTE:  I tend to 
avoid specification files and specify everything in-line.  You can obviously 
move it out to specification files if you want.


-- 
Alan Chandler
http://www.chandlerfamily.org.uk
Open Source. It's the difference between trust and antitrust.

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


Re: How to inject components?

Posted by Ron Piterman <rp...@gmx.net>.
I think its like that:
1. transition is performed in listener objects. If you want to activate 
a page *and* pass parameters you get the page from the RequestCycle, 
cast it to the needed class and set your parameters.
I preffer to use external links (and IExternalPage) for that, since the 
user can easily bookmark the page.

2. now in your new page, you "delegate" the real job to some component 
inside the page. For that you use component parameters - so you store 
the value on a page property (or, if you need, a state object...) and 
bind the component's parameter to this property (or, in case of state 
property, you inject the object to your component directly, not 
recommended though for what you do, since its more a flow than a state...).

Hope that helps,
Cheers,
Ron



Izak Wessels wrote:
> Ok, let me describe my problem in a bit more detail via an analogy.
> 
> Let's say I have a html table, called ComputerPartTable, in a file -
> ComputerPart. This table
> has the following columns : partID, partName,partDesc. Now the user
> can click on the partID column and that will forward them to another page,
> ComputerPartDetails, that displays the details of the selected computer
> part.
> 
> Now, each part has different attributes. CPU has clockspeed, fsb speed, etc.
> 
> RAM has size, speed, etc.
> 
> Ok, so I have created a custom component, called CPUComponentPart.jwc that
> lists the relevant details of a CPU component. But what I want to do is, I
> want to pass
> the partID to the CPUComponentPart.java so that I can lookup the correct
> details of
> the selected part.
> 
> So in my ComputerPart I have
> 
> @Parameter
> public abstract CPUComponentPart getCPUComponentPart();
> 
> public void onFormAction(Integer partID) {
>   getCPUComponentPart().setPartID(partID); // this is the line where i am
> getting an exception
> }
> 
> Hope that helps,
> 
> -- Izak
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> On 2/12/06, Alan Chandler <al...@chandlerfamily.org.uk> wrote:
> 
>>On Sunday 12 February 2006 16:10, Izak Wessels wrote:
>>
>>>Hello all,
>>>
>>>I was wondering, how do one inject a component into a page?
>>>For example, when the user clicks on a link, I want to pass the
>>>id of the link that they clicked to my custom component.
>>
>>I am not sure I fully understand what you are doing.
>>
>>If you use the @DirectLink component, you can specify some parameters
>>which
>>get passed to the listener when he clicks on the link.  Pass the ID (or
>>the
>>object if its not too big) of the right object.
>>
>><a jwcid="@DirectLink" listener="listener:doSomthing" parameters="ognl:
>>{supplierProduct.id, any other parameters ...}"> ...
>>
>>
>>If on the other hand you are trying to use a component
>>
>><span jwcid="@MyComponent" product="ognl:supplierProduct" >
>>
>>inside your java class for the component
>>
>>@Parameter
>>public abstract CementSupplierProductSpecificationComponent getProduct();
>>
>>or maybe its a combination of the two?
>>
>>--
>>Alan Chandler
>>http://www.chandlerfamily.org.uk
>>Open Source. It's the difference between trust and antitrust.
>>
>>---------------------------------------------------------------------
>>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: How to inject components?

Posted by Izak Wessels <po...@gmail.com>.
Ok, let me describe my problem in a bit more detail via an analogy.

Let's say I have a html table, called ComputerPartTable, in a file -
ComputerPart. This table
has the following columns : partID, partName,partDesc. Now the user
can click on the partID column and that will forward them to another page,
ComputerPartDetails, that displays the details of the selected computer
part.

Now, each part has different attributes. CPU has clockspeed, fsb speed, etc.

RAM has size, speed, etc.

Ok, so I have created a custom component, called CPUComponentPart.jwc that
lists the relevant details of a CPU component. But what I want to do is, I
want to pass
the partID to the CPUComponentPart.java so that I can lookup the correct
details of
the selected part.

So in my ComputerPart I have

@Parameter
public abstract CPUComponentPart getCPUComponentPart();

public void onFormAction(Integer partID) {
  getCPUComponentPart().setPartID(partID); // this is the line where i am
getting an exception
}

Hope that helps,

-- Izak










On 2/12/06, Alan Chandler <al...@chandlerfamily.org.uk> wrote:
>
> On Sunday 12 February 2006 16:10, Izak Wessels wrote:
> > Hello all,
> >
> > I was wondering, how do one inject a component into a page?
> > For example, when the user clicks on a link, I want to pass the
> > id of the link that they clicked to my custom component.
>
> I am not sure I fully understand what you are doing.
>
> If you use the @DirectLink component, you can specify some parameters
> which
> get passed to the listener when he clicks on the link.  Pass the ID (or
> the
> object if its not too big) of the right object.
>
> <a jwcid="@DirectLink" listener="listener:doSomthing" parameters="ognl:
> {supplierProduct.id, any other parameters ...}"> ...
>
>
> If on the other hand you are trying to use a component
>
> <span jwcid="@MyComponent" product="ognl:supplierProduct" >
>
> inside your java class for the component
>
> @Parameter
> public abstract CementSupplierProductSpecificationComponent getProduct();
>
> or maybe its a combination of the two?
>
> --
> Alan Chandler
> http://www.chandlerfamily.org.uk
> Open Source. It's the difference between trust and antitrust.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>

Re: How to inject components?

Posted by Alan Chandler <al...@chandlerfamily.org.uk>.
On Sunday 12 February 2006 16:10, Izak Wessels wrote:
> Hello all,
>
> I was wondering, how do one inject a component into a page?
> For example, when the user clicks on a link, I want to pass the
> id of the link that they clicked to my custom component.

I am not sure I fully understand what you are doing. 

 If you use the @DirectLink component, you can specify some parameters which 
get passed to the listener when he clicks on the link.  Pass the ID (or the 
object if its not too big) of the right object.  

<a jwcid="@DirectLink" listener="listener:doSomthing" parameters="ognl:
{supplierProduct.id, any other parameters ...}"> ...


If on the other hand you are trying to use a component

<span jwcid="@MyComponent" product="ognl:supplierProduct" >

inside your java class for the component

@Parameter
public abstract CementSupplierProductSpecificationComponent getProduct();

or maybe its a combination of the two?

-- 
Alan Chandler
http://www.chandlerfamily.org.uk
Open Source. It's the difference between trust and antitrust.

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


Re: How to inject components?

Posted by Izak Wessels <po...@gmail.com>.
Ok, made some progress, by removing the line
@InjectPage("CementSupplierProductSpecificationComponent"), however I get a
NullPointerException at the following line :

getCementSupplierProductSpecificationComponent().setSupplierProductID(supplierProductID);

I believe that it doesn't actually set the supplierProductID on the
component. Anybody have any thoughts
on how I can accomplish this?

On 2/12/06, Izak Wessels <po...@gmail.com> wrote:
>
> Hello all,
>
> I was wondering, how do one inject a component into a page?
> For example, when the user clicks on a link, I want to pass the
> id of the link that they clicked to my custom component.
>
> // Trying to inject the page, so that I can set the id, so that the
> correct
> details can be
> // displayed on the following page
>
> ------------------------------------------------------------------------------------------------------------
> @InjectPage("CementSupplierProductSpecificationComponent")
> public abstract CementSupplierProductSpecificationComponent
> getCementSupplierProductSpecificationComponent();
>
> // When clicking the link, set the id on the page -> Line 4
> ------------------------------------------------------------------------
> 1.    public QuotationSupplierProductDetailsPage
> onShowQuotationSupplierProductDetails(Integer supplierProductID) {
> 2.
> 3.        if
> (getAgentSession().getCategory().getCategoryName().equals("Cement")) {
> 4.
>
> getCementSupplierProductSpecificationComponent().setSupplierProductID(supplierProductID);
> 5.        }
> 6.        return getQuotationSupplierProductDetailsPage();
> 7.    }
>
>
> Thanks,
>
> -- Izak
>
>