Foros de discusión

Spring MVC + Portlet Preferences

thumbnail
Marina Batet, modificado hace 11 años.

Spring MVC + Portlet Preferences

New Member Mensajes: 24 Fecha de incorporación: 18/04/11 Mensajes recientes
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, modificado hace 11 años.

RE: Spring MVC + Portlet Preferences

Liferay Master Mensajes: 678 Fecha de incorporación: 7/07/09 Mensajes recientes
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, modificado hace 11 años.

RE: Spring MVC + Portlet Preferences

New Member Mensajes: 24 Fecha de incorporación: 18/04/11 Mensajes recientes
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, modificado hace 11 años.

RE: Spring MVC + Portlet Preferences

New Member Mensajes: 24 Fecha de incorporación: 18/04/11 Mensajes recientes
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, modificado hace 11 años.

RE: Spring MVC + Portlet Preferences

Regular Member Mensajes: 138 Fecha de incorporación: 24/01/12 Mensajes recientes
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, modificado hace 11 años.

RE: Spring MVC + Portlet Preferences

Regular Member Mensajes: 138 Fecha de incorporación: 24/01/12 Mensajes recientes
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, modificado hace 11 años.

RE: Spring MVC + Portlet Preferences

Junior Member Mensajes: 36 Fecha de incorporación: 3/05/12 Mensajes recientes
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, modificado hace 11 años.

RE: Spring MVC + Portlet Preferences

New Member Mensajes: 24 Fecha de incorporación: 18/04/11 Mensajes recientes
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, modificado hace 8 años.

RE: Spring MVC + Portlet Preferences

New Member Mensaje: 1 Fecha de incorporación: 13/04/16 Mensajes recientes
Hello. Can I view your web.xml? emoticon