The container calls render method to generate content in render phase. The default implementation is as follows
1. it internally calls dispatch method which performs main task
2. dispatch method, first try to find a method which annotated with RenderMode and name equal to
portlet mode. it calls that method if it finds
Ex:
@RenderMode(name="HELP")
public void renderHelp(RenderRequest request,
RenderResponse response)throws PortletException, IOException {
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/help.jsp").
include(request,response);
}
public void renderHelp(RenderRequest request,
RenderResponse response)throws PortletException, IOException {
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/help.jsp").
include(request,response);
}
3. If there in no annotated method, then it calls default doXYZ methods
doView
doEdit
doHelp
/**
* The default implementation of this method routes the render request to:
* <ol>
* <li>method annotated with <code>@RenderMode</name> and the name of the
* portlet mode</li>
* <li>a set of helper methods depending on the current portlet mode the portlet
* is currently in. These methods are:
* <ul>
* <li><code>doView</code> for handling <code>view</code> requests</li>
* <li><code>doEdit</code> for handling <code>edit</code> requests</li>
* <li><code>doHelp</code> for handling <code>help</code> requests</li>
* </ul>
* </li>
* </ul>
* <P>
* If the window state of this portlet is <code>minimized</code>, this
* method does not invoke any of the portlet mode rendering methods.
* <p>
* For handling custom portlet modes the portlet should either use the
* <code>@RenderMode</code> annotation or override this
* method. Note that the annotated methods needs to be public in order
* to be allowed to be called by <code>GenericPortlet</code>.
* The default implementation of this method routes the render request to:
* <ol>
* <li>method annotated with <code>@RenderMode</name> and the name of the
* portlet mode</li>
* <li>a set of helper methods depending on the current portlet mode the portlet
* is currently in. These methods are:
* <ul>
* <li><code>doView</code> for handling <code>view</code> requests</li>
* <li><code>doEdit</code> for handling <code>edit</code> requests</li>
* <li><code>doHelp</code> for handling <code>help</code> requests</li>
* </ul>
* </li>
* </ul>
* <P>
* If the window state of this portlet is <code>minimized</code>, this
* method does not invoke any of the portlet mode rendering methods.
* <p>
* For handling custom portlet modes the portlet should either use the
* <code>@RenderMode</code> annotation or override this
* method. Note that the annotated methods needs to be public in order
* to be allowed to be called by <code>GenericPortlet</code>.
protected void doDispatch(RenderRequest request, RenderResponse response) throws PortletException,
java.io.IOException {
WindowState state = request.getWindowState();
if (!state.equals(WindowState.MINIMIZED)) {
PortletMode mode = request.getPortletMode();
// first look if there are methods annotated for
// handling the rendering of this mode
try {
// check if mode is cached
Method renderMethod = renderModeHandlingMethodsMap.get(mode.toString());
if (renderMethod != null) {
renderMethod.invoke(this, request, response);
return;
}
} catch (Exception e) {
throw new PortletException(e);
}
// if not, try the default doXYZ methods
if (mode.equals(PortletMode.VIEW)) {
doView(request, response);
} else if (mode.equals(PortletMode.EDIT)) {
doEdit(request, response);
} else if (mode.equals(PortletMode.HELP)) {
doHelp(request, response);
} else {
throw new PortletException("unknown portlet mode: " + mode);
}
}
}
java.io.IOException {
WindowState state = request.getWindowState();
if (!state.equals(WindowState.MINIMIZED)) {
PortletMode mode = request.getPortletMode();
// first look if there are methods annotated for
// handling the rendering of this mode
try {
// check if mode is cached
Method renderMethod = renderModeHandlingMethodsMap.get(mode.toString());
if (renderMethod != null) {
renderMethod.invoke(this, request, response);
return;
}
} catch (Exception e) {
throw new PortletException(e);
}
// if not, try the default doXYZ methods
if (mode.equals(PortletMode.VIEW)) {
doView(request, response);
} else if (mode.equals(PortletMode.EDIT)) {
doEdit(request, response);
} else if (mode.equals(PortletMode.HELP)) {
doHelp(request, response);
} else {
throw new PortletException("unknown portlet mode: " + mode);
}
}
}
No comments:
Post a Comment