留言板

Spring MVC + Portlet Preferences

thumbnail
Marina Batet,修改在11 年前。

Spring MVC + Portlet Preferences

New Member 帖子: 24 加入日期: 11-4-18 最近的帖子
Hi,

I am developing in Liferay 6.1 with Spring. I haven't had any problems with the @Controller or @RequestMapping until now, but now I'm trying to run a controller to manage the portlet configuration / perferences and load a configuration view and I can't get it to work.

Step by step:

portlet.xml:


...
<supports>
			<mime-type>text/html</mime-type>
			<portlet-mode>view</portlet-mode>
			<portlet-mode>edit</portlet-mode>
</supports>
...


controllers.xml:

<bean id="portletModeParameterHandlerMapping" class="org.springframework.web.portlet.handler.PortletModeParameterHandlerMapping">
	<property name="portletModeParameterMap">
		<map>
			<entry key="view"> 
				<map>
					<entry key="action"><ref bean="mainController" /></entry>		 
				</map>
			</entry>
		
			<entry key="edit"> 
				<map>
					 <entry key="prefs"><ref bean="prefsHandler" /></entry>		
				</map>
		</entry>
		
		</map>
	</property>
</bean>


servlet-context.xml:

...
<beans:bean id="mainController" class="com.mypackage.controller.MainController" />
<beans:bean id="prefsHandler" class="com.mypackage.controller.ConfigurationController" />
...


ConfigurationController.java: (and here is where I don't really know how to do the method mappings):

@Controller
@RequestMapping("edit")
public class ConfigurationController  {

	private static final Logger log = LoggerFactory.getLogger(ConfigurationController.class);

	@RequestMapping //Default action 
	public ModelAndView mainHandler(RenderRequest request, RenderResponse response) throws Exception
	{	
		log.debug("mainHandler");
		Map<string, object> model = new HashMap<string, object>();
		return new ModelAndView("configuration", model);
	}

@ActionMapping
	protected void onSubmitAction(ActionRequest request, ActionResponse  response) throws Exception {

		log.debug("onSubmitAction");
	}

}
</string,></string,>


configuration.jsp:


<portlet:defineobjects />

&lt;% 

PortletPreferences prefs = renderRequest.getPreferences();
String portletResource = ParamUtil.getString(request, "portletResource");

if (Validator.isNotNull(portletResource)) {
	prefs = PortletPreferencesFactoryUtil.getPortletSetup(request, portletResource);
}
...


I think it does not even call my ConfigurationController class. Any ideas? Wich is the right way to do this?

Thanks in advanced!
thumbnail
Nagendra Kumar Busam,修改在11 年前。

RE: Spring MVC + Portlet Preferences

Liferay Master 帖子: 678 加入日期: 09-7-7 最近的帖子
Can you have a look into @ http://www.liferay.com/community/forums/-/message_boards/message/13637045. Let us know about whether it is working or not
thumbnail
Marina Batet,修改在11 年前。

RE: Spring MVC + Portlet Preferences

New Member 帖子: 24 加入日期: 11-4-18 最近的帖子
Nagendra Kumar Busam:
Can you have a look into @ http://www.liferay.com/community/forums/-/message_boards/message/13637045. Let us know about whether it is working or not


Thanks for the reply!

I have tried to make my controller as the one in the example that you provided, but it's still not working for me. When I open the portlet's configuration page, it shows only the permissions page, and the controller it's not even being called.

One thing that I have detected is that when I add the "edit" entry key in my controller.xml:


<entry key="edit">
                <map>

                    <entry key="edit"><ref bean="prefsHandler" /></entry>
                </map>
            </entry>


An error appears when I visualize the portlet (not when I'm reloading it or when I click in the configuration menu, but when I load / view the portlet). The error it's:

[indent]10:58:12,170 ERROR [AdvancedPermissionChecker:944]com.liferay.portal.NoSuchResourceActionException: myportlet_WAR_myportlet#PREFERENCES
com.liferay.portal.NoSuchResourceActionException: myportlet_WAR_myportlet#PREFERENCES
[/indent]

What's the meaning of this error? It's there anything missing in my portlet?

Thanks for the help!!
thumbnail
Marina Batet,修改在11 年前。

RE: Spring MVC + Portlet Preferences

New Member 帖子: 24 加入日期: 11-4-18 最近的帖子
Well, it's working now, and I'm not really sure of what I changed in my portlet.

Anyway, the resultant code is (if anyone it's interested).

servlet-context.xml:


...
<beans:bean id="configurationController" class="com.mypackage..controller.ConfigurationController" />
...


controller.xml:


...
<entry key="edit">
                <map>
                    <entry key="edit"><ref bean="configurationController" /></entry>
                </map>
            </entry>
....


ConfigurationController.java:


@Controller
@RequestMapping("edit")
public class ConfigurationController  {

	private static final Logger log = LoggerFactory.getLogger(ConfigurationController.class);

	@RenderMapping
    public String render(    Model model, PortletPreferences prefs)
    {
		log.error("render");

        model.addAttribute("attribute", prefs.getValue("prefVal", "default"));

        return "configuration";
    }

    @ActionMapping(params = "action=save")
    public void action(    @RequestParam("myparam") String myparam,   PortletPreferences prefs,  ActionResponse response) throws ReadOnlyException, ValidatorException, IOException, PortletModeException
    {
       
    	log.error("action");

    	//Obtenim el parametre entrat per l'usuari al form

    			if (myparam != null &amp;&amp; !myparam.equals(""))
    			{
    				prefs.reset("myparam");
    				prefs.setValue("myparam", myparam);
    			}

    			//Guardem les noves preferencies
    			prefs.store();
    }
}


configuration.jsp:


&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%&gt;
&lt;%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %&gt; 
&lt;%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %&gt; 
&lt;%@ page import="com.liferay.portal.kernel.util.*" %&gt;
&lt;%@ page import="com.liferay.portal.kernel.util.*" %&gt;
&lt;%@ page import="com.liferay.portlet.*" %&gt;
 
&lt;%@ page import="javax.portlet.*" %&gt; 

<portlet:defineobjects />

&lt;% 

PortletPreferences prefs = renderRequest.getPreferences();
String portletResource = ParamUtil.getString(request, "portletResource");

if (Validator.isNotNull(portletResource)) {
	prefs = PortletPreferencesFactoryUtil.getPortletSetup(request, portletResource);
}

String urlWorkflowPeticio = (String)prefs.getValue("myparam","");

%&gt;
<form action="<liferay-portlet:actionURL portletConfiguration=" true">" method="post" name="<portlet:namespace />fm"&gt;	
	My Param: <input size="50" type="text" value="<%=myparam%>" name="<portlet:namespace />myparam"><br><br>	
	
	<input type="hidden" name="action" value="save">
	<input type="button" value="Save" onClick="submitForm(document.<portlet:namespace />fm);"><br><br> 			
</form>
Lior Hadaya,修改在11 年前。

RE: Spring MVC + Portlet Preferences

Regular Member 帖子: 138 加入日期: 12-1-24 最近的帖子
Hi Marina, thank you for the code sample.
I am trying to achive the same goal.
I followed your last post but for some reason it won't work for me.
Did you have to change anything in the liferay xml files?

Does your configuration page show up as the "set up" tab on the configuration window or does it appear as another option in the menu - preferences - which changes the portlet mode to edit?

Thanks,
Lior
Lior Hadaya,修改在11 年前。

RE: Spring MVC + Portlet Preferences

Regular Member 帖子: 138 加入日期: 12-1-24 最近的帖子
Another question, if you use the JSR 286 standard for dealing with the portlet preferences instead of Liferay's API, how does Liferay know to save them for you in the DB?
thumbnail
Vitor Silva,修改在11 年前。

RE: Spring MVC + Portlet Preferences

Junior Member 帖子: 36 加入日期: 12-5-3 最近的帖子
Liferay implements the JSR 286 specification. So if you have a couple of preferences and invoke the store for your portlet preferences, Liferay will save them in the database (we have an XML representation of the preferences) .
thumbnail
Marina Batet,修改在11 年前。

RE: Spring MVC + Portlet Preferences

New Member 帖子: 24 加入日期: 11-4-18 最近的帖子
Lior Hadaya:
Hi Marina, thank you for the code sample.
I am trying to achive the same goal.
I followed your last post but for some reason it won't work for me.
Did you have to change anything in the liferay xml files?

Does your configuration page show up as the "set up" tab on the configuration window or does it appear as another option in the menu - preferences - which changes the portlet mode to edit?

Thanks,
Lior



In your portlet.xml file be sure to add the edit portlet mode:


<supports>
			<mime-type>text/html</mime-type>
			<portlet-mode>view</portlet-mode>
			<portlet-mode>edit</portlet-mode>
		</supports>


I have nothing added in my liferay-portlet.xml.
Jewel Picar,修改在8 年前。

RE: Spring MVC + Portlet Preferences

New Member 发布: 1 加入日期: 16-4-13 最近的帖子
Hello. Can I view your web.xml? emoticon