Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
Add User (Create Account) Customization
Hello Friends,
I am using Liferay 7.2.
I have added few new field in Add User page and for creation of account. I want to fetch those fields in to class.
For that I have implemented MVCActionCommand hook for User Account customization.
Issues : When I am creating a new user my class is not calling.
Following is my code
import com.liferay.login.web.internal.constants.LoginPortletKeys;
import com.liferay.portal.kernel.portlet.bridges.mvc.BaseMVCActionCommand;
import com.liferay.portal.kernel.portlet.bridges.mvc.MVCActionCommand;import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;/**
* @author nirav.prajapati
*/
@Component(
property = {
"javax.portlet.name="+LoginPortletKeys.FAST_LOGIN,
"javax.portlet.name="+LoginPortletKeys.LOGIN,
"mvc.command.name=/login/create_account",
"service.ranking:Integer=100"
},
service = MVCActionCommand.class
)public class CustomCreateAccountMVCActionCommandPortlet extends BaseMVCActionCommand { @Override
protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
// TODO Auto-generated method stub
System.out.println("Inside Hook");
mvcActionCommand.processAction(actionRequest, actionResponse); // it process existing logic
}
@Reference(
target = "(component.name=com.liferay.login.web.internal.portlet.action.CreateAccountMVCActionCommand)"
) protected MVCActionCommand mvcActionCommand;
}
Please help me with it.
Thanks
I am using Liferay 7.2.
I have added few new field in Add User page and for creation of account. I want to fetch those fields in to class.
For that I have implemented MVCActionCommand hook for User Account customization.
Issues : When I am creating a new user my class is not calling.
Following is my code
import com.liferay.login.web.internal.constants.LoginPortletKeys;
import com.liferay.portal.kernel.portlet.bridges.mvc.BaseMVCActionCommand;
import com.liferay.portal.kernel.portlet.bridges.mvc.MVCActionCommand;import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;/**
* @author nirav.prajapati
*/
@Component(
property = {
"javax.portlet.name="+LoginPortletKeys.FAST_LOGIN,
"javax.portlet.name="+LoginPortletKeys.LOGIN,
"mvc.command.name=/login/create_account",
"service.ranking:Integer=100"
},
service = MVCActionCommand.class
)public class CustomCreateAccountMVCActionCommandPortlet extends BaseMVCActionCommand { @Override
protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
// TODO Auto-generated method stub
System.out.println("Inside Hook");
mvcActionCommand.processAction(actionRequest, actionResponse); // it process existing logic
}
@Reference(
target = "(component.name=com.liferay.login.web.internal.portlet.action.CreateAccountMVCActionCommand)"
) protected MVCActionCommand mvcActionCommand;
}
Please help me with it.
Thanks
Hi Nirav,
When you say your class is not being called, do you mean that your custom MVCActionCommand that you are using to override it is not working? If that is the case then there are two things I would check. First I would try adding "immediate=true" to the component annotation -- I believe by default it is actually false, and this has bitten me a few times.
If that doesn't work, then I would next go into the gogo shell and run scr:info <your package>.CustomCreateAccountMVCActionCommandPortlet and look at the output. I am wondering if perhaps the issue is with the @Reference to the original command .. issue being that it can't satisfy it. So if it can't satisfy the reference, which is not optional (by default it is MANDATORY) then the component won't start (even if the module has)
When you say your class is not being called, do you mean that your custom MVCActionCommand that you are using to override it is not working? If that is the case then there are two things I would check. First I would try adding "immediate=true" to the component annotation -- I believe by default it is actually false, and this has bitten me a few times.
If that doesn't work, then I would next go into the gogo shell and run scr:info <your package>.CustomCreateAccountMVCActionCommandPortlet and look at the output. I am wondering if perhaps the issue is with the @Reference to the original command .. issue being that it can't satisfy it. So if it can't satisfy the reference, which is not optional (by default it is MANDATORY) then the component won't start (even if the module has)
Hi Andrew,
I have tried with immediate = true in component, but it's also not working. I have run the script : info com.nec.user.portlet.CustomCreateAccountMVCActionCommand in gogo shell.
Following is the output.
Output
Please let me know how can I resolve it?
Thanks
I have tried with immediate = true in component, but it's also not working. I have run the script : info com.nec.user.portlet.CustomCreateAccountMVCActionCommand in gogo shell.
Following is the output.
Output
Component Description: com.nec.user.portlet.CustomCreateAccountMVCActionCommand
===============================================================================
Class: com.nec.user.portlet.CustomCreateAccountMVCActionCommand
Bundle: 1167 (hook-user-action:1.0.0)
Enabled: true
Immediate: true
Services: [com.liferay.portal.kernel.portlet.bridges.mvc.MVCActionCommand]
Scope: singleton
Config PID(s): [com.nec.user.portlet.CustomCreateAccountMVCActionCommand], Policy: optional
Base Props: (4 entries)
javax.portlet.name = [com_liferay_login_web_portlet_FastLoginPortlet, com_liferay_login_web_portlet_LoginPortlet]
mvc.command.name = /login/create_account
mvcActionCommand.target = (component.name=com.liferay.login.web.internal.portlet.action.CreateAccountMVCActionCommand)
service.ranking = 300
Component Configuration Id: 5116
--------------------------------
State: ACTIVE
Service: 11100 [com.liferay.portal.kernel.portlet.bridges.mvc.MVCActionCommand]
Used by bundle 0 (org.eclipse.osgi:3.13.0.LIFERAY-PATCHED-5)
Config Props: (6 entries)
component.id = 5116
component.name = com.nec.user.portlet.CustomCreateAccountMVCActionCommand
javax.portlet.name = [com_liferay_login_web_portlet_FastLoginPortlet, com_liferay_login_web_portlet_LoginPortlet]
mvc.command.name = /login/create_account
mvcActionCommand.target = (component.name=com.liferay.login.web.internal.portlet.action.CreateAccountMVCActionCommand)
service.ranking = 300
References: (total 1)
- mvcActionCommand: com.liferay.portal.kernel.portlet.bridges.mvc.MVCActionCommand SATISFIED 1..1 static
target=(component.name=com.liferay.login.web.internal.portlet.action.CreateAccountMVCActionCommand) scope=bundle (1 binding):
* Bound to [4178] from bundle 530 (com.liferay.login.web:4.0.8)Please let me know how can I resolve it?
Thanks
Hi Nirav,
Actually that output looks fine. Are you able to zip up the entire module and send it over to me so I can try it on my side? can you also tell me specifically which version of Liferay you are working with?
Actually that output looks fine. Are you able to zip up the entire module and send it over to me so I can try it on my side? can you also tell me specifically which version of Liferay you are working with?
Hi Andrew,
I am using liferay-dxp-7.2.10-ga1 version. It's a pretty simple module project. In that I have change the portlet class only, instead of extends MVCPortlet I have make it as BaseMVCActionCommand .
In that whole module project I have only one class . Nothing any more.
I am using liferay-dxp-7.2.10-ga1 version. It's a pretty simple module project. In that I have change the portlet class only, instead of extends MVCPortlet I have make it as BaseMVCActionCommand .
In that whole module project I have only one class . Nothing any more.
Hi Nirav,
I created a module with nothing more than the override on my side and it seems to be working without issue. One difference is that I used the API template from BLADE, not the MVC Portlet one -- but I think the only real difference there is that I have to add the dependencies for kernel and portlet as well as the login web myself. I also changed the name of the class (removing the Portlet suffix -- since it's not a portlet, it's just an MVCActionCommand), but again, I don't see how that matters. I've attached my project to this message. Does it work in your 7.2 environment?
I created a module with nothing more than the override on my side and it seems to be working without issue. One difference is that I used the API template from BLADE, not the MVC Portlet one -- but I think the only real difference there is that I have to add the dependencies for kernel and portlet as well as the login web myself. I also changed the name of the class (removing the Portlet suffix -- since it's not a portlet, it's just an MVCActionCommand), but again, I don't see how that matters. I've attached my project to this message. Does it work in your 7.2 environment?
Attachments:
Hi Andrew,
I have run your zip file, but unfortunately it's also not working in 7.2.
I have attached my code also.
I have run your zip file, but unfortunately it's also not working in 7.2.
I have attached my code also.
Attachments:
Ok, in that case there is something whacky with your environment. I build this sample on a vanilla 7.2 GA1 Liferay workspace -- and it worked for me.
Can you try with a new install to see if that makes a difference? I would also make sure that you are working with the lastest blade version ($>blade update .. on the command line in case you are not familiar) and that your Liferay workspace version is fairly recent. My Liferay workspace config (settings.gradle) looks like this --
Can you try with a new install to see if that makes a difference? I would also make sure that you are working with the lastest blade version ($>blade update .. on the command line in case you are not familiar) and that your Liferay workspace version is fairly recent. My Liferay workspace config (settings.gradle) looks like this --
buildscript {
dependencies {
classpath(group: "com.liferay", name: "com.liferay.gradle.plugins.workspace", version: "2.1.10") {
exclude group: "biz.aQute.bnd", module: "biz.aQute.bnd"
exclude group: "biz.aQute.bnd", module: "biz.aQute.bnd.gradle"
exclude group: "biz.aQute.bnd", module: "biz.aQute.repository"
exclude group: "biz.aQute.bnd", module: "biz.aQute.resolve"
}
classpath group: "biz.aQute.bnd", name: "biz.aQute.bnd", version: "3.5.0"
classpath group: "biz.aQute.bnd", name: "biz.aQute.bnd.gradle", version: "3.5.0"
}
repositories {
maven {
url "https://repository-cdn.liferay.com/nexus/content/groups/public"
}
}
}
apply plugin: "com.liferay.workspace"
Hi Andrew,
It's Resolved.Thanks You So Much.
It's Resolved.Thanks You So Much.
Great! Glad to hear you got it all worked out. In the end, what was the problem? It's always best to share incase someone else experiencing this same issue in the future comes across this thread.
Hi Andrew,
I was trying to make a hook for (Add User) Create Account. But my question was not proper.
Actually, Add User and Create Account are two different things in liferay.
Create Account : This option is available on Log in portlet
Add User : Control Panel > User and Organization > Add USer (+)
My Account : After login
The following are the classes for customization for it
Create Account : com.liferay.login.web.internal.portlet.action.CreateAccountMVCActionCommand
Add User or Edit User : com.liferay.users.admin.web.internal.portlet.action.EditUserMVCActionCommand
My Account : com.liferay.users.admin.web.internal.portlet.action.EditUserMyAccountMVCActionCommand
Thank You so much Andrew for your kind help..!!!
I was trying to make a hook for (Add User) Create Account. But my question was not proper.
Actually, Add User and Create Account are two different things in liferay.
Create Account : This option is available on Log in portlet
Add User : Control Panel > User and Organization > Add USer (+)
My Account : After login
The following are the classes for customization for it
Create Account : com.liferay.login.web.internal.portlet.action.CreateAccountMVCActionCommand
Add User or Edit User : com.liferay.users.admin.web.internal.portlet.action.EditUserMVCActionCommand
My Account : com.liferay.users.admin.web.internal.portlet.action.EditUserMyAccountMVCActionCommand
Thank You so much Andrew for your kind help..!!!
Haha -- that makes more sense now
. Yes, it can be tricky sometimes to get around the nomenclature that Liferay uses. For future reference, in case you are not aware, you can look up a file called struts-config.xml in the Liferay source and find all the mappings (that you would see in the portlet) and associated Class mappings.
Now, will all this said, at this point I would normally ask WHAT it is that you are trying to alter/add into the action. The reason I say this is because if there is something that you need to happen when a user is created, regardless of context, then altering the Action itself is not the best option. The reason I say this is because there is more than one avenue that can be used in the portal to create a user -- as you have seen on this thread in fact. Even if you covered all actions in place today, there would still be the risk of something new being added to the portal in the future (that you have not covered) or something custom that someone builds (also not covered by your work).
If you need your requirement to be enforced in all cases where a user account is created you are better to use a server wrapper and override the UserLocalServiceImpl#addUserWIthWorkflow method, or alternatively if what you are doing has to do with something "related" to the user, then you might be best to use a Model Listener on the for the User model.
If you can share with me what it is you are trying to do exactly, (your requirements) then I might be able to help you decide on the most future proof direction.
Now, will all this said, at this point I would normally ask WHAT it is that you are trying to alter/add into the action. The reason I say this is because if there is something that you need to happen when a user is created, regardless of context, then altering the Action itself is not the best option. The reason I say this is because there is more than one avenue that can be used in the portal to create a user -- as you have seen on this thread in fact. Even if you covered all actions in place today, there would still be the risk of something new being added to the portal in the future (that you have not covered) or something custom that someone builds (also not covered by your work).
If you need your requirement to be enforced in all cases where a user account is created you are better to use a server wrapper and override the UserLocalServiceImpl#addUserWIthWorkflow method, or alternatively if what you are doing has to do with something "related" to the user, then you might be best to use a Model Listener on the for the User model.
If you can share with me what it is you are trying to do exactly, (your requirements) then I might be able to help you decide on the most future proof direction.
Hi Andrew,
Thank you for your help and support.
I will inform you on that.
Thank you for your help and support.
I will inform you on that.