You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by "Rabenau, David (Non-Associate)" <dr...@Schnucks.com> on 2004/06/15 17:49:46 UTC

Interactive Component Question

Hi all!

I'm a relative newbie to Tapestry and I am having trouble understanding how
to create an interactive component.  The overall gist of what I am trying is
to have an link on a page that when triggered will covert an
org.w3c.dom.Document to a Excel document (a
org.apache.poi.hssf.usermodel.HSSFWorkbook).

I've built a "WorkbookLink" component which includes a Conditional component
which itself includes a DirectLink component.  If the Document is not null,
then the link is supposed to display, which it does.  If the user clicks on
the link, the link is supposed to trigger the downloadAction() method in
WorkbookLink.java, which it does.  However, at that point the same Document
that was not null for Conditional is now null by the time it gets to
DirectLink.

I suspect this has something to do with the way I've tried to jimmie up the
listener, but I'm lost as to what to do next.  Any help would be greatly
appreciated.

David


Here is the compoonent's template (WorkbookLink.html):

<span jwcid="Conditional">
	<a jwcid="DirectLink">
		Get Report As Excel
	</a>
</span>


Here is it's jwc:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE component-specification
      PUBLIC "-//Apache Software Foundation//Tapestry Specification 3.0//EN"
      "http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd">
<component-specification class="com.smi.tapestry.components.WorkbookLink" 
    allow-body="no" 
    allow-informal-parameters="yes">
    <parameter name="srcdoc" direction="in" required="yes"
        type="com.smi.utility.web.xml.SqlResultDocument" />
    <parameter name="condition" direction="in" required="yes"
        type="java.lang.Object" />
    <component id="Conditional" type="Conditional">
        <binding name="condition" expression="condition" />
    </component>
    <component id="DirectLink" type="DirectLink">
        <binding name="listener" expression="listeners.downloadAction" />
        <binding name="srcdoc" expression="srcdoc" />
    </component>    
</component-specification>

Here is the html tag for it:

<span jwcid="@WorkbookLink" srcdoc="ognl:visit.report"
condition="ognl:visit.report" />

Finally, here is the WorkbookLink.java:

public abstract class WorkbookLink extends BaseComponent //implements
IActionListener//implements IDirect
{
	//public SqlResultDocument report;
	public abstract SqlResultDocument getSrcdoc();

	public void downloadAction(IRequestCycle cycle)
	{
		SqlResultDocument doc = getSrcdoc();
		
		if (doc != null)
		{
			try
			{
				PoiUtil.streamWorkbook(doc, cycle);
			}
			catch (IOException e)
			{
				// TODO: handle exception
				e.printStackTrace();
			}
		}
	}
}

And if you've read this far, you deserve a break!  Go get an Oreo.

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


Re: Interactive Component Question

Posted by Jonny Wray <jo...@yahoo.com>.
Looks like the direction of the srcdoc parameter should be auto and not
in. Then it is available outside of the rendering phase, eg in a
listener.


--- "Rabenau, David (Non-Associate)" <dr...@Schnucks.com> wrote:
> Hi all!
> 
> I'm a relative newbie to Tapestry and I am having trouble
> understanding how
> to create an interactive component.  The overall gist of what I am
> trying is
> to have an link on a page that when triggered will covert an
> org.w3c.dom.Document to a Excel document (a
> org.apache.poi.hssf.usermodel.HSSFWorkbook).
> 
> I've built a "WorkbookLink" component which includes a Conditional
> component
> which itself includes a DirectLink component.  If the Document is not
> null,
> then the link is supposed to display, which it does.  If the user
> clicks on
> the link, the link is supposed to trigger the downloadAction() method
> in
> WorkbookLink.java, which it does.  However, at that point the same
> Document
> that was not null for Conditional is now null by the time it gets to
> DirectLink.
> 
> I suspect this has something to do with the way I've tried to jimmie
> up the
> listener, but I'm lost as to what to do next.  Any help would be
> greatly
> appreciated.
> 
> David
> 
> 
> Here is the compoonent's template (WorkbookLink.html):
> 
> <span jwcid="Conditional">
> 	<a jwcid="DirectLink">
> 		Get Report As Excel
> 	</a>
> </span>
> 
> 
> Here is it's jwc:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE component-specification
>       PUBLIC "-//Apache Software Foundation//Tapestry Specification
> 3.0//EN"
>       "http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd">
> <component-specification
> class="com.smi.tapestry.components.WorkbookLink" 
>     allow-body="no" 
>     allow-informal-parameters="yes">
>     <parameter name="srcdoc" direction="in" required="yes"
>         type="com.smi.utility.web.xml.SqlResultDocument" />
>     <parameter name="condition" direction="in" required="yes"
>         type="java.lang.Object" />
>     <component id="Conditional" type="Conditional">
>         <binding name="condition" expression="condition" />
>     </component>
>     <component id="DirectLink" type="DirectLink">
>         <binding name="listener"
> expression="listeners.downloadAction" />
>         <binding name="srcdoc" expression="srcdoc" />
>     </component>    
> </component-specification>
> 
> Here is the html tag for it:
> 
> <span jwcid="@WorkbookLink" srcdoc="ognl:visit.report"
> condition="ognl:visit.report" />
> 
> Finally, here is the WorkbookLink.java:
> 
> public abstract class WorkbookLink extends BaseComponent //implements
> IActionListener//implements IDirect
> {
> 	//public SqlResultDocument report;
> 	public abstract SqlResultDocument getSrcdoc();
> 
> 	public void downloadAction(IRequestCycle cycle)
> 	{
> 		SqlResultDocument doc = getSrcdoc();
> 		
> 		if (doc != null)
> 		{
> 			try
> 			{
> 				PoiUtil.streamWorkbook(doc, cycle);
> 			}
> 			catch (IOException e)
> 			{
> 				// TODO: handle exception
> 				e.printStackTrace();
> 			}
> 		}
> 	}
> }
> 
> And if you've read this far, you deserve a break!  Go get an Oreo.
> 
> ---------------------------------------------------------------------
> 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