掲示板

Setting initial portlet mode to Edit

10年前 に Sean Krems によって更新されました。

Setting initial portlet mode to Edit

New Member 投稿: 8 参加年月日: 10/10/07 最新の投稿
I am working with a version of the PrimeFaces demo found at https://www.liferay.com/community/liferay-projects/liferay-faces/demos and my goal is to use the Preferences dropdown (Edit portlet mode) to allow the user to configure a query to an Oracle database and display the results in a table (View portlet mode).
portlet.xml

 <portlet-name>status</portlet-name>
 <display-name>Status</display-name>
 <portlet-class>com.my.dashboard.portlet.SystemStatusPortlet</portlet-class>
    <init-param>
            <name>javax.portlet.faces.defaultViewId.view</name>
            <value>/views/status/portletViewMode.xhtml</value>
    </init-param>
    <init-param>
             <name>javax.portlet.faces.defaultViewId.edit</name>
             <value>/views/status/portletEditMode.xhtml</value>
    </init-param>


I'm using a custom class that extends GenericFacesPortlet and I want the Edit mode to initially display and then once that is set the View mode should only be displayed. I'm attempting to set the ViewId to the Edit screen temporarily and then switch it back to portletViewMode.xhtml later (I havent figured out how/when to switch yet - just trying to get the Edit to display intially). However, this code still uses the View screen when the portlet is added even though I believe I am "overwriting" it with the Edit screen.

my java class

public class SystemStatusPortlet extends GenericFacesPortlet{
	
	public void doView(RenderRequest renderRequest, RenderResponse renderResponse) 
			throws PortletException, IOException {
		
		renderRequest.setAttribute("javax.portlet.faces.defaultViewId.view", "/views/status/portletEditMode.xhtml");
		super.doView(renderRequest, renderResponse);
	}
}


I am relatively new to custom portlet development using JSF. Is what I am attempting to do even possible and has anyone had success getting something similar to work? Could someone with more portlet experience help with this issue?

Thanks for your help,
Sean
thumbnail
10年前 に Kyle Joseph Stiemann によって更新されました。

RE: Setting initial portlet mode to Edit

Liferay Master 投稿: 760 参加年月日: 13/01/14 最新の投稿
Hi Sean,
Since you probably want the initial portlet view to contain a freindly URL, it is probably best not to mess with EDIT mode initially. Instead, you can just have the portlet display the preferences view without switching to edit mode. There are two ways that this can be done:
  • You can add this line to PortletViewMode.xhtml:
    <ui:include src="#{backingBean.defaultView}" />
    Then in the backing bean, you just need to add code which decides what the default view is based on whether preferences have been chosen or not.
  • Otherwise, you can do this in PortletViewMode.xhtml:
    <c:choose>
        <c:when test="#{backingBean.preferencesSaved}">
            <ui:include src="normal.xhtml" />
        </c:when>
        <c:otherwise>
            <ui:include src="preferences.xhtml" />
        </c:otherwise>
    </c:choose>
    In this case all that is needed in the backing bean is a boolean which knows whether preferences have been chosen or not.

Hope that helps,
- Kyle