stackoverflow user
stackoverflow user

Reputation: 313

How to fetch UserId of the User submitting the form

I am using Liferay 6.1.1.

I have created a portlet with <aui:form> having two text fields and a button.

On submit I want to know the userId who submitted the below form:

<aui:form action="<%=myUrl%>" method="post">
    <aui:input type="text" name="name"></aui:input>
    <aui:input type="text" name="addr"></aui:input>

    <aui:button type="submit" value="save"></aui:button>
</aui:form>

How can I get the userId?

Upvotes: 0

Views: 408

Answers (4)

Pandey
Pandey

Reputation: 1

On your java code use,

get ThemeDisplay from the request(actionRequest) and get userid from themeDisplay.getUserId()

Upvotes: 0

Jennis Vaishnav
Jennis Vaishnav

Reputation: 341

Type this in your java code:

String userId=ParamUtil.getString(portletRequest, param);

Upvotes: 0

yannicuLar
yannicuLar

Reputation: 3133

You can use the PortalUtil. On the Controler side :

User user = PortalUtil.getUser(actionRequest)

in your jsp :

User user = PortalUtil.getUser(renderRequest);

Don't forget to handle exceptions, or user being not null.

Upvotes: 0

Rasabihari Kumar
Rasabihari Kumar

Reputation: 491

I hope the Users are login into your portal before you show them this form.

If yes than you can look at the answers of this question which show a JSR-286 specific way and a liferay specific way to get the UserId.

And if you are showing this form and letting guest users i.e. any anonymous person to submit this form, then obviously you can't get the UserId.

Upvotes: 1

Related Questions