Foren

Portlet development: configuration updates only after refresh

Lior Hadaya, geändert vor 11 Jahren.

Portlet development: configuration updates only after refresh

Regular Member Beiträge: 138 Beitrittsdatum: 24.01.12 Neueste Beiträge
Hi,
I'm using Liferay EE 6.1.10 and I'm trying to develop my own portlet, using the plugins SDK, inheriting from MVCPortlet.

I followed this guide http://www.liferay.com/community/wiki/-/wiki/Main/Add+Config+Page+to+Plugin+Portlet in order to create a configuration jsp page that will appear as the Setup tab in the portlet's configuration.
In the setup tab I have one text box and a save button.
The view.jsp of my portlet displays the value that the user typed in the configuration.jsp page.

My problem is that after I click save, I don't see the green message saying the request completed successfully and the parameter doesn't update on my view.jsp.
Only after I close the configuration dialog and refresh the browser, the parameter change is reflected in my portlet's view.jsp.

What am I missing? This is the relevant code:

View.jsp
<% PortletPreferences preferences = renderRequest.getPreferences();
	
	String portletResource = ParamUtil.getString(request, "portletResource");
	
	if (Validator.isNotNull(portletResource)) {
		preferences = PortletPreferencesFactoryUtil.getPortletSetup(request, portletResource);
	}

	String param_name = preferences.getValue("pref-title","");
	
	%>
<br>
The title parameter is now &lt;%=param_name%&gt; <br>


Configuration.jsp
&lt;%
	PortletPreferences preferences = renderRequest.getPreferences();
	
	String portletResource = ParamUtil.getString(request, "portletResource");
	
	if (Validator.isNotNull(portletResource)) {
		preferences = PortletPreferencesFactoryUtil.getPortletSetup(request, portletResource);
	}

	String param_name = preferences.getValue("pref-title","");
%&gt;

<form action="<liferay-portlet:actionURL portletConfiguration=" true">" method="post" name="<portlet:namespace />fm"&gt; 
<input name="<portlet:namespace /><%=Constants.CMD%>" type="hidden" value="<%=Constants.UPDATE%>"> <br>
<table>
	<tbody><tr>
		<td>Title:</td>
		<td>
			&lt;%
				if (preferences != null) {
			%&gt;
				<input name="txtTitle" type="text" value="<%=param_name %>">
			&lt;%
				} else {
			%&gt;
				<input name="txtTitle" type="text" value="">
			&lt;%
				}
			%&gt;
		</td>
	</tr>
</tbody></table>
<input type="button" value="<liferay-ui:message key=" save">" onClick="submitForm(document.<portlet:namespace />fm);" /&gt;
<br>
</form>


ConfigurationActionImpl.java
public class ConfigurationActionImpl implements ConfigurationAction {

	@Override
	public void processAction(PortletConfig config, ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
		 
		String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
		
		if (!cmd.equals(Constants.UPDATE)) {
			return;
		} 
		
		String title = actionRequest.getParameter("txtTitle");
		
		String portletResource = ParamUtil.getString(actionRequest, "portletResource"); 
		PortletPreferences prefs = PortletPreferencesFactoryUtil.getPortletSetup(actionRequest, portletResource); 

		//Read, validate, and then set form parameters as portlet prerferences //

		
		prefs.setValue("pref-title", title);
		prefs.store();

		SessionMessages.add( 
				actionRequest, config.getPortletName() + ".doConfigure"); 

	}

	@Override
	public String render(PortletConfig arg0, RenderRequest arg1,
			RenderResponse arg2) throws Exception {

		return "/configuration.jsp";
	}

}


Thanks a lot,
Lior
Lior Hadaya, geändert vor 11 Jahren.

RE: Portlet development: configuration updates only after refresh

Regular Member Beiträge: 138 Beitrittsdatum: 24.01.12 Neueste Beiträge
Anyone? please?
thumbnail
Pilar Hidalgo, geändert vor 11 Jahren.

RE: Portlet development: configuration updates only after refresh

New Member Beiträge: 14 Beitrittsdatum: 10.04.12 Neueste Beiträge
I have the same problem.... Did you solve it?
Lior Hadaya, geändert vor 11 Jahren.

RE: Portlet development: configuration updates only after refresh

Regular Member Beiträge: 138 Beitrittsdatum: 24.01.12 Neueste Beiträge
No, it's still an open issue for me.
bo li, geändert vor 11 Jahren.

RE: Portlet development: configuration updates only after refresh

Junior Member Beiträge: 38 Beitrittsdatum: 14.11.11 Neueste Beiträge
Have you found the solution for this yet?
Lior Hadaya, geändert vor 11 Jahren.

RE: Portlet development: configuration updates only after refresh

Regular Member Beiträge: 138 Beitrittsdatum: 24.01.12 Neueste Beiträge
No, it's still an open issue for me.
bo li, geändert vor 11 Jahren.

RE: Portlet development: configuration updates only after refresh

Junior Member Beiträge: 38 Beitrittsdatum: 14.11.11 Neueste Beiträge
Hi, I have found where the problem is, I am using 6.1EE.

http://www.liferay.com/community/wiki/-/wiki/Main/Add+Config+Page+to+Plugin+Portlet

SessionMessages.add(actionRequest, config.getPortletName() + ".doConfigure");
After this line, we need to add another line:
super.processAction(portletConfig, actionRequest, actionResponse);

Then it will show success message and update the portlet automatically.
thumbnail
Randy Parsons, geändert vor 11 Jahren.

RE: Portlet development: configuration updates only after refresh

Junior Member Beiträge: 33 Beitrittsdatum: 04.01.11 Neueste Beiträge
Hello,

Thank you for the response as I have been trying to solve this for awhile. I eventually got the "Success" message to appear using a different technique but it never updated the view.jsp when I returned. So when I saw your reply, I thought I'd give it another try.

However, after adding the line you indicated, I now get a fatal exception error:
The method processAction(PortletConfig, ActionRequest, ActionResponse) is undefined for the type Object

When in Eclipse I can never get the processAction resolved in the line added:

super.processAction(portletConfig, actionRequest, actionResponse);


Eclipse gives the same message as the error when running it. It's as if I'm missing an Import, but I can't find anything missing.
thumbnail
David H Nebinger, geändert vor 11 Jahren.

RE: Portlet development: configuration updates only after refresh

Liferay Legend Beiträge: 14916 Beitrittsdatum: 02.09.06 Neueste Beiträge
You can only call the method on the super class if you have a super class. The OP's first post indicated they were just implementing an interface, not extending a superclass...
Lior Hadaya, geändert vor 11 Jahren.

RE: Portlet development: configuration updates only after refresh

Regular Member Beiträge: 138 Beitrittsdatum: 24.01.12 Neueste Beiträge
David H Nebinger:
You can only call the method on the super class if you have a super class. The OP's first post indicated they were just implementing an interface, not extending a superclass...



Is implementing the interface the right way to go? What's the other option that extends a superclass?
I still can't get this to work.. please advise

Thanks
Lior Hadaya, geändert vor 11 Jahren.

RE: Portlet development: configuration updates only after refresh

Regular Member Beiträge: 138 Beitrittsdatum: 24.01.12 Neueste Beiträge
Also, what worked for me before with displaying the parameter's value in view.jsp doesn't work anymore..

when I run this code
&lt;% PortletPreferences preferences = renderRequest.getPreferences();
    
    String portletResource = ParamUtil.getString(request, "portletResource");
    
    if (Validator.isNotNull(portletResource)) {
        preferences = PortletPreferencesFactoryUtil.getPortletSetup(request, portletResource);
    }

    String param_name = preferences.getValue("pref-title","");
    
    %&gt;
<br>
The title parameter is now &lt;%=param_name%&gt; <br>


It doesn't show the parameter's value. Validator.isNotNull(portletResource) returns false (i.e portletResource is null).

Any help would be greatly appreciated..

Thanks
Lior Hadaya, geändert vor 11 Jahren.

RE: Portlet development: configuration updates only after refresh

Regular Member Beiträge: 138 Beitrittsdatum: 24.01.12 Neueste Beiträge
I ended up using a different way to get the portletResource:
String portletResource = (themeDisplay.getPortletDisplay()).getId();


This worked, I can display the configuration value in the view but the original problem that I must refresh the page after saving the configuration settings in order for the view to update still exists.
Lior Hadaya, geändert vor 11 Jahren.

RE: Portlet development: configuration updates only after refresh

Regular Member Beiträge: 138 Beitrittsdatum: 24.01.12 Neueste Beiträge
I will continue updating on my attempt to solve this hoping one of you might be able to step in and assist..

I began looking at how Liferay implements configuation.jsp pages, for the polls display portlet for example.
I see that polls display's configuration's page uses aui, like this:

&lt;%
String redirect = ParamUtil.getString(request, "redirect");
questionId = ParamUtil.getLong(request, "questionId", questionId);
List<pollsquestion> questions = PollsQuestionLocalServiceUtil.getQuestions(scopeGroupId);
if (scopeGroupId != themeDisplay.getCompanyGroupId()) {
	questions = ListUtil.copy(questions);
	questions.addAll(PollsQuestionLocalServiceUtil.getQuestions(themeDisplay.getCompanyGroupId()));
}
%&gt;

<liferay-portlet:actionurl portletConfiguration="true" var="configurationURL" />

<aui:form action="<%= configurationURL %>" method="post" name="fm">
	<aui:input name="<%= Constants.CMD %>" type="hidden" value="<%= Constants.UPDATE %>" />
	<aui:input name="redirect" type="hidden" value="<%= redirect %>" />

	<c:choose>
		<c:when test="<%= !questions.isEmpty() %>">
			<aui:fieldset>
				<aui:select label="question" name="preferences--questionId--">
	                          ...
			</aui:select>
			</aui:fieldset>
		</c:when>
		<c:otherwise>
		</c:otherwise>
	</c:choose>

	<aui:button-row>
		<aui:button disabled="<%= questions.isEmpty() %>" type="submit" />
	</aui:button-row>
</aui:form>
</pollsquestion>


Does this mean I need to use aui too?
I tried to implement my configuration page in a similar way but I get an exception when using aui:form tag:
 java.lang.NoClassDefFoundError: com/liferay/portal/kernel/servlet/ DirectServletContext


Any thoughts?

Thanks
thumbnail
Florencia Gadea, geändert vor 11 Jahren.

RE: Portlet development: configuration updates only after refresh

Regular Member Beiträge: 146 Beitrittsdatum: 27.03.12 Neueste Beiträge
Hi Lior,

Were you finally able to solve this issue?

Lior Hadaya:

I tried to implement my configuration page in a similar way but I get an exception when using aui:form tag:
 java.lang.NoClassDefFoundError: com/liferay/portal/kernel/servlet/ DirectServletContext



Regards,

Flor.
thumbnail
Hitoshi Ozawa, geändert vor 11 Jahren.

RE: Portlet development: configuration updates only after refresh

Liferay Legend Beiträge: 7942 Beitrittsdatum: 24.03.10 Neueste Beiträge
If you're using Liferay IDE, you can just check Configuration during new project wizard (check custom) to create a empty configuration page.
This is probably the easiest the surest way to create a configuration page.
Lior Hadaya, geändert vor 11 Jahren.

RE: Portlet development: configuration updates only after refresh

Regular Member Beiträge: 138 Beitrittsdatum: 24.01.12 Neueste Beiträge
I eventually implemented this differently, with a spring portlet.
I have a method in the Controller that returns the configuration values and I call it using AJAX after the user saves the configuration.
Mikko Torri, geändert vor 11 Jahren.

RE: Portlet development: configuration updates only after refresh

Junior Member Beiträge: 33 Beitrittsdatum: 10.05.11 Neueste Beiträge
As described here instead of
SessionMessages.add(actionRequest,
config.getPortletName() + ".doConfigure");

use
SessionMessages.add(actionRequest, 
portletConfig.getPortletName() + SessionMessages.KEY_SUFFIX_REFRESH_PORTLET,
portletResource);


It will reload the portlet automatically.
thumbnail
Vishal Panchal, geändert vor 9 Jahren.

RE: Portlet development: configuration updates only after refresh

Expert Beiträge: 289 Beitrittsdatum: 20.05.12 Neueste Beiträge
Dear All,

Kindly have a look at my response on below thread, Hope that helps.
https://www.liferay.com/community/forums/-/message_boards/message/47794047

Thanks,
Vishal