Fórumok

Nyitólap » Liferay Portal » English » 3. Development

Kombinált nézet Egyszerű nézet Fa-nézet
Szálak [ Előző | Következő ]
toggle
Jean Gerard
Add new configuration tab
2012. június 15. 4:15
Válasz

Jean Gerard

Rangsorolás: New Member

Hozzászólások: 10

Csatlakozás dátuma: 2012. június 5.

Legújabb hozzászólások

Hello,
I'm searching how I can add a new configuration tab beside the permission and sharing tab.

I want a tab which can change values of a variable within my file conf.properties.

How can I do this?

Regards.
Anil T
RE: Add new configuration tab
2012. június 15. 7:05
Válasz

Anil T

Rangsorolás: Junior Member

Hozzászólások: 45

Csatlakozás dátuma: 2012. január 14.

Legújabb hozzászólások

Hi Jean,

You can add new configuration tab in the tabs1.jsp of html/portlet/portlet_configuration. Check this.
Riccardo Ferrari
RE: Add new configuration tab
2012. június 15. 8:01
Válasz

Riccardo Ferrari

Rangsorolás: Regular Member

Hozzászólások: 121

Csatlakozás dátuma: 2010. november 13.

Legújabb hozzászólások

Hi,

may this link will be useful:
http://www.liferay.com/community/wiki/-/wiki/Main/How+to+Add+Configuration+Page+to+a+Plugin+Portlet
Liferay configuration are a bit more complicated than plain EDIT mode, but offer lots of benefits

regards,
Riccardo
Jean Gerard
RE: Add new configuration tab
2012. június 17. 12:56
Válasz

Jean Gerard

Rangsorolás: New Member

Hozzászólások: 10

Csatlakozás dátuma: 2012. június 5.

Legújabb hozzászólások

So, if my custom portlet is already create, i had to do all of this, just for add a new tab in the conf menu (cf beside import/export and permissions)?

And, how i can do this :
had 2 input text to change 2 parameters in a conf.properties?

Thank you.
Riccardo Ferrari
RE: Add new configuration tab
2012. június 17. 13:11
Válasz

Riccardo Ferrari

Rangsorolás: Regular Member

Hozzászólások: 121

Csatlakozás dátuma: 2010. november 13.

Legújabb hozzászólások

Hi,

well it is not more complicated than creating page with a form available in EDIT mode of your portlet. Relaying on properties files is not so maintainable in my opinion, you should always set up a form to store portlet setting into PortletPreferences. A quick and dirty solution is to add EDIT mode support to your portlet, a much more Liferay's way solution would be to use the configuration mode.

Riccardo
Jean Gerard
RE: Add new configuration tab
2012. június 18. 1:31
Válasz

Jean Gerard

Rangsorolás: New Member

Hozzászólások: 10

Csatlakozás dátuma: 2012. június 5.

Legújabb hozzászólások

I'm am reading your link, but i don't understank how work his JSP.

Maybe it's me, but seems not very clear.

Plus, is it possible to imlements directly ConfigurationAction in my portlet controller? And simply complete implements method?

Thank you.
Amit Doshi
RE: Add new configuration tab
2012. június 18. 1:45
Válasz

Amit Doshi

Rangsorolás: Expert

Hozzászólások: 491

Csatlakozás dátuma: 2010. december 29.

Legújabb hozzászólások

Yes you can implements direclty in your custom portlet.

Add following line in liferay-portlet.xml inside the portlet tag.

<configuration-action-class>com.test.liferay.portlet.xyz.action.ConfigurationActionImpl</configuration-action-class>


And ConfigurationActionImpl will extend BaseConfigurationAction and in that Override render and ProcessAction according to your requirement.

And in the render method you should return the jsp page along with the path. So it will open your jsp page.

Hope its clear.

Regards,
Amit Doshi
Jean Gerard
RE: Add new configuration tab
2012. június 18. 2:17
Válasz

Jean Gerard

Rangsorolás: New Member

Hozzászólások: 10

Csatlakozás dátuma: 2012. június 5.

Legújabb hozzászólások

Ok, so the render, will return the jsp with the form i want, but what is this line :

1<portlet:defineObjects />


Is that permit that follow in the jsp?

How i choose the conf.properties that i want modify?Is it on the jsp?Or processAction?

Becuase in the processAction, i don't really see the links with the jsp. So, do it change or still always the same?

How my param enters in the form on jsp are really enters in my conf.propertis?

Sorry for so many questions, but I want to clarify all these stuffs.

Thank you.
Amit Doshi
RE: Add new configuration tab
2012. június 18. 2:53
Válasz

Amit Doshi

Rangsorolás: Expert

Hozzászólások: 491

Csatlakozás dátuma: 2010. december 29.

Legújabb hozzászólások

Ohh.. lots of Question in single post.......
So Going one by one.......


Ok, so the render, will return the jsp with the form i want, but what is this line :


In that you have to return the jsp page from the render method as below :-

1
2@Override
3    public String render(final PortletConfig portletConfig, final RenderRequest renderRequest, final RenderResponse renderResponse) throws Exception
4    {
5             ...............    
6               return "/html/asd/config.jsp" ; // path as per your jsp page.
7        }



<portlet:defineObjects />
Is that permit that follow in the jsp?


As in the normal jsp page there are 9 implict objects that we are able to use without declaring anywhere. In the same way by defining this properties we can use the portlet implicit objects.


How i choose the conf.properties that i want modify?Is it on the jsp?Or processAction?


Why you are using conf.properties ? I came accross this for the first time. what was the purpose for using conf.properties?

Becuase in the processAction, i don't really see the links with the jsp. So, do it change or still always the same?


In the processAction, do all the necessary operations like saving the preferences etc... and no need to specify any jsp page in that. After processing action, it will automatically call the render method and display your configuration jsp page. Please check the portlet lifecycle which will help you to understand in the better way.


How my param enters in the form on jsp are really enters in my conf.propertis?


why you want to add in the config.properties file ? you can save in the portlet preferences which liferay provides.

Regards,
Amit Doshi
Jean Gerard
RE: Add new configuration tab
2012. június 18. 3:14
Válasz

Jean Gerard

Rangsorolás: New Member

Hozzászólások: 10

Csatlakozás dátuma: 2012. június 5.

Legújabb hozzászólások

Why you are using conf.properties ? I came accross this for the first time. what was the purpose for using conf.properties?


Well, I'm using 2 variable in my portlet-conf.properties, those i want to change by administrate the portlet, like in this image

And i want, in a setup tab, when i change the parameters of one of the value, it changes the good parameters in my portlet-conf.properties, because i use them in my controller(for example, one of those two, load an external page that i use after.

1@Value("${portlet.mycustomportlet.config.url}")
2    public void seUrl(String conf) {
3        monUrl = conf;
4    }


So, i want for example, change from the setup tab the url i load, and that by changing my properties file, and then, keep the code with my methode setUrl.

I hope i'm clear.

Thank you
Amit Doshi
RE: Add new configuration tab
2012. június 18. 3:19
Válasz

Amit Doshi

Rangsorolás: Expert

Hozzászólások: 491

Csatlakozás dátuma: 2010. december 29.

Legújabb hozzászólások

Jean Gerard:
Why you are using conf.properties ? I came accross this for the first time. what was the purpose for using conf.properties?


Well, I'm using 2 variable in my portlet-conf.properties, those i want to change by administrate the portlet, like in this image

And i want, in a setup tab, when i change the parameters of one of the value, it changes the good parameters in my portlet-conf.properties, because i use them in my controller(for example, one of those two, load an external page that i use after.

1@Value("${portlet.mycustomportlet.config.url}")
2    public void seUrl(String conf) {
3        monUrl = conf;
4    }


So, i want for example, change from the setup tab the url i load, and that by changing my properties file, and then, keep the code with my methode setUrl.

I hope i'm clear.

Thank you


Instead of doing all this stuff, store directly in the Portlet Preferences.
Jean Gerard
RE: Add new configuration tab
2012. június 18. 5:31
Válasz

Jean Gerard

Rangsorolás: New Member

Hozzászólások: 10

Csatlakozás dátuma: 2012. június 5.

Legújabb hozzászólások

But so, how can i do this in your way?

1@Value("${portlet.mycustomportlet.config.url}")
2    public void seUrl(String conf) {
3        monUrl = conf;
4    }



Add following line in liferay-portlet.xml inside the portlet tag.

<configuration-action-class>com.test.liferay.portlet.xyz.action.ConfigurationActionImpl</configuration-action-class>


So, i have this in my liferay-portlet.xml :

1    <portlet>
2        <portlet-name>My portlet</portlet-name>
3        <control-panel-entry-category>My portletPage</control-panel-entry-category>
4        <configuration-action-class>path</configuration-action-class>
5        <instanceable>true</instanceable>
6        <private-request-attributes>false</private-request-attributes>
7        <private-session-attributes>false</private-session-attributes>
8    </portlet>


where path is :
package where my class is : com.ent.portlets.
name of portlet : myportlet.
and action.ConfigurationActionImpl (i also tried with my classname)

so : com.ent.portlets.myportlet.action.ConfigurationActionImpl

and my class is like :
public class myportlet extends BaseConfigurationAction implements ConfigurationAction{}

But i have this error message :
This portlet has been undeployed. Please redeploy it or remove it from the page.


Also, a question with your way. If i undertand, it will appears an option "preferences" for this portlet, and redicrect me on my jsp when i will click on "preferences"?And when i will save, register this parameter. Right?
Amit Doshi
RE: Add new configuration tab
2012. június 18. 23:24
Válasz

Amit Doshi

Rangsorolás: Expert

Hozzászólások: 491

Csatlakozás dátuma: 2010. december 29.

Legújabb hozzászólások


But so, how can i do this in your way?

1@Value("${portlet.mycustomportlet.config.url}")
2    public void seUrl(String conf) {
3        monUrl = conf;
4    }



No need to do any such things don't make the things complicated,

In the Jsp page do as below configurations.

 1
 2<form action="<liferay-portlet:actionURL portletConfiguration="true" />" method="post" name="<portlet:namespace />fm">
 3
 4<div id="test">
 5<UL>
 6   
 7    <li><input type="text" name="test" />test</li>
 8   
 9    </UL>
10    </div>
11    <input name="save" type="submit" value="Save">
12    </form>

In the jsp page <liferay-portlet:actionURL portletConfiguration="true" /> , it will tell the portlet to call the action for the Configuration. No need to mention any url the way u mentioned.

And in the ConfigurationImpl do as below :-

 1
 2public class ConfigurationActionImpl extends BaseConfigurationAction
 3{
 4       @Override
 5    public void processAction(final PortletConfig portletConfig, final ActionRequest actionRequest, final ActionResponse actionResponse) throws Exception
 6    {
 7                final String test= ParamUtil.getString(actionRequest, "test"); // you will get the text box value in the test
 8        }
 9}



Also, a question with your way. If i undertand, it will appears an option "preferences" for this portlet, and redicrect me on my jsp when i will click on "preferences"?And when i will save, register this parameter. Right?


Liferay don't do any automation for saving your preferences value. you need to write code in the processAction as below for saving value in the preferences.
1
2
3final PortletPreferences portletPreferences = PortletPreferencesFactoryUtil.getPortletSetup(actionRequest, portletResource);
4
5        portletPreferences.setValue("test", test);
6        portletPreferences.store();


Hope now its clear.

Regards,
Amit Doshi
Jean Gerard
RE: Add new configuration tab
2012. június 20. 5:22
Válasz

Jean Gerard

Rangsorolás: New Member

Hozzászólások: 10

Csatlakozás dátuma: 2012. június 5.

Legújabb hozzászólások

Ok, my conf.jsp and ConfigurationActionImpl works fine

I am trying to get the value in my controller.

How can i have default preferences, and how can i use preferences in my portlet then?

Thank you Amit
Amit Doshi
RE: Add new configuration tab
2012. június 20. 7:28
Válasz

Amit Doshi

Rangsorolás: Expert

Hozzászólások: 491

Csatlakozás dátuma: 2010. december 29.

Legújabb hozzászólások

I am trying to get the value in my controller.

Please check the below code for getting value into the controller
1final String test= ParamUtil.getString(actionRequest, "test");


How can i have default preferences, and how can i use preferences in my portlet then?


When the first time page load you don't have any preference set over there. So you can put below code in the render method

1
2PortletPreferences portletPreferences  = PortletPreferencesFactoryUtil.getPortletSetup(renderRequest, portletResource);
3            final String test= portletPreferences.getValue("test","defaultValue"); // no value found then it will take defaultValue what you have entered.


Regards,
Amit Doshi
Jean Gerard
RE: Add new configuration tab
2012. június 21. 4:23
Válasz

Jean Gerard

Rangsorolás: New Member

Hozzászólások: 10

Csatlakozás dátuma: 2012. június 5.

Legújabb hozzászólások

I have done what i want to do, and works fine, except the default value.

I saw that i had to add your lines into the render, but, where is define default value for first load?

If possible, have the value default, when i add a new portlet in a page.

Is it possible to load actual preferences in he form when we open conf tab?
And also keep value in the form when we validate?

And then, this :

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


I was thinking this just display a message when the form is validate, but if i remove it, then, the form can't be validate.

I don't understand how it works.

And thanks again for your great help Amit.