You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Niraj Shah <ni...@metadot.com> on 2004/07/13 17:46:06 UTC
Help with component rendering
Hello,
I want to render a template/page retrieved from database or other external
resource. There is no template or page specification for this component in
the webcontext at the application startup.
I specified a template-source-delegate extension element and appropriate
class name in my application specification file.
<extension name="org.apache.tapestry.template-source-delegate"
class="com.metadot.portal.utility.TemplateFinder"
immediate="no" />
The specified class TemplateFinder implements the "findTemplate" method of
the ITemplateSourceDelegate interface.
public ComponentTemplate findTemplate(IRequestCycle cycle, IComponent
component, Locale locale) {
//get template from database...for testing just create one here
char[] templateData = "Hello World".toCharArray();
ComponentTemplate template = new ComponentTemplate(templateData, null);
return templateData;
}
I try to invoke the above method from one of my listener methods as follows,
Public void formSubmit(IRequestCycle cycle) {
IEngine engine = getEngine();
//get the application specification
IApplicationSpecification specification = engine.getSpecification();
//look up the template-source-delegate from the namespace
TemplateFinder templateFinder = (TemplateFinder)
specification.getExtension("org.apache.tapestry.template-source-
delegate");
//get the template
ComponentTemplate template = templateFinder.findTemplate(cycle,
cycle.getPage(), getLocale());
//Renderthe found template..");
StringBuffer sbf = new StringBuffer();
sbf.append(template.getTemplateData());
cycle.activate(sbf.toString());
}
However I get an error "Page 'Hello World' not found in application
namespace".
Can someone give some pointers on how to render such a page and what I am
doing wrong?
Thanks,
Niraj
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Help with component rendering
Posted by Erik Hatcher <er...@ehatchersolutions.com>.
If you use the formal jwcid format and put the component specifications
in your .page file, it should work. Works for me at least.
Erik
On Jul 13, 2004, at 5:13 PM, Niraj Shah wrote:
> Hello,
>
> Rendering a template (static contents) using this approach works fine.
> However, if I want to render a template with some components and ognl
> expressions, it does not render correctly.
>
> This is the template I am outputting in my findTemplate method,
>
> public ComponentTemplate findTemplate(IRequestCycle cycle, IComponent
> component, Locale locale) {
>
> StringBuffer sbuf = new StringBuffer();
> sbuf.append("<html><head></head><body>Hello World");
> sbuf.append("<span jwcid=\"@Form\"
> listener=\"ognl:listeners.formSubmit\">");
>
> sbuf.append("<table>");
> sbuf.append("<tr>");
> sbuf.append("<th>File:</th>");
> sbuf.append("<td><jwcid=\"@Upload\" file=\"ognl:file\"
> size=\"30\"/></td>");
> sbuf.append("</tr>");
> sbuf.append("<tr>");
> sbuf.append("<td></td>");
> sbuf.append("<td><input type=\"submit\"
> value=\"Upload\"/>");
> sbuf.append("</tr>");
> sbuf.append("</table>");
> sbuf.append("</span>");
> sbuf.append("</body></html>");
>
> String htmlString = sbuf.toString();
>
> char[] templateData = htmlString.toCharArray();
>
> TemplateParser parser = new TemplateParser();
> ITemplateParserDelegate delegate = new
> ParserDelegate(component,
> cycle);
>
>
> TemplateToken[] tokens;
>
> try {
> tokens = parser.parse(templateData, delegate, null);
> } catch (TemplateParseException e) {
> throw new ApplicationRuntimeException(e);
> }
>
> ComponentTemplate template = new
> ComponentTemplate(templateData,
> tokens);
>
> } //end of method
>
> When the application runs, it renders only the static HTML part, the
> Tapestry components @Form and @Upload with ognl expressions are not
> rendered. In my ParserDelegate class, I have getAllowBody returning
> "true".
>
> Can someone suggest what I need to do to render the Tapestry
> components with
> ognl bindings? I also wrote a corresponding Page class with listener
> method
> and properties!!
>
> Thanks,
>
> Niraj
>
> -----Original Message-----
> From: Erik Hatcher [mailto:erik@ehatchersolutions.com]
> Sent: Tuesday, July 13, 2004 12:24 PM
> To: Tapestry users
> Subject: Re: Help with component rendering
>
>
> On Jul 13, 2004, at 11:46 AM, Niraj Shah wrote:
>> I want to render a template/page retrieved from database or other
>> external
>> resource. There is no template or page specification for this
>> component in
>> the webcontext at the application startup.
>
> You need a page specification.
>
>> I specified a template-source-delegate extension element and
>> appropriate
>> class name in my application specification file.
>>
>> <extension name="org.apache.tapestry.template-source-delegate"
>> class="com.metadot.portal.utility.TemplateFinder"
>> immediate="no" />
>
> But with at template source delegate, you will have no .html template,
> explicitly at least.
>
>>
>> The specified class TemplateFinder implements the "findTemplate"
>> method of
>> the ITemplateSourceDelegate interface.
>>
>> public ComponentTemplate findTemplate(IRequestCycle cycle, IComponent
>>
>> component, Locale locale) {
>>
>> //get template from database...for testing just create one here
>>
>> char[] templateData = "Hello World".toCharArray();
>> ComponentTemplate template = new ComponentTemplate(templateData,
>> null);
>
> You need to parse the template also - see an e-mail I just sent.
>
>> I try to invoke the above method from one of my listener methods as
>> follows,
>
> No! You do not invoke the findTemplate method yourself. The framework
> does this for you when it cannot find the template through the normal
> mechanism.
>
> Erik
>
>>
>>
>> Public void formSubmit(IRequestCycle cycle) {
>> IEngine engine = getEngine();
>>
>> //get the application specification
>> IApplicationSpecification specification =
>> engine.getSpecification();
>>
>> //look up the template-source-delegate from the namespace
>> TemplateFinder templateFinder = (TemplateFinder)
>> specification.getExtension("org.apache.tapestry.template-source-
>> delegate");
>>
>> //get the template
>> ComponentTemplate template = templateFinder.findTemplate(cycle,
>> cycle.getPage(), getLocale());
>>
>> //Renderthe found template..");
>> StringBuffer sbf = new StringBuffer();
>> sbf.append(template.getTemplateData());
>> cycle.activate(sbf.toString());
>>
>> }
>>
>> However I get an error "Page 'Hello World' not found in application
>> namespace".
>>
>> Can someone give some pointers on how to render such a page and what I
>> am
>> doing wrong?
>>
>> Thanks,
>>
>> Niraj
>>
>>
>>
>> ---------------------------------------------------------------------
>> 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
>
>
> ---------------------------------------------------------------------
> 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: Help with component rendering
Posted by Niraj Shah <ni...@metadot.com>.
Hello,
Rendering a template (static contents) using this approach works fine.
However, if I want to render a template with some components and ognl
expressions, it does not render correctly.
This is the template I am outputting in my findTemplate method,
public ComponentTemplate findTemplate(IRequestCycle cycle, IComponent
component, Locale locale) {
StringBuffer sbuf = new StringBuffer();
sbuf.append("<html><head></head><body>Hello World");
sbuf.append("<span jwcid=\"@Form\"
listener=\"ognl:listeners.formSubmit\">");
sbuf.append("<table>");
sbuf.append("<tr>");
sbuf.append("<th>File:</th>");
sbuf.append("<td><jwcid=\"@Upload\" file=\"ognl:file\"
size=\"30\"/></td>");
sbuf.append("</tr>");
sbuf.append("<tr>");
sbuf.append("<td></td>");
sbuf.append("<td><input type=\"submit\"
value=\"Upload\"/>");
sbuf.append("</tr>");
sbuf.append("</table>");
sbuf.append("</span>");
sbuf.append("</body></html>");
String htmlString = sbuf.toString();
char[] templateData = htmlString.toCharArray();
TemplateParser parser = new TemplateParser();
ITemplateParserDelegate delegate = new
ParserDelegate(component,
cycle);
TemplateToken[] tokens;
try {
tokens = parser.parse(templateData, delegate, null);
} catch (TemplateParseException e) {
throw new ApplicationRuntimeException(e);
}
ComponentTemplate template = new
ComponentTemplate(templateData,
tokens);
} //end of method
When the application runs, it renders only the static HTML part, the
Tapestry components @Form and @Upload with ognl expressions are not
rendered. In my ParserDelegate class, I have getAllowBody returning "true".
Can someone suggest what I need to do to render the Tapestry components with
ognl bindings? I also wrote a corresponding Page class with listener method
and properties!!
Thanks,
Niraj
-----Original Message-----
From: Erik Hatcher [mailto:erik@ehatchersolutions.com]
Sent: Tuesday, July 13, 2004 12:24 PM
To: Tapestry users
Subject: Re: Help with component rendering
On Jul 13, 2004, at 11:46 AM, Niraj Shah wrote:
> I want to render a template/page retrieved from database or other
> external
> resource. There is no template or page specification for this
> component in
> the webcontext at the application startup.
You need a page specification.
> I specified a template-source-delegate extension element and
> appropriate
> class name in my application specification file.
>
> <extension name="org.apache.tapestry.template-source-delegate"
> class="com.metadot.portal.utility.TemplateFinder"
> immediate="no" />
But with at template source delegate, you will have no .html template,
explicitly at least.
>
> The specified class TemplateFinder implements the "findTemplate"
> method of
> the ITemplateSourceDelegate interface.
>
> public ComponentTemplate findTemplate(IRequestCycle cycle, IComponent
>
> component, Locale locale) {
>
> //get template from database...for testing just create one here
>
> char[] templateData = "Hello World".toCharArray();
> ComponentTemplate template = new ComponentTemplate(templateData,
> null);
You need to parse the template also - see an e-mail I just sent.
> I try to invoke the above method from one of my listener methods as
> follows,
No! You do not invoke the findTemplate method yourself. The framework
does this for you when it cannot find the template through the normal
mechanism.
Erik
>
>
> Public void formSubmit(IRequestCycle cycle) {
> IEngine engine = getEngine();
>
> //get the application specification
> IApplicationSpecification specification =
> engine.getSpecification();
>
> //look up the template-source-delegate from the namespace
> TemplateFinder templateFinder = (TemplateFinder)
> specification.getExtension("org.apache.tapestry.template-source-
> delegate");
>
> //get the template
> ComponentTemplate template = templateFinder.findTemplate(cycle,
> cycle.getPage(), getLocale());
>
> //Renderthe found template..");
> StringBuffer sbf = new StringBuffer();
> sbf.append(template.getTemplateData());
> cycle.activate(sbf.toString());
>
> }
>
> However I get an error "Page 'Hello World' not found in application
> namespace".
>
> Can someone give some pointers on how to render such a page and what I
> am
> doing wrong?
>
> Thanks,
>
> Niraj
>
>
>
> ---------------------------------------------------------------------
> 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
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Upload file type specification
Posted by Erik Hatcher <er...@ehatchersolutions.com>.
We wrote our own ValidUpload component that wraps the Upload component
and rejects the upload if it is not in a list of mime types we provide
as a parameter. I don't currently have the time to package it up nice
and neat and contribute it, but it was pretty straightforward to do.
Erik
On Jul 13, 2004, at 2:33 PM, Jeff LaMarche wrote:
> With HTML 4.0, you can use the "accept" parameter to the input tag,
> but it uses mime types with some wildcarding ability, like:
>
> <input type="file" accept="image/gif,image/jpeg"/>
>
> or
>
> <input type="file" accept="image/*"/>
>
> But HTML 3.2 references but does not require browsers to enforce this,
> so no matter what you do, you're going to have to do server-side
> checks.
>
> Hope this helps.
>
> Jeff
>
> References:
> HTML 4.0 spec:
> http://www.w3.org/TR/REC-html40/interact/forms.html#adef-accept
> HTML 3.2 spec: http://www.w3.org/TR/REC-html32#input
>
>
>
> On Jul 13, 2004, at 2:17 PM, Jonny Wray wrote:
>
>> I'm using the upload component succesfully, but I need to limit the
>> file types the user can choose to excel. I included the informal
>> parameter accept="Application/vnd.ms-excel" to the @Upload component,
>> but this does not work.
>>
>> Does anyone know how to do this?
>
>
> ---------------------------------------------------------------------
> 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: Upload file type specification
Posted by Jeff LaMarche <je...@mac.com>.
On Jul 13, 2004, at 3:44 PM, Jonny Wray wrote:
> Am I wrong here? Is there a way to limit the file types exposed by the
> browse button?
Well, if you specify HTML 4.0 in your doc header, technically browsers
that support HTML 4.0 should enforce it, but I don' t have any idea
what the status of HTML 4.0 support on current browsers. If you specify
3.2, the browser is free to ignore the accept parameter, and probably
will.
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Upload file type specification
Posted by Jonny Wray <jo...@yahoo.com>.
Ah, maybe I misunderstood the accept parameter and what it does.
I'm already doing the server-side validation, my code works right now
no matter what the user enters. I just want only excel files to be
exposed by the browse button, and that's what I thought accept
parameter did.
Am I wrong here? Is there a way to limit the file types exposed by the
browse button?
thanks
Jonny
--- Jeff LaMarche <je...@mac.com> wrote:
> With HTML 4.0, you can use the "accept" parameter to the input tag,
> but
> it uses mime types with some wildcarding ability, like:
>
> <input type="file" accept="image/gif,image/jpeg"/>
>
> or
>
> <input type="file" accept="image/*"/>
>
> But HTML 3.2 references but does not require browsers to enforce
> this,
> so no matter what you do, you're going to have to do server-side
> checks.
>
> Hope this helps.
>
> Jeff
>
> References:
> HTML 4.0 spec:
> http://www.w3.org/TR/REC-html40/interact/forms.html#adef-accept
> HTML 3.2 spec: http://www.w3.org/TR/REC-html32#input
>
>
>
> On Jul 13, 2004, at 2:17 PM, Jonny Wray wrote:
>
> > I'm using the upload component succesfully, but I need to limit the
> > file types the user can choose to excel. I included the informal
> > parameter accept="Application/vnd.ms-excel" to the @Upload
> component,
> > but this does not work.
> >
> > Does anyone know how to do this?
>
>
> ---------------------------------------------------------------------
> 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: Upload file type specification
Posted by Jeff LaMarche <je...@mac.com>.
With HTML 4.0, you can use the "accept" parameter to the input tag, but
it uses mime types with some wildcarding ability, like:
<input type="file" accept="image/gif,image/jpeg"/>
or
<input type="file" accept="image/*"/>
But HTML 3.2 references but does not require browsers to enforce this,
so no matter what you do, you're going to have to do server-side
checks.
Hope this helps.
Jeff
References:
HTML 4.0 spec:
http://www.w3.org/TR/REC-html40/interact/forms.html#adef-accept
HTML 3.2 spec: http://www.w3.org/TR/REC-html32#input
On Jul 13, 2004, at 2:17 PM, Jonny Wray wrote:
> I'm using the upload component succesfully, but I need to limit the
> file types the user can choose to excel. I included the informal
> parameter accept="Application/vnd.ms-excel" to the @Upload component,
> but this does not work.
>
> Does anyone know how to do this?
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Upload file type specification
Posted by Jonny Wray <jo...@yahoo.com>.
Hi,
I'm using the upload component succesfully, but I need to limit the
file types the user can choose to excel. I included the informal
parameter accept="Application/vnd.ms-excel" to the @Upload component,
but this does not work.
Does anyone know how to do this?
thanks
Jonny
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Help with component rendering
Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Jul 13, 2004, at 11:46 AM, Niraj Shah wrote:
> I want to render a template/page retrieved from database or other
> external
> resource. There is no template or page specification for this
> component in
> the webcontext at the application startup.
You need a page specification.
> I specified a template-source-delegate extension element and
> appropriate
> class name in my application specification file.
>
> <extension name="org.apache.tapestry.template-source-delegate"
> class="com.metadot.portal.utility.TemplateFinder"
> immediate="no" />
But with at template source delegate, you will have no .html template,
explicitly at least.
>
> The specified class TemplateFinder implements the "findTemplate"
> method of
> the ITemplateSourceDelegate interface.
>
> public ComponentTemplate findTemplate(IRequestCycle cycle, IComponent
>
> component, Locale locale) {
>
> //get template from database...for testing just create one here
>
> char[] templateData = "Hello World".toCharArray();
> ComponentTemplate template = new ComponentTemplate(templateData,
> null);
You need to parse the template also - see an e-mail I just sent.
> I try to invoke the above method from one of my listener methods as
> follows,
No! You do not invoke the findTemplate method yourself. The framework
does this for you when it cannot find the template through the normal
mechanism.
Erik
>
>
> Public void formSubmit(IRequestCycle cycle) {
> IEngine engine = getEngine();
>
> //get the application specification
> IApplicationSpecification specification =
> engine.getSpecification();
>
> //look up the template-source-delegate from the namespace
> TemplateFinder templateFinder = (TemplateFinder)
> specification.getExtension("org.apache.tapestry.template-source-
> delegate");
>
> //get the template
> ComponentTemplate template = templateFinder.findTemplate(cycle,
> cycle.getPage(), getLocale());
>
> //Renderthe found template..");
> StringBuffer sbf = new StringBuffer();
> sbf.append(template.getTemplateData());
> cycle.activate(sbf.toString());
>
> }
>
> However I get an error "Page 'Hello World' not found in application
> namespace".
>
> Can someone give some pointers on how to render such a page and what I
> am
> doing wrong?
>
> Thanks,
>
> Niraj
>
>
>
> ---------------------------------------------------------------------
> 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