You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-user@portals.apache.org by Geoffrey <jc...@hotmail.com> on 2004/03/03 14:38:28 UTC

Can a Portlet generate an image?

Can a Portlet generate a dynamic image?

I've seen Pluto's test portlet use a static image, located as a file in the
archive and references by from jsp pages.
However, I would like to generate an image on the fly, something which is
possible with a Servlet, as it can set the mime time, generate the image
(for example take a pattern image and cut a users name out of it) and write
it to the Servlet outputstream.

-- 
Thank you for any and all help,
Geoffrey




Re: Can a Portlet generate an image?

Posted by Dettborn <de...@minet.uni-jena.de>.
Hello Joerg,
I not sure, you can read the chapter over Resource Serving. There you 
can create a link which points back to itself. You can find the 
Specification under the folliwing link:
http://ipc658.inf-swt.uni-jena.de/spec/
Best regards
Torsten

Joerg Heinicke schrieb:

>Glenn R. Golden <ggolden <at> umich.edu> writes:
>
>  
>
>>A portlet can only generate "markup fragment".  The output from a 
>>portlet is aggregated by the portal engine into a complete "markup" 
>>document.  Markup is usually (but not limited to) HTML.
>>
>>Portlets can not generate images or other binary content, as that does 
>>not fit in the model of fragments and markups and aggregated documents.
>>    
>>
>
>Sorry for resurrecting such an old thread [1], but it's the best one I found on
>this topic.
>
>Is everything of the above still true? Probably yes for JSR 168, but what about
>the JSR 286?
>
>Stefan Hepper mentioned later in the thread:
>
>  
>
>>However, for the problem you mentioned there is currently no solution
>>besides the servlet one that Glenn mentioned, as there is no ability for
>>the portlet to create a link pointing back to it that does not trigger
>>the rendering of all portlets on the page.
>>    
>>
>
>Shouldn't it be easy to let a request that returns non-markup "pass
>through" the portal and prevent it to "trigger the rendering of all portlets on
>the page"? The detection of returning markup or non-markup can be either
>auto-magically or by configuration.
>
>  
>
>>You can continue to use a servlet to generate your image.  You would 
>>use a portlet to generate the html markup fragment that places the 
>>image into the document at a particular point.
>>    
>>
>
>This is quite sub-optimal. A portlet should encapsulate some functionality. I
>have the need to provide data as table and as chart. By enforcing the chart
>generation to a servlet I first have to spread the functionality into 2
>components and second copy & paste at least the code to implement the same
>controller logic while it would theoretically only be necessary to implement
>different views.
>
>Is using a servlet still the recommended and necessary way?
>
>Regards
>Jörg
>
>[1] http://thread.gmane.org/gmane.comp.jakarta.pluto.user/467
>
>  
>


Re: Can a Portlet generate an image?

Posted by Joerg Heinicke <jo...@gmx.de>.
Glenn R. Golden <ggolden <at> umich.edu> writes:

> A portlet can only generate "markup fragment".  The output from a 
> portlet is aggregated by the portal engine into a complete "markup" 
> document.  Markup is usually (but not limited to) HTML.
> 
> Portlets can not generate images or other binary content, as that does 
> not fit in the model of fragments and markups and aggregated documents.

Sorry for resurrecting such an old thread [1], but it's the best one I found on
this topic.

Is everything of the above still true? Probably yes for JSR 168, but what about
the JSR 286?

Stefan Hepper mentioned later in the thread:

> However, for the problem you mentioned there is currently no solution
> besides the servlet one that Glenn mentioned, as there is no ability for
> the portlet to create a link pointing back to it that does not trigger
> the rendering of all portlets on the page.

Shouldn't it be easy to let a request that returns non-markup "pass
through" the portal and prevent it to "trigger the rendering of all portlets on
the page"? The detection of returning markup or non-markup can be either
auto-magically or by configuration.

> You can continue to use a servlet to generate your image.  You would 
> use a portlet to generate the html markup fragment that places the 
> image into the document at a particular point.

This is quite sub-optimal. A portlet should encapsulate some functionality. I
have the need to provide data as table and as chart. By enforcing the chart
generation to a servlet I first have to spread the functionality into 2
components and second copy & paste at least the code to implement the same
controller logic while it would theoretically only be necessary to implement
different views.

Is using a servlet still the recommended and necessary way?

Regards
Jörg

[1] http://thread.gmane.org/gmane.comp.jakarta.pluto.user/467


Re: Can a Portlet generate an image?

Posted by Stefan Hepper <st...@hursley.ibm.com>.
Hi Glenn,
actually that is not quite true, a portlet can still generate binary 
content that may be aggregated into a page. One example of this would be 
an iFrame based portal where the browser would do the aggregation.

However, for the problem you mentioned there is currently no solution 
besides the servlet one that Glenn mentioned, as there is no ability for 
the portlet to create a link pointing back to it that does not trigger 
the rendering of all portlets on the page. Maybe something we should 
consider for V1.1.

Stefan


Glenn R. Golden wrote:

> A portlet can only generate "markup fragment".  The output from a 
> portlet is aggregated by the portal engine into a complete "markup" 
> document.  Markup is usually (but not limited to) HTML.
> 
> Portlets can not generate images or other binary content, as that does 
> not fit in the model of fragments and markups and aggregated documents.
> 
> Portlets are just one component of the java web application family, 
> along with servlet, jsp (and soon JavaServer Faces).  This means that 
> your web application can contain servlets, jsp pages, as well as portlets.
> 
> You can continue to use a servlet to generate your image.  You would use 
> a portlet to generate the html markup fragment that places the image 
> into the document at a particular point.
> 
> - Glenn
> 
> Glenn R. Golden
> CHEF Architect  - Sr. Systems Research Programmer
> School of Information, Media Union - University of Michigan
> ggolden@umich.edu
> 
> On Mar 3, 2004, at 8:38 AM, Geoffrey wrote:
> 
>> Can a Portlet generate a dynamic image?
>>
>> I've seen Pluto's test portlet use a static image, located as a file 
>> in the
>> archive and references by from jsp pages.
>> However, I would like to generate an image on the fly, something which is
>> possible with a Servlet, as it can set the mime time, generate the image
>> (for example take a pattern image and cut a users name out of it) and 
>> write
>> it to the Servlet outputstream.
>>
>> -- 
>> Thank you for any and all help,
>> Geoffrey
>>
>>
>>
> 
> 


Re: Can a Portlet generate an image?

Posted by Brian Lalor <bl...@bravo5.org>.
On Mar 4, 2004, at 12:59 PM, Stefan Hepper wrote:

>> 2) What about Portlet properties?
>> Can I access them in my image generating Servlet?
>
> No, no portlet objs are available. the only chance for data sharing is 
> to use the HttpSession

Its pretty hairy, but it works.  The session keys generated in the 
portlet have some garbage prepended to them (in WPS, anyway) to make 
them unique across the entire session.  I was able to pull a value out 
of the session in my servlet by looking for a value of a particular 
class type.

-- 
    __   ____
   / /  / __/ Brian Lalor
  / _ \/__ \  blalor@bravo5.org
/_.__/____/  http://bravo5.org/

Re: Can a Portlet generate an image?

Posted by Stefan Hepper <st...@hursley.ibm.com>.
Geoffrey wrote:

>>the servlet will be accessed via the context root under which the
>>portlet app is deployed, the portlet will be accessed through the portal
>>(via the context root of the portal web app)
>>
> 
> 
> So in this case:
> Portlet p's class location:
> <portlet-root>/WEB-INF/classes/org/sf/MyPortlet.class
> JSP page
> Static image location: <portlet-root>/images/staticimage.jpg
> Servlet location:
> <portlet-root>/WEB-INF/classes/org/sf/MyGeneratingServlet.class
> 
> Are these the recommended properties?
> Portlet p context path uri: mydir/portlets/myportlet
> Servlet context path uri: mydir/portlets/myportlet/myservlet
> 
> And do I call them like this?
> response.encodeURL("images/staticimage.jpg");
> response.encodeURL("myserlvet");
> 

No, for the encodeURL method you need to specify the full path, like
response.encodeURL(request.getContextPath()+"images/staticimage.jpg");

Stefan

Re: Can a Portlet generate an image?

Posted by Geoffrey <jc...@hotmail.com>.
> the servlet will be accessed via the context root under which the
> portlet app is deployed, the portlet will be accessed through the portal
> (via the context root of the portal web app)
>

So in this case:
Portlet p's class location:
<portlet-root>/WEB-INF/classes/org/sf/MyPortlet.class
JSP page
Static image location: <portlet-root>/images/staticimage.jpg
Servlet location:
<portlet-root>/WEB-INF/classes/org/sf/MyGeneratingServlet.class

Are these the recommended properties?
Portlet p context path uri: mydir/portlets/myportlet
Servlet context path uri: mydir/portlets/myportlet/myservlet

And do I call them like this?
response.encodeURL("images/staticimage.jpg");
response.encodeURL("myserlvet");

-- 
Thank you for any and all help,
Geoffrey
"Stefan Hepper" <st...@hursley.ibm.com> schreef in bericht
news:40476E6F.8090105@hursley.ibm.com...
> Geoffrey wrote:
>
> > Thank you for the clarification.
> >
> > So can I include a Servlet next to my Portlet in the archive which will
be
> > deployed to the Portlet Container?
>
> Yes, you can package servlets in a portlet application like normal web
apps.
>
> > (Didn't seem logical to deploy a servlet to a portlet container which
> > resides in a servlet container.)
> >
>
> why that? as portlet apps are web apps, why would you preclude servlets
> being packaged with portlets?
>
> > 1) What about the URL rewriting?
> > If I give my servlet the uri
> > mydir/MyServlet
> > and the Portlet calling it has uri
> > mydir/MyPortlet
> > Will they both be deployed under a namespace on the level of a portlet
> > (for example domain.com/servletspace/porletspace),
> > or will the MyServlet be deployed under the namespace on the level of a
> > servlet
> > (for example domain.com/servletspace/)?
> >
>
> the servlet will be accessed via the context root under which the
> portlet app is deployed, the portlet will be accessed through the portal
> (via the context root of the portal web app)
>
> > 2) What about Portlet properties?
> > Can I access them in my image generating Servlet?
> >
>
> No, no portlet objs are available. the only chance for data sharing is
> to use the HttpSession
>
> > As the action and view method are seperated, is there a specific reason
why
> > the action method can't deside to:
> > set the mime type,
> > generate the content
> > and make the portlet container not do the assembly of the different
markup
> > fragments?
> >
> yes, this is done to enforce the model-view-controller pattern, where
> rendering does not change the state. As action is the method where you
> should do all the state changes, action cannot access the output stream.
>
> Stefan
>
>




Re: Can a Portlet generate an image?

Posted by Stefan Hepper <st...@hursley.ibm.com>.
Geoffrey wrote:

> Thank you for the clarification.
> 
> So can I include a Servlet next to my Portlet in the archive which will be
> deployed to the Portlet Container?

Yes, you can package servlets in a portlet application like normal web apps.

> (Didn't seem logical to deploy a servlet to a portlet container which
> resides in a servlet container.)
> 

why that? as portlet apps are web apps, why would you preclude servlets 
being packaged with portlets?

> 1) What about the URL rewriting?
> If I give my servlet the uri
> mydir/MyServlet
> and the Portlet calling it has uri
> mydir/MyPortlet
> Will they both be deployed under a namespace on the level of a portlet
> (for example domain.com/servletspace/porletspace),
> or will the MyServlet be deployed under the namespace on the level of a
> servlet
> (for example domain.com/servletspace/)?
> 

the servlet will be accessed via the context root under which the 
portlet app is deployed, the portlet will be accessed through the portal 
(via the context root of the portal web app)

> 2) What about Portlet properties?
> Can I access them in my image generating Servlet?
> 

No, no portlet objs are available. the only chance for data sharing is 
to use the HttpSession

> As the action and view method are seperated, is there a specific reason why
> the action method can't deside to:
> set the mime type,
> generate the content
> and make the portlet container not do the assembly of the different markup
> fragments?
> 
yes, this is done to enforce the model-view-controller pattern, where 
rendering does not change the state. As action is the method where you 
should do all the state changes, action cannot access the output stream.

Stefan


Re: Can a Portlet generate an image?

Posted by Geoffrey <jc...@hotmail.com>.
Thank you for the clarification.

So can I include a Servlet next to my Portlet in the archive which will be
deployed to the Portlet Container?
(Didn't seem logical to deploy a servlet to a portlet container which
resides in a servlet container.)

1) What about the URL rewriting?
If I give my servlet the uri
mydir/MyServlet
and the Portlet calling it has uri
mydir/MyPortlet
Will they both be deployed under a namespace on the level of a portlet
(for example domain.com/servletspace/porletspace),
or will the MyServlet be deployed under the namespace on the level of a
servlet
(for example domain.com/servletspace/)?

2) What about Portlet properties?
Can I access them in my image generating Servlet?

As the action and view method are seperated, is there a specific reason why
the action method can't deside to:
set the mime type,
generate the content
and make the portlet container not do the assembly of the different markup
fragments?

-- 
Thank you for any and all help,
Geoffrey
"Glenn R. Golden" <gg...@umich.edu> schreef in bericht
news:C38FB934-6D18-11D8-A131-000A95A93076@umich.edu...
> A portlet can only generate "markup fragment".  The output from a
> portlet is aggregated by the portal engine into a complete "markup"
> document.  Markup is usually (but not limited to) HTML.
>
> Portlets can not generate images or other binary content, as that does
> not fit in the model of fragments and markups and aggregated documents.
>
> Portlets are just one component of the java web application family,
> along with servlet, jsp (and soon JavaServer Faces).  This means that
> your web application can contain servlets, jsp pages, as well as
> portlets.
>
> You can continue to use a servlet to generate your image.  You would
> use a portlet to generate the html markup fragment that places the
> image into the document at a particular point.
>
> - Glenn
>
> Glenn R. Golden
> CHEF Architect  - Sr. Systems Research Programmer
> School of Information, Media Union - University of Michigan
> ggolden@umich.edu
>
> On Mar 3, 2004, at 8:38 AM, Geoffrey wrote:
>
> > Can a Portlet generate a dynamic image?
> >
> > I've seen Pluto's test portlet use a static image, located as a file
> > in the
> > archive and references by from jsp pages.
> > However, I would like to generate an image on the fly, something which
> > is
> > possible with a Servlet, as it can set the mime time, generate the
> > image
> > (for example take a pattern image and cut a users name out of it) and
> > write
> > it to the Servlet outputstream.
> >
> > -- 
> > Thank you for any and all help,
> > Geoffrey
> >
> >
> >
>
>




Re: Can a Portlet generate an image?

Posted by "Glenn R. Golden" <gg...@umich.edu>.
A portlet can only generate "markup fragment".  The output from a 
portlet is aggregated by the portal engine into a complete "markup" 
document.  Markup is usually (but not limited to) HTML.

Portlets can not generate images or other binary content, as that does 
not fit in the model of fragments and markups and aggregated documents.

Portlets are just one component of the java web application family, 
along with servlet, jsp (and soon JavaServer Faces).  This means that 
your web application can contain servlets, jsp pages, as well as 
portlets.

You can continue to use a servlet to generate your image.  You would 
use a portlet to generate the html markup fragment that places the 
image into the document at a particular point.

- Glenn

Glenn R. Golden
CHEF Architect  - Sr. Systems Research Programmer
School of Information, Media Union - University of Michigan
ggolden@umich.edu

On Mar 3, 2004, at 8:38 AM, Geoffrey wrote:

> Can a Portlet generate a dynamic image?
>
> I've seen Pluto's test portlet use a static image, located as a file 
> in the
> archive and references by from jsp pages.
> However, I would like to generate an image on the fly, something which 
> is
> possible with a Servlet, as it can set the mime time, generate the 
> image
> (for example take a pattern image and cut a users name out of it) and 
> write
> it to the Servlet outputstream.
>
> -- 
> Thank you for any and all help,
> Geoffrey
>
>
>