views:

1076

answers:

1

I'm new to Java portlets, and am trying to get a handle on how these things work at a fairly basic level.

I'm confused now about how to have multiple "views" in my portlet. Let's say my portlet will be used for CRUD operations. For the sake of simplicity, I'm imagining that when a user first views the portlet they'll see a table with all of the records from the database. The user might then be able to click a record which will show a new page in the portlet containing a form for updating the record. Adding a record would work in much the same way. Nothing shocking here...

Where do I control how the user navigates between the different views, and where do I switch between the different actions that the user might perform (update, add, delete, etc)?

I've looked online and have found a ton of "hello world" portlet tutorials, which don't help much. I've found many other tutorials that are more advanced and geared towards what I'm doing, but they all seem to use some underlying framework like Struts, JSF, etc.

I'd like to know how to make this work using just a basic portlet using JSPs to render the views.

+3  A: 

Portlet API (JSR-168) is what you need to look for. This will explain to you how views are managed by portlet container, how portlets are rendered and how actions are mapped.

Co

  • portlet interaction is always 2-phase - action and render - while web server interaction is always single phase;
  • in a standard Web application, the form is submitted to the servlet specified in action field of the html form tag. In JSR-168 portlet, the action URL for an HTML form is generated using the actionURL portlet tag e.g. <form action="<portlet:actionURL/>" method="post">
  • submitting the HTML form results in invoking the processAction(ActionRequest aRequest, ActionResponse aResponse) method of a portlet
  • servlets are allowed to do include, forward, and redirect; portlets are only allowed to include.
  • Servlets can render a complete page, portlets render only page fragments.
  • and so on
grigory
Yes, I understand that. But what if I have three JSPs, each with a different form. Do they all trigger the same processAction function in my portlet, and then I just switch based on....some hidden form field or something?
Boden
Yes, we use hidden input parameter to route request to various JSPs.
grigory