Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Gnaniyar Zubair
Custom Attributes for Registration
February 9, 2013 6:15 AM
Answer

Gnaniyar Zubair

Rank: Liferay Master

Posts: 603

Join Date: December 19, 2007

Recent Posts

Hi,

I am extending Liferay user services by adding some extra fields through Custom attributes. I dont wanna display custom attribute tag in create_account.jsp as those fields are hidden fields. So, I have set as hidden through control panel UI.

Now while Registering the account, i need to send the custom attributes values as a hidden field. from create_account.jsp to action file and store into database . Here my requirement is, I need to store those custom attribute hidden values into expando tables for particular user using HOOK plugin not using EXT plugin.

There are different ways of Hook trial and my analysis.

1. STRUTS HOOK

Using Struts Hook :


I am overriding processAction method by extending BaseStrutsPortletAction .
but i dont have user object as this is the register mode not login mode. So cant store into expando table for the particular user without user object :

1public void processAction(StrutsPortletAction originalStrutsPortletAction,
2        PortletConfig portletConfig, ActionRequest actionRequest,
3        ActionResponse actionResponse) throws Exception {
4
5               // i cannot use registered user object here like this
6             // user.getExpandoBridge().setAttribute("MY-CUSTOM-FIELD", "custom-field-value");
7}



2.SERVICE HOOK

I can try Service Hook which extends UserLocalServiceWrapper class:


But problem is, here i cannot get request object .

public User addUser(blah,blah......etc - user fields ) {}


So cant get my hidden custom field value from create_account.jsp like this as request object is not available :

ParamUtil.getString(portletRequest, "Form-Field-Name");


3.Model Listener Hook [ Property Hook ]

Using Model Listener :


Here also we can extend the functionality using onAfterCreate method. request object will not be available.
So no use of Listerner hook

4.EVENT HOOK

No event hook would match for this requirement as I need to extend the user service while registering the account not Post / Pre events of any service.


So, I can achieve only through EXT by extending the CreateAccountAction class. Is there any other way to achieve above requirement using HOOK ?
Gnaniyar Zubair
RE: Custom Attributes for Registration
February 10, 2013 2:07 AM
Answer

Gnaniyar Zubair

Rank: Liferay Master

Posts: 603

Join Date: December 19, 2007

Recent Posts

Finally I have done through Struts Hook. But Hidden Custom Attribute field and setting value has done from JSP level.

As We cannot change the custom attribute field as a hidden mode in jsp page level using liferay tag, i tried like this :

<liferay-ui:custom-attribute className="<%=User.class.getName() %>" classPK="<%= 0 %>" editable="true" label="false" name="Account Type"></liferay-ui:custom-attribute>

I made the label attribute as false. Then Label name will not display only text box will appear to enter the value. Then thorugh jQuery i have made it as hidden and setting the value into that field through script. That's it.

$("input[id*='Account Type']").hide();

$("input[id*='Account Type']").val('SOME_VALUE');


So that particular field will be available in jsp page as hidden mode . No need to worry to receive the custom attribute in hook/ext plugin and storing into expando table as it is the default behavior.

But Liferay should consider to add one more attribute in Liferay-ui custom attribute tag like "hidden" in next version.


- Gnaniyar Zubair