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 Akshay Ahooja <ak...@gmail.com> on 2006/06/16 18:45:45 UTC

Adding my own portlet

I am trying to set up a portlet but it is showing errors when I deploy it. I
would just like to review the steps:

Using Jetspeed 2 - using maven jetspeed plugin 2.0

What are the neccesary files needed to create a portlet?

First I create a directory:

c:/myportlet.

Followed by:

c:/myportlet/WEB-INF/classes


The files I think that are needed are:

A .java file inside the classes directory which is compiled using
--> javac -cp
~/.maven/repository/org.apache.portals.jetspeed-2/jars/portlet-api-1.0.jar
Myportlet.java

NOTE: (I had to seperatley download portlet-api-1.0.jar and put it in the
right directory - is there another way to do this?)

Then there is a need for:

portlet.xml and web.xml.


This directory is made into a war :

using: jar cvf ../myportlet.war .


Once this is copied into:

tomcat/myportlet/web-inf/deploy,

A psml file is created named:

 myportlet.psml inside myportal/web-inf/pages/.


Any other files needed?


Now with all these files - this is where I get confused - What file is for
defining what:

   - Where is the main page of the portlet defined? Is it index.jsp by
   default right under myportlet/ ??       (JSP)
      - I assume this is where the entire Portlet Definition is
   - I assume using this main page there will be actions leading to .java
   classes - where are the action and validation classes defined?
      - I cannot seem to find any .java classes in the demo apps -
      anyone know where to locate them? If I can take a look at these it would
      give me some examples to work from.
   - What wraps these things into a portlet - and what files tie in all
   these things together?


If I am not mistaken - to add a portlet there is no need to touch the
original portal until the portlet is deployed - and then only the psml files
need to changed/added. The original portal only needs to be deployed once -
and then only individual portlets are deployed when created/updated/changed.

Thanks,

Akshay

Re: Adding my own portlet

Posted by Aaron Evans <aa...@gmail.com>.
Here is a super simple example of a portlet that simply displays the
contents of an arbitrary JSP:

***************************
package com.mycompany.portlet

import java.io.IOException;

import javax.portlet.GenericPortlet;
import javax.portlet.PortletConfig;
import javax.portlet.PortletContext;
import javax.portlet.PortletException;
import javax.portlet.PortletRequestDispatcher;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

public class SimpleJSPPortlet extends GenericPortlet
{
	protected String viewPage="/WEB-INF/pages/view.jsp";
	
	public void init(PortletConfig config)
    throws PortletException
    {
        if(config.getInitParameter("ViewPage")!=null)
        {
        	this.viewPage = config.getInitParameter("ViewPage");
        }

        super.init(config);
    }
	
	public void doView(RenderRequest request, RenderResponse response)
throws PortletException, IOException
    {
		PortletContext context = getPortletContext();
		PortletRequestDispatcher rd = context.getRequestDispatcher(this.viewPage);
        rd.include(request, response);
    }
}
***************************

So this portlet only supports the VIEW mode since I did not implement
doEdit and doHelp.  By default, it will attempt include
/WEB-INF/pages/view.jsp when it renders.  That is unless there is a
'ViewPage' init parameter declared in portlet.xml that will override
that.

The JSP could contain whatever content but you wouldn't put the HTML
tags nor the head or body tags because that is handled by the portal
as part of page aggregation.  You'd probably use the portlet tag lib
to output portlet links and so forth.

Your web.xml need not contain much:

********
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web
Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
  <display-name>My Portlet Application</display-name>

  <!-- Portlet tag library TLD -->
  <taglib>
    <taglib-uri>http://java.sun.com/portlet</taglib-uri>
    <taglib-location>/WEB-INF/tld/portlet.tld</taglib-location>
  </taglib>

</web-app>

**************
and even then, if you leave out the portlet tag-lib I think jetspeed injects it.

And the portlet.xml to support this simple portlet:
*****************
<?xml version="1.0" encoding="UTF-8"?>

<portlet-app id="tpn-portlet" version="1.0">

  <portlet id="myFirstPortlet">
	<init-param>
		<name>ViewPage</name>
		<value>/WEB-INF/pages/mycustompage.jsp</value>
	</init-param>
    <portlet-name>myFirstPortlet</portlet-name>
    <display-name>My First Portlet</display-name>
    <portlet-class>com.mycompany.portlet.SimpleJSPPortlet</portlet-class>
    <expiration-cache>-1</expiration-cache>
    <supports>
      <mime-type>text/html</mime-type>
      <portlet-mode>VIEW</portlet-mode>
    </supports>
    <supported-locale>en</supported-locale>
    <portlet-info>
      <title>My First Portlet</title>
      <short-title>My First Portlet</short-title>
    </portlet-info>
  </portlet>
</portlet-app>
***************

Then you just create a war for your app as you would for any servlet-based app.

So far, this applies to all JSR-168 compliant portals.

Here's the jetspeed specific stuff:

-Drop your war in jetspeed/WEB-INF/deploy and let jetspeed deploy it

-Use the portal site manager to make a page that will include your
portlet in it or hand-write a PSML page that will include it and put
it in jetspeed/WEB-INF/pages (see PSML documentation).

Next thing you're going to want to make your portlet actually do
stuff.  I would seriously recommend reading the Java Portlet
Specification 1.0 so that you are clear on what you can do in portlets
and what you can't when compared to servlets as well as learning about
the action and render phases and so forth...

On 6/16/06, Akshay Ahooja <ak...@gmail.com> wrote:
> Thanks Ruben,
>
> Do you have a jsp portlet with the .java files you could send me as an
> example?
>
> Thanks,
>
> Akshay
>
>
>
> On 6/16/06, Ruben Fragoso <ru...@tap.pt> wrote:
> >
> > In Addition:
> >
> > the definitions for you portlet are made in the "portlet.xml" file, either
> > under:
> >
> >        <init-param>
> >        <description>my desc</description>
> >              <name>myParamName</name>
> >        <value>myValue</value>
> >        </init-param>
> >
> >                        or under
> >
> >        <portlet-preferences>
> >        <preference>
> >                <name>myPreference</name>
> >                        <value>myPreferenceValue</value>
> >        </preference>
> >         </portlet-preferences>
> >
> > Depending if it is to be read in the initialization of the portlet, or  by
> > the user in EditMode
> >
> > Regards
> >
> > Ruben
> >
> > -----Original Message-----
> > From: Ruben Fragoso [mailto:ruben.fragoso@tap.pt]
> > Sent: sexta-feira, 16 de Junho de 2006 18:15
> > To: 'Jetspeed Users List'
> > Subject: RE: Adding my own portlet
> >
> >
> > The psml file is not create in the Tomcat\myportlet\myfile.psml. Besides
> > "psml" files are not portlets, they are the containers of jetspeed for you
> > to put your portlet in. You create a psml in the "Portal Site Manager"
> > option of the "Jetspeed Administrative Portlets" Menu
> >
> >
> > The default file for the portlet, is defined in the web.xml, under
> >
> >                <welcome-file-list>index.jsp</welcome-file-list>
> >
> >
> > Regards
> >
> > Ruben
> >
> >
> >
> > -----Original Message-----
> > From: Akshay Ahooja [mailto:akshayahooja@gmail.com]
> > Sent: sexta-feira, 16 de Junho de 2006 17:46
> > To: Jetspeed Users List
> > Subject: Adding my own portlet
> >
> >
> > I am trying to set up a portlet but it is showing errors when I deploy it.
> > I
> > would just like to review the steps:
> >
> > Using Jetspeed 2 - using maven jetspeed plugin 2.0
> >
> > What are the neccesary files needed to create a portlet?
> >
> > First I create a directory:
> >
> > c:/myportlet.
> >
> > Followed by:
> >
> > c:/myportlet/WEB-INF/classes
> >
> >
> > The files I think that are needed are:
> >
> > A .java file inside the classes directory which is compiled using
> > --> javac -cp
> > ~/.maven/repository/org.apache.portals.jetspeed-2/jars/portlet-api-1.0.jar
> > Myportlet.java
> >
> > NOTE: (I had to seperatley download portlet-api-1.0.jar and put it in the
> > right directory - is there another way to do this?)
> >
> > Then there is a need for:
> >
> > portlet.xml and web.xml.
> >
> >
> > This directory is made into a war :
> >
> > using: jar cvf ../myportlet.war .
> >
> >
> > Once this is copied into:
> >
> > tomcat/myportlet/web-inf/deploy,
> >
> > A psml file is created named:
> >
> > myportlet.psml inside myportal/web-inf/pages/.
> >
> >
> > Any other files needed?
> >
> >
> > Now with all these files - this is where I get confused - What file is for
> > defining what:
> >
> >   - Where is the main page of the portlet defined? Is it index.jsp by
> >   default right under myportlet/ ??       (JSP)
> >      - I assume this is where the entire Portlet Definition is
> >   - I assume using this main page there will be actions leading to .java
> >   classes - where are the action and validation classes defined?
> >      - I cannot seem to find any .java classes in the demo apps -
> >      anyone know where to locate them? If I can take a look at these it
> > would
> >      give me some examples to work from.
> >   - What wraps these things into a portlet - and what files tie in all
> >   these things together?
> >
> >
> > If I am not mistaken - to add a portlet there is no need to touch the
> > original portal until the portlet is deployed - and then only the psml
> > files
> > need to changed/added. The original portal only needs to be deployed once
> > -
> > and then only individual portlets are deployed when
> > created/updated/changed.
> >
> > Thanks,
> >
> > Akshay
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
> > For additional commands, e-mail: jetspeed-user-help@portals.apache.org
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
> > For additional commands, e-mail: jetspeed-user-help@portals.apache.org
> >
> >
>
>

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


Re: Adding my own portlet

Posted by Akshay Ahooja <ak...@gmail.com>.
Thanks Ruben,

Do you have a jsp portlet with the .java files you could send me as an
example?

Thanks,

Akshay



On 6/16/06, Ruben Fragoso <ru...@tap.pt> wrote:
>
> In Addition:
>
> the definitions for you portlet are made in the "portlet.xml" file, either
> under:
>
>        <init-param>
>        <description>my desc</description>
>              <name>myParamName</name>
>        <value>myValue</value>
>        </init-param>
>
>                        or under
>
>        <portlet-preferences>
>        <preference>
>                <name>myPreference</name>
>                        <value>myPreferenceValue</value>
>        </preference>
>         </portlet-preferences>
>
> Depending if it is to be read in the initialization of the portlet, or  by
> the user in EditMode
>
> Regards
>
> Ruben
>
> -----Original Message-----
> From: Ruben Fragoso [mailto:ruben.fragoso@tap.pt]
> Sent: sexta-feira, 16 de Junho de 2006 18:15
> To: 'Jetspeed Users List'
> Subject: RE: Adding my own portlet
>
>
> The psml file is not create in the Tomcat\myportlet\myfile.psml. Besides
> "psml" files are not portlets, they are the containers of jetspeed for you
> to put your portlet in. You create a psml in the "Portal Site Manager"
> option of the "Jetspeed Administrative Portlets" Menu
>
>
> The default file for the portlet, is defined in the web.xml, under
>
>                <welcome-file-list>index.jsp</welcome-file-list>
>
>
> Regards
>
> Ruben
>
>
>
> -----Original Message-----
> From: Akshay Ahooja [mailto:akshayahooja@gmail.com]
> Sent: sexta-feira, 16 de Junho de 2006 17:46
> To: Jetspeed Users List
> Subject: Adding my own portlet
>
>
> I am trying to set up a portlet but it is showing errors when I deploy it.
> I
> would just like to review the steps:
>
> Using Jetspeed 2 - using maven jetspeed plugin 2.0
>
> What are the neccesary files needed to create a portlet?
>
> First I create a directory:
>
> c:/myportlet.
>
> Followed by:
>
> c:/myportlet/WEB-INF/classes
>
>
> The files I think that are needed are:
>
> A .java file inside the classes directory which is compiled using
> --> javac -cp
> ~/.maven/repository/org.apache.portals.jetspeed-2/jars/portlet-api-1.0.jar
> Myportlet.java
>
> NOTE: (I had to seperatley download portlet-api-1.0.jar and put it in the
> right directory - is there another way to do this?)
>
> Then there is a need for:
>
> portlet.xml and web.xml.
>
>
> This directory is made into a war :
>
> using: jar cvf ../myportlet.war .
>
>
> Once this is copied into:
>
> tomcat/myportlet/web-inf/deploy,
>
> A psml file is created named:
>
> myportlet.psml inside myportal/web-inf/pages/.
>
>
> Any other files needed?
>
>
> Now with all these files - this is where I get confused - What file is for
> defining what:
>
>   - Where is the main page of the portlet defined? Is it index.jsp by
>   default right under myportlet/ ??       (JSP)
>      - I assume this is where the entire Portlet Definition is
>   - I assume using this main page there will be actions leading to .java
>   classes - where are the action and validation classes defined?
>      - I cannot seem to find any .java classes in the demo apps -
>      anyone know where to locate them? If I can take a look at these it
> would
>      give me some examples to work from.
>   - What wraps these things into a portlet - and what files tie in all
>   these things together?
>
>
> If I am not mistaken - to add a portlet there is no need to touch the
> original portal until the portlet is deployed - and then only the psml
> files
> need to changed/added. The original portal only needs to be deployed once
> -
> and then only individual portlets are deployed when
> created/updated/changed.
>
> Thanks,
>
> Akshay
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
> For additional commands, e-mail: jetspeed-user-help@portals.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
> For additional commands, e-mail: jetspeed-user-help@portals.apache.org
>
>

RE: Adding my own portlet

Posted by Ruben Fragoso <ru...@tap.pt>.
In Addition:

the definitions for you portlet are made in the "portlet.xml" file, either
under:
	
	<init-param>
      	<description>my desc</description>
	      <name>myParamName</name>
      	<value>myValue</value>
	</init-param>

			or under

	<portlet-preferences>
      	<preference>
	      	<name>myPreference</name>
	        	<value>myPreferenceValue</value>
      	</preference>
   	 </portlet-preferences>

Depending if it is to be read in the initialization of the portlet, or  by
the user in EditMode

Regards

Ruben

-----Original Message-----
From: Ruben Fragoso [mailto:ruben.fragoso@tap.pt] 
Sent: sexta-feira, 16 de Junho de 2006 18:15
To: 'Jetspeed Users List'
Subject: RE: Adding my own portlet


The psml file is not create in the Tomcat\myportlet\myfile.psml. Besides
"psml" files are not portlets, they are the containers of jetspeed for you
to put your portlet in. You create a psml in the "Portal Site Manager"
option of the "Jetspeed Administrative Portlets" Menu


The default file for the portlet, is defined in the web.xml, under

		<welcome-file-list>index.jsp</welcome-file-list>


Regards 

Ruben



-----Original Message-----
From: Akshay Ahooja [mailto:akshayahooja@gmail.com] 
Sent: sexta-feira, 16 de Junho de 2006 17:46
To: Jetspeed Users List
Subject: Adding my own portlet


I am trying to set up a portlet but it is showing errors when I deploy it. I
would just like to review the steps:

Using Jetspeed 2 - using maven jetspeed plugin 2.0

What are the neccesary files needed to create a portlet?

First I create a directory:

c:/myportlet.

Followed by:

c:/myportlet/WEB-INF/classes


The files I think that are needed are:

A .java file inside the classes directory which is compiled using
--> javac -cp
~/.maven/repository/org.apache.portals.jetspeed-2/jars/portlet-api-1.0.jar
Myportlet.java

NOTE: (I had to seperatley download portlet-api-1.0.jar and put it in the
right directory - is there another way to do this?)

Then there is a need for:

portlet.xml and web.xml.


This directory is made into a war :

using: jar cvf ../myportlet.war .


Once this is copied into:

tomcat/myportlet/web-inf/deploy,

A psml file is created named:

 myportlet.psml inside myportal/web-inf/pages/.


Any other files needed?


Now with all these files - this is where I get confused - What file is for
defining what:

   - Where is the main page of the portlet defined? Is it index.jsp by
   default right under myportlet/ ??       (JSP)
      - I assume this is where the entire Portlet Definition is
   - I assume using this main page there will be actions leading to .java
   classes - where are the action and validation classes defined?
      - I cannot seem to find any .java classes in the demo apps -
      anyone know where to locate them? If I can take a look at these it
would
      give me some examples to work from.
   - What wraps these things into a portlet - and what files tie in all
   these things together?


If I am not mistaken - to add a portlet there is no need to touch the
original portal until the portlet is deployed - and then only the psml files
need to changed/added. The original portal only needs to be deployed once -
and then only individual portlets are deployed when created/updated/changed.

Thanks,

Akshay


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


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


RE: Adding my own portlet

Posted by Ruben Fragoso <ru...@tap.pt>.
The psml file is not create in the Tomcat\myportlet\myfile.psml. Besides
"psml" files are not portlets, they are the containers of jetspeed for you
to put your portlet in. You create a psml in the "Portal Site Manager"
option of the "Jetspeed Administrative Portlets" Menu


The default file for the portlet, is defined in the web.xml, under

		<welcome-file-list>index.jsp</welcome-file-list>


Regards 

Ruben



-----Original Message-----
From: Akshay Ahooja [mailto:akshayahooja@gmail.com] 
Sent: sexta-feira, 16 de Junho de 2006 17:46
To: Jetspeed Users List
Subject: Adding my own portlet


I am trying to set up a portlet but it is showing errors when I deploy it. I
would just like to review the steps:

Using Jetspeed 2 - using maven jetspeed plugin 2.0

What are the neccesary files needed to create a portlet?

First I create a directory:

c:/myportlet.

Followed by:

c:/myportlet/WEB-INF/classes


The files I think that are needed are:

A .java file inside the classes directory which is compiled using
--> javac -cp
~/.maven/repository/org.apache.portals.jetspeed-2/jars/portlet-api-1.0.jar
Myportlet.java

NOTE: (I had to seperatley download portlet-api-1.0.jar and put it in the
right directory - is there another way to do this?)

Then there is a need for:

portlet.xml and web.xml.


This directory is made into a war :

using: jar cvf ../myportlet.war .


Once this is copied into:

tomcat/myportlet/web-inf/deploy,

A psml file is created named:

 myportlet.psml inside myportal/web-inf/pages/.


Any other files needed?


Now with all these files - this is where I get confused - What file is for
defining what:

   - Where is the main page of the portlet defined? Is it index.jsp by
   default right under myportlet/ ??       (JSP)
      - I assume this is where the entire Portlet Definition is
   - I assume using this main page there will be actions leading to .java
   classes - where are the action and validation classes defined?
      - I cannot seem to find any .java classes in the demo apps -
      anyone know where to locate them? If I can take a look at these it
would
      give me some examples to work from.
   - What wraps these things into a portlet - and what files tie in all
   these things together?


If I am not mistaken - to add a portlet there is no need to touch the
original portal until the portlet is deployed - and then only the psml files
need to changed/added. The original portal only needs to be deployed once -
and then only individual portlets are deployed when created/updated/changed.

Thanks,

Akshay


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