You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-user@portals.apache.org by Marek Nowak <ma...@o2.pl> on 2005/01/19 12:40:48 UTC

portlet property

Hello

I want to write a portlet for Jetspeed2. This portlet should display a given html page. Let's call this portlet HtmlPortlet. I want to put 4 portlets on my page, each of them should display a given page.



++++++++++++++++++++++++++++++++++++++++++++++
|                      |                     |
|                      |                     |
|      HtmlPortlet     |     HtmlPortlet     |
|                      |                     |
|    displays a.html   |   displays b.html   |
|                      |                     |
|                      |                     |
++++++++++++++++++++++++++++++++++++++++++++++
|                      |                     |
|                      |                     |
|      HtmlPortlet     |     HtmlPortlet     |
|                      |                     |
|    displays c.html   |   displays d.html   |
|                      |                     |
|                      |                     |
++++++++++++++++++++++++++++++++++++++++++++++



Does anybody know how to set an "myUrl" property of these portlets? Is it possible? I know that properties of portlets are stored in database, but I would like to set the property "myUrl" in a file. If it is impossible, maybe you know how to make my application to set this property in database for each portlet.

Regards
Marek

Re: portlet property

Posted by Jeff Sheets <je...@gmail.com>.
All,
I am having an issue where the preferences are reset when I redeploy
my portlet application.  This seems like it should be a bug, would
others agree?


On Thu, 20 Jan 2005 11:02:07 +0100, Marek Nowak <ma...@op.pl> wrote:
> Thanks David, you helped me a lot. So I understand that for each instance of
> my HtmlPortlet I can have a set of preferences. So HtmlPortlet that is
> displayed as the first one at the page can have preference "file" set to
> "a.html", the same portlet that is displayed as the second one at the page
> can have preference "file" set to "b.html". Am I right?
> 
> I want to do something like this:
> 
> MyApplication :
> - creates psml file (which contains 4 instances of HtmlPortlet)
> - for each instance of portlet sets "file" preference to a proper value
> <-------- How can I do this?
> 
> Regards
> Marek
> 
> 
> ----- Original Message -----
> From: "David Sean Taylor" <da...@bluesunrise.com>
> To: "Jetspeed Users List" <je...@jakarta.apache.org>
> Sent: Wednesday, January 19, 2005 7:21 PM
> Subject: Re: portlet property
> 
> > Marek Nowak wrote:
> >> Hello
> >>
> >> I want to write a portlet for Jetspeed2. This portlet should display a
> >> given html page. Let's call this portlet HtmlPortlet. I want to put 4
> >> portlets on my page, each of them should display a given page.
> >>
> >>
> >>
> >> ++++++++++++++++++++++++++++++++++++++++++++++
> >> |                      |                     |
> >> |                      |                     |
> >> |      HtmlPortlet     |     HtmlPortlet     |
> >> |                      |                     |
> >> |    displays a.html   |   displays b.html   |
> >> |                      |                     |
> >> |                      |                     |
> >> ++++++++++++++++++++++++++++++++++++++++++++++
> >> |                      |                     |
> >> |                      |                     |
> >> |      HtmlPortlet     |     HtmlPortlet     |
> >> |                      |                     |
> >> |    displays c.html   |   displays d.html   |
> >> |                      |                     |
> >> |                      |                     |
> >> ++++++++++++++++++++++++++++++++++++++++++++++
> >>
> >>
> >>
> >> Does anybody know how to set an "myUrl" property of these portlets? Is it
> >> possible? I know that properties of portlets are stored in database, but
> >> I would like to set the property "myUrl" in a file. If it is impossible,
> >> maybe you know how to make my application to set this property in
> >> database for each portlet.
> >>
> >> Regards
> >> Marek
> >>
> > Think you mean preferences.
> >
> > The storage method of preferences is up to the portal impl.
> > You shouldn't really be concerned with the details of how the portal
> > stores preferences...
> >
> > Are you looking for an external link or a local file? We already have a
> > web content portlet for external links in Jetspeed-2.
> >
> > For a local html file, I just took 5 minutes and wrote this portlet for
> > you.
> > I guess I should commit it to Gems if Ken doesnt already have something
> > like this.
> > -------------------------------------------------------------------
> >
> > package com.which.idtb.portlets;
> >
> > import java.io.IOException;
> > import java.io.InputStream;
> > import java.io.OutputStream;
> >
> > import javax.portlet.PortletConfig;
> > import javax.portlet.PortletException;
> > import javax.portlet.RenderRequest;
> > import javax.portlet.RenderResponse;
> > import javax.portlet.PortletPreferences;
> >
> > import org.apache.portals.bridges.common.GenericServletPortlet;
> >
> > /*
> >  * Copyright 2000-2004 The Apache Software Foundation.
> >  *
> >  * Licensed under the Apache License, Version 2.0 (the "License");
> >  * you may not use this file except in compliance with the License.
> >  * You may obtain a copy of the License at
> >  *
> >  *      http://www.apache.org/licenses/LICENSE-2.0
> >  *
> >  * Unless required by applicable law or agreed to in writing, software
> >  * distributed under the License is distributed on an "AS IS" BASIS,
> >  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
> > implied.
> >  * See the License for the specific language governing permissions and
> >  * limitations under the License.
> >  */
> >
> > /**
> >  * FilePortlet
> >  *
> >  * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
> >  * @version $Id: $
> >  */
> > public class FilePortlet extends GenericServletPortlet
> > {
> >
> >     public void doView(RenderRequest request, RenderResponse response)
> > throws PortletException, IOException
> >     {
> >         response.setContentType("text/html");
> >         PortletPreferences prefs = request.getPreferences();
> >         String fileName = prefs.getValue("file", null);
> >         if (fileName != null)
> >         {
> >             InputStream is =
> > this.getPortletContext().getResourceAsStream(fileName);
> >             drain(is, response.getPortletOutputStream());
> >             is.close();
> >         }
> >         else
> >         {
> >             response.getWriter().println("Could not find file preference
> > ");
> >         }
> >     }
> >
> >     static final int BLOCK_SIZE=4096;
> >
> >     public static void drain(InputStream r,OutputStream w) throws
> > IOException
> >     {
> >         byte[] bytes=new byte[BLOCK_SIZE];
> >         try
> >         {
> >           int length=r.read(bytes);
> >           while(length!=-1)
> >           {
> >               if(length!=0)
> >                   {
> >                       w.write(bytes,0,length);
> >                   }
> >               length=r.read(bytes);
> >           }
> >       }
> >       finally
> >       {
> >         bytes=null;
> >       }
> >
> >     }
> >
> >
> > }
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jetspeed-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jetspeed-user-help@jakarta.apache.org
> 
>

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


Re: portlet property

Posted by Marek Nowak <ma...@op.pl>.
Thanks David, you helped me a lot. So I understand that for each instance of 
my HtmlPortlet I can have a set of preferences. So HtmlPortlet that is 
displayed as the first one at the page can have preference "file" set to 
"a.html", the same portlet that is displayed as the second one at the page 
can have preference "file" set to "b.html". Am I right?

I want to do something like this:

MyApplication :
- creates psml file (which contains 4 instances of HtmlPortlet)
- for each instance of portlet sets "file" preference to a proper value 
<-------- How can I do this?


Regards
Marek



----- Original Message ----- 
From: "David Sean Taylor" <da...@bluesunrise.com>
To: "Jetspeed Users List" <je...@jakarta.apache.org>
Sent: Wednesday, January 19, 2005 7:21 PM
Subject: Re: portlet property


> Marek Nowak wrote:
>> Hello
>>
>> I want to write a portlet for Jetspeed2. This portlet should display a 
>> given html page. Let's call this portlet HtmlPortlet. I want to put 4 
>> portlets on my page, each of them should display a given page.
>>
>>
>>
>> ++++++++++++++++++++++++++++++++++++++++++++++
>> |                      |                     |
>> |                      |                     |
>> |      HtmlPortlet     |     HtmlPortlet     |
>> |                      |                     |
>> |    displays a.html   |   displays b.html   |
>> |                      |                     |
>> |                      |                     |
>> ++++++++++++++++++++++++++++++++++++++++++++++
>> |                      |                     |
>> |                      |                     |
>> |      HtmlPortlet     |     HtmlPortlet     |
>> |                      |                     |
>> |    displays c.html   |   displays d.html   |
>> |                      |                     |
>> |                      |                     |
>> ++++++++++++++++++++++++++++++++++++++++++++++
>>
>>
>>
>> Does anybody know how to set an "myUrl" property of these portlets? Is it 
>> possible? I know that properties of portlets are stored in database, but 
>> I would like to set the property "myUrl" in a file. If it is impossible, 
>> maybe you know how to make my application to set this property in 
>> database for each portlet.
>>
>> Regards
>> Marek
>>
> Think you mean preferences.
>
> The storage method of preferences is up to the portal impl.
> You shouldn't really be concerned with the details of how the portal 
> stores preferences...
>
> Are you looking for an external link or a local file? We already have a 
> web content portlet for external links in Jetspeed-2.
>
> For a local html file, I just took 5 minutes and wrote this portlet for 
> you.
> I guess I should commit it to Gems if Ken doesnt already have something 
> like this.
> -------------------------------------------------------------------
>
> package com.which.idtb.portlets;
>
> import java.io.IOException;
> import java.io.InputStream;
> import java.io.OutputStream;
>
> import javax.portlet.PortletConfig;
> import javax.portlet.PortletException;
> import javax.portlet.RenderRequest;
> import javax.portlet.RenderResponse;
> import javax.portlet.PortletPreferences;
>
> import org.apache.portals.bridges.common.GenericServletPortlet;
>
> /*
>  * Copyright 2000-2004 The Apache Software Foundation.
>  *
>  * Licensed under the Apache License, Version 2.0 (the "License");
>  * you may not use this file except in compliance with the License.
>  * You may obtain a copy of the License at
>  *
>  *      http://www.apache.org/licenses/LICENSE-2.0
>  *
>  * Unless required by applicable law or agreed to in writing, software
>  * distributed under the License is distributed on an "AS IS" BASIS,
>  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 
> implied.
>  * See the License for the specific language governing permissions and
>  * limitations under the License.
>  */
>
> /**
>  * FilePortlet
>  *
>  * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
>  * @version $Id: $
>  */
> public class FilePortlet extends GenericServletPortlet
> {
>
>     public void doView(RenderRequest request, RenderResponse response) 
> throws PortletException, IOException
>     {
>         response.setContentType("text/html");
>         PortletPreferences prefs = request.getPreferences();
>         String fileName = prefs.getValue("file", null);
>         if (fileName != null)
>         {
>             InputStream is = 
> this.getPortletContext().getResourceAsStream(fileName);
>             drain(is, response.getPortletOutputStream());
>             is.close();
>         }
>         else
>         {
>             response.getWriter().println("Could not find file preference 
> ");
>         }
>     }
>
>     static final int BLOCK_SIZE=4096;
>
>     public static void drain(InputStream r,OutputStream w) throws 
> IOException
>     {
>         byte[] bytes=new byte[BLOCK_SIZE];
>         try
>         {
>           int length=r.read(bytes);
>           while(length!=-1)
>           {
>               if(length!=0)
>                   {
>                       w.write(bytes,0,length);
>                   }
>               length=r.read(bytes);
>           }
>       }
>       finally
>       {
>         bytes=null;
>       }
>
>     }
>
>
> }
> 


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


Re: portlet property

Posted by David Sean Taylor <da...@bluesunrise.com>.
Ken Ramirez wrote:
> I don't have one like that yet, and I was planning on writing one. This 
> is perfect. I'll put it into Gems.
> 
> 
Great!

> In my opinion, what makes this portlet cooler than using an init-param 
> is that the name of the file can be changed after the portlet is 
> deployed without having to redeploy any part of the portlet. Would you 
> agree with this?
>
Yes.
Init Params are across all users.
Using a pref is better here so that we can use the same portlet for 
different users.

-- 
David Sean Taylor
Bluesunrise Software
david@bluesunrise.com
[office] +01 707 773-4646
[mobile] +01 707 529 9194

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


Re: portlet property

Posted by Ken Ramirez <kr...@TheJavaThinkTank.org>.
I don't have one like that yet, and I was planning on writing one. This 
is perfect. I'll put it into Gems.


In my opinion, what makes this portlet cooler than using an init-param 
is that the name of the file can be changed after the portlet is 
deployed without having to redeploy any part of the portlet. Would you 
agree with this?

Ken


David Sean Taylor wrote:

> Marek Nowak wrote:
>
>> Hello
>>
>> I want to write a portlet for Jetspeed2. This portlet should display 
>> a given html page. Let's call this portlet HtmlPortlet. I want to put 
>> 4 portlets on my page, each of them should display a given page.
>>
>>
>>
>> ++++++++++++++++++++++++++++++++++++++++++++++
>> |                      |                     |
>> |                      |                     |
>> |      HtmlPortlet     |     HtmlPortlet     |
>> |                      |                     |
>> |    displays a.html   |   displays b.html   |
>> |                      |                     |
>> |                      |                     |
>> ++++++++++++++++++++++++++++++++++++++++++++++
>> |                      |                     |
>> |                      |                     |
>> |      HtmlPortlet     |     HtmlPortlet     |
>> |                      |                     |
>> |    displays c.html   |   displays d.html   |
>> |                      |                     |
>> |                      |                     |
>> ++++++++++++++++++++++++++++++++++++++++++++++
>>
>>
>>
>> Does anybody know how to set an "myUrl" property of these portlets? 
>> Is it possible? I know that properties of portlets are stored in 
>> database, but I would like to set the property "myUrl" in a file. If 
>> it is impossible, maybe you know how to make my application to set 
>> this property in database for each portlet.
>>
>> Regards
>> Marek
>>
> Think you mean preferences.
>
> The storage method of preferences is up to the portal impl.
> You shouldn't really be concerned with the details of how the portal 
> stores preferences...
>
> Are you looking for an external link or a local file? We already have 
> a web content portlet for external links in Jetspeed-2.
>
> For a local html file, I just took 5 minutes and wrote this portlet 
> for you.
> I guess I should commit it to Gems if Ken doesnt already have 
> something like this.
> -------------------------------------------------------------------
>
> package com.which.idtb.portlets;
>
> import java.io.IOException;
> import java.io.InputStream;
> import java.io.OutputStream;
>
> import javax.portlet.PortletConfig;
> import javax.portlet.PortletException;
> import javax.portlet.RenderRequest;
> import javax.portlet.RenderResponse;
> import javax.portlet.PortletPreferences;
>
> import org.apache.portals.bridges.common.GenericServletPortlet;
>
> /*
>  * Copyright 2000-2004 The Apache Software Foundation.
>  *
>  * Licensed under the Apache License, Version 2.0 (the "License");
>  * you may not use this file except in compliance with the License.
>  * You may obtain a copy of the License at
>  *
>  *      http://www.apache.org/licenses/LICENSE-2.0
>  *
>  * Unless required by applicable law or agreed to in writing, software
>  * distributed under the License is distributed on an "AS IS" BASIS,
>  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 
> implied.
>  * See the License for the specific language governing permissions and
>  * limitations under the License.
>  */
>
> /**
>  * FilePortlet
>  *
>  * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
>  * @version $Id: $
>  */
> public class FilePortlet extends GenericServletPortlet
> {
>
>     public void doView(RenderRequest request, RenderResponse response) 
> throws PortletException, IOException
>     {
>         response.setContentType("text/html");
>         PortletPreferences prefs = request.getPreferences();
>         String fileName = prefs.getValue("file", null);
>         if (fileName != null)
>         {
>             InputStream is = 
> this.getPortletContext().getResourceAsStream(fileName);
>             drain(is, response.getPortletOutputStream());
>             is.close();
>         }
>         else
>         {
>             response.getWriter().println("Could not find file 
> preference ");
>         }
>     }
>
>     static final int BLOCK_SIZE=4096;
>
>     public static void drain(InputStream r,OutputStream w) throws 
> IOException
>     {
>         byte[] bytes=new byte[BLOCK_SIZE];
>         try
>         {
>           int length=r.read(bytes);
>           while(length!=-1)
>           {
>               if(length!=0)
>                   {
>                       w.write(bytes,0,length);
>                   }
>               length=r.read(bytes);
>           }
>       }
>       finally
>       {
>         bytes=null;
>       }
>
>     }
>
>
> }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jetspeed-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jetspeed-user-help@jakarta.apache.org
>

-- 
*----*----*----*----*----*----*----*----*----*----*----*----
Stay on top of all things to do with JSR-168 Portlet and
Portal development by bookmarking the authority on the
subject: http://community.java.net/portlet
*
* News
* Weblogs
* Community Tips
* Portlet and Portal Projects
* Featured Articles
* And much more
*
*----*----*----*----*----*----*----*----*----*----*----*----
Ken Ramirez
Send mail to: mailto://kramirez@TheJavaThinkTank.org
Check out the website: http://www.TheJavaThinkTank.org
Check out my Blog at: http://weblogs.java.net/blog/ken_ramirez
*----*----*----*----*----*----*----*----*----*----*----*----


Re: portlet property

Posted by David Sean Taylor <da...@bluesunrise.com>.
Marek Nowak wrote:
> Hello
> 
> I want to write a portlet for Jetspeed2. This portlet should display a given html page. Let's call this portlet HtmlPortlet. I want to put 4 portlets on my page, each of them should display a given page.
> 
> 
> 
> ++++++++++++++++++++++++++++++++++++++++++++++
> |                      |                     |
> |                      |                     |
> |      HtmlPortlet     |     HtmlPortlet     |
> |                      |                     |
> |    displays a.html   |   displays b.html   |
> |                      |                     |
> |                      |                     |
> ++++++++++++++++++++++++++++++++++++++++++++++
> |                      |                     |
> |                      |                     |
> |      HtmlPortlet     |     HtmlPortlet     |
> |                      |                     |
> |    displays c.html   |   displays d.html   |
> |                      |                     |
> |                      |                     |
> ++++++++++++++++++++++++++++++++++++++++++++++
> 
> 
> 
> Does anybody know how to set an "myUrl" property of these portlets? Is it possible? I know that properties of portlets are stored in database, but I would like to set the property "myUrl" in a file. If it is impossible, maybe you know how to make my application to set this property in database for each portlet.
> 
> Regards
> Marek
> 
Think you mean preferences.

The storage method of preferences is up to the portal impl.
You shouldn't really be concerned with the details of how the portal 
stores preferences...

Are you looking for an external link or a local file? We already have a 
web content portlet for external links in Jetspeed-2.

For a local html file, I just took 5 minutes and wrote this portlet for you.
I guess I should commit it to Gems if Ken doesnt already have something 
like this.
-------------------------------------------------------------------

package com.which.idtb.portlets;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.portlet.PortletConfig;
import javax.portlet.PortletException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.PortletPreferences;

import org.apache.portals.bridges.common.GenericServletPortlet;

/*
  * Copyright 2000-2004 The Apache Software Foundation.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *      http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */

/**
  * FilePortlet
  *
  * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
  * @version $Id: $
  */
public class FilePortlet extends GenericServletPortlet
{

     public void doView(RenderRequest request, RenderResponse response) 
throws PortletException, IOException
     {
         response.setContentType("text/html");
         PortletPreferences prefs = request.getPreferences();
         String fileName = prefs.getValue("file", null);
         if (fileName != null)
         {
             InputStream is = 
this.getPortletContext().getResourceAsStream(fileName);
             drain(is, response.getPortletOutputStream());
             is.close();
         }
         else
         {
             response.getWriter().println("Could not find file 
preference ");
         }
     }

     static final int BLOCK_SIZE=4096;

     public static void drain(InputStream r,OutputStream w) throws 
IOException
     {
         byte[] bytes=new byte[BLOCK_SIZE];
         try
         {
           int length=r.read(bytes);
           while(length!=-1)
           {
               if(length!=0)
                   {
                       w.write(bytes,0,length);
                   }
               length=r.read(bytes);
           }
       }
       finally
       {
         bytes=null;
       }

     }


}

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