Portlet Development III The ActionPortlet Model: Tags, Beans, and Events

advertisement
Portlet Development III
The ActionPortlet Model: Tags, Beans,
and Events
Jason Novotny novotny@aei.mpg.de
Michael Russell russell@aei.mpg.de
Oliver Wehrens wehrens@aei.mpg.de
Albert Einstein Institute
Portals & Portlets 2003; July 14 -17 2003; Edinburgh
Critique of Portlet Model
In complex portlet development navigation between
various “views” and events can be difficult to manage
Developers must still write lots of tedious CSS/HTML to
create presentations.
Lots of portlet actions can lead to actionPerformed
methods with large amounts of branching logic:
public void actionPerformed(ActionEvent event) {
String actionName = event.getAction().getName();
if (actionName.equals(“doThis”) {
doThis();
} else if (actionName.equals(“doThat”)) {
doThat();
} else if …
}
Portals & Portlets 2003; July 14 -17 2003; Edinburgh
The ActionPortlet
ActionPortlet acts as an intelligent dispatcher that hides
branching logic from a portlet developer
A subclass of ActionPortlet makes use of the dispatching
mechanisms and defines the action and view methods to
invoke for a particuar event
ActionPortlet provides setNextState() method that is used to
specify the next display state that should be presented after an
action method. Also setNextTitle and setNextError are
provided.
ActionPortlet provides default actionPerformed and doXXX
methods so normally these methods need not be defined in the
ActionPortlet subclass
Specify default pages in init method of portlet:
DEFAULT_VIEW_PAGE, DEFAULT_EDIT_PAGE, etc.
Portals & Portlets 2003; July 14 -17 2003; Edinburgh
Example Portlet
public class ExamplePortlet extends ActionPortlet {
public void init(PortletConfig config) throws UnavailableException {
super.init(config);
}
public void initConcrete(PortletSettings settings) throws UnavailableException {
super.initConcrete(settings);
DEFAULT_VIEW_PAGE = ”example/view.jsp";
}
public void doStuff(FormEvent event) throws PortletException {
…
setNextState(event.getPortletRequest(), DEFAULT_VIEW_PAGE);
}
…
}
Portals & Portlets 2003; July 14 -17 2003; Edinburgh
Action Methods
ActionPortlet provides subclassed portlets with
FormEvent object that acts as decorator for
ActionEvent to provide form-based visual components
public interface FormEvent extends ActionEvent {
public FileInputBean getFileInputBean(String beanId)
throws IOException;
public ErrorFrameBean getErrorFrameBean(String beanId);
public CheckBoxBean getCheckBoxBean(String beanId);
public TextFieldBean getTextFieldBean(String beanId);
public HiddenFieldBean getHiddenFieldBean(String beanId);
public PasswordBean getPasswordBean(String beanId);
public TextAreaBean getTextAreaBean(String beanId);
public TextBean getTextBean(String beanId);
…
}
Portals & Portlets 2003; July 14 -17 2003; Edinburgh
Visual Beans
Instead of using HTML in Portlet java code, visual beans
provide wrappers around CSS/HTML that allows portlet
developers to modify or create presentation elements
Standard HTML elements are wrapped as beans:
CheckBoxBean. ListBoxBean, TableBean, HiddenFieldBean,
TextFieldBean, PasswordBean. etc.
Beans are identified by tags, called “beanId” which acts a label.
Beans are created at every request and are updated after
request has been generated and made available to portlet
action methods
Every visual bean has a corresponding UI tag that may be
used in JSP pages to produce presentation output
Portals & Portlets 2003; July 14 -17 2003; Edinburgh
UI Tag Library
Action model provides value-added tag library to make creating
presentations more like component based design like Swing.
Tags that wish to be accessed by a portlet must declare a
beanId
<ui:form>
<ui:panel>
<ui:frame>
<ui:tablerow>
<ui:tablecell width="100">
<ui:text key="LOGIN_NAME"/>
</ui:tablecell>
</ui:tablerow>
</ui:frame>
…
</ui:panel>
</ui:form>
Portals & Portlets 2003; July 14 -17 2003; Edinburgh
UI Tag Usage
Any JSP that wishes to use the UI tag library must
include the following boilerplate JSP:
<%@ taglib uri="/portletUI" prefix="ui" %>
<%@ taglib uri="/portletAPI" prefix="portletAPI" %>
<portletAPI:init/>
This instructs the page to include the Portlet and UI
tag libraries
Portals & Portlets 2003; July 14 -17 2003; Edinburgh
UI Tag Attributes
Most presentation beans/tags subclass from
BaseComponentBean and BaseComponentTag
which provides following fields:
beanId - name of the presentation tag/bean
name - name as used in HTML elements
value - value as used in HTML elements
key - a key that represents a localized properties file key
width - width of the component
font - font to be used
cssStyle - the CSS style
Tag attributes can also be passed in as request time
values:
<ui:text value=<%= myFavoriteFruit %>/>
Portals & Portlets 2003; July 14 -17 2003; Edinburgh
Localized Messages
In general any text displayed in a portlet should be
localized
Use the TextTag!
<ui:text key="LOGIN"/>
The key attribute specifies the key used in the
Portlet.properties_<country> file found in WEBINF/classes
All presentation tags that display text include key
attribute:
ActionSubmitTag for displaying buttons
Portals & Portlets 2003; July 14 -17 2003; Edinburgh
Creating Actions
Action presentation elements can trigger portlet
events
ActionLink -- creates a hyperlink with a specified
action
ActionSubmitButton -- creates a button with a
specified action
Form-- provides “action” attribute to trigger an action
from a form submission
Action elements can include nested ActionParam
elements for associating additional name/value
parameters to an action
Portals & Portlets 2003; July 14 -17 2003; Edinburgh
Creating Actions (cont.)
Creating an actionlink with actionparams:
<ui:actionlink action=”doSomething" value=”Click Me">
<ui:actionparam name=“color” value=“red”/>
<ui:actionparam name=“fruit” value=“apple”/>
</ui:actionlink>
Creating a default form:
<ui:form action=“doAction”>
<ui:textfield beanId=“fruit” size=“15” value=“apple”/>
</ui:form>
Creating a form with buttons:
<ui:form>
<ui:actionsubmit action=“doAction” value=“Click Me”/>
<ui:actionsubmit action=“doAnotherAction” value=“No, me”/>
</ui:form>
Portals & Portlets 2003; July 14 -17 2003; Edinburgh
Container Tags and Beans
Several beans/tags act as containers for other beans/tags
A <ui:panel> tag contains nested <ui:frame> or <ui:table> tags
to produce stylized nested tables
A <ui:table> or <ui:frame> tag is composed of nested
<ui:tablerow> tags which contain nested <ui:tablecell> tags to
produce stylized tables
A <ui:form> tag is a container for all tags included within it.
A <ui:listbox> tag can contain nested <ui:listboxitem> tags
Action tags are containers for <ui:actionparam> tags to specify
additional action parameters.
Portals & Portlets 2003; July 14 -17 2003; Edinburgh
Conclusion
ActionPortlet model is the “GridSphere recommended
approach” for building complex portlets
Tags and Beans provide value-added functionality
Default navigation methods take care of forwarding to the
appropriate page, error handling and setting portlet title.
The UI tag library provides a toolbox of reusable presentation
components
UI tag library frees developers from working with HTML/CSS
Future goal is to integrate JavaScript/DHTML into tags for
increased interactivity
Please contact us with comments, questions, suggestions on
improving the model!
Portals & Portlets 2003; July 14 -17 2003; Edinburgh
Download