Prevent duplicate form submission in liferay - liferay

I am facing the problem of duplicate form submission.
I kept <action-url-redirect>true</action-url-redirect> in liferay-portlet.xml.
My portlet gets hanged up and I am not able to perform any action.
I am using Liferay MVC portlet. Any solution apart from redirect.

Related

ViewExpiredException: View could not be restored when user is logged in again

My web app is built on spring boot + spring security + JSF 2.2.12
I have read a lot of posts about the view expired exception, and try to solve it using this proposal.
To be shortly, I have added ?faces-redirect=true to my action methods, added NoCacheFilter to inform browser not cache the dynamic JSF pages. Also I have add expired.xhtml page. Also, I have added custom InvalidSessionStrategy implementation using this sample.
For the case, when I have two tabs in my browser, and perform log out in one tab, and in other I click <p:commandButton which trigger POST request for page navigation, everything works fine, browser redirect me to the login page.
But for case, when I have two tabs in my browser, and in one tab I perform log out and then log in, and in other I click again <p:commandButton, the ViewExpiredException is thrown.
Please, help me to solve this issue. Or tell me what I have missed?

Why can't the login page for form-based authentication be written in JSF?

I'm just starting down the track of developing web apps and have started with JSF 2.2 on Java EE 7, GlassFish 4.
I thought I'd start with the very basics. I just want to protect the entire site, so every page you navigate to would first require you to authenticate yourself. So I read through the Java EE 7 Tutorial and tried the samples, modified them and then started to break them in ways I didn't think they would break. I tried all sorts of angles, but I'd generally end up in two situations:
I'd try to access a page using a partial request, which would land me at /index.xhtml as defined by <welcome-file-list>, and be prompted to login; but on submitting the username/password I'd be instantly directed back to the login form.
I added an action to the <h:commandButton> to point to index. This worked, but when I submitted the form on the index page which should take me to the response.xhtml page, I'd end up back at the login form instead of at the response page.
After many hours of trawling the net, it seemed that the reason I had broken the login procedure was because I had changed the plain HTML login form to use JSF tags like <h:form>, instead of <form>.
There is a discussion here that says you should not do this with login forms. To quote an interesting line from that page:
To make such a page login, make the actual login form be HTML and not JSF and code it according to the j2EE standards for login forms. Use the HTML form tag instead of the JSF form, and make sure you code an HTML SUBMIT button and not a JSF commandButton!
Once I changed it back to plain old HTML it worked. But I don't understand why. Can anyone enlighten me?! I think I am missing something fundamental which I need to understand if I'm going to start writing web apps in JSF.
Many thanks...
It's because <h:form> submits to the current URL (in web development terms also known as "postback"), not to j_security_check, while the form based authentication intercepts on j_security_check URLs.
It's however not true that using a JSF form for form based authentication is impossible. It's quite possible, you only need to perform the login in backing bean using HttpServletRequest#login() yourself.
See also:
Performing user authentication in Java EE / JSF using j_security_check

Liferay Login page JSP name

Once the Liferay Start Up page is displayed , there is a Sign-in Hyperlink , and once we click on that Sign-in Hyperlink it will take us to the Page where it will display the actual Login page.
What is the name of that JSP page (The Actual page with Email, Password and the Submit Button)?
I am using Liferay 6.1.
If you are thinking of modifying any JSP which is already there in liferay, consider modifying using hooks so that you dont have to restart liferay server since hooks are hot-deployable and easy to manage.
To learn more about hooks follow this link. http://www.liferay.com/documentation/liferay-portal/6.1/development/-/ai/hoo-4
The login link call login portlet. But you can change default login page, add to portal-ext.properties auth.login.url=mypageurl.
If what you want to do in your new login page is to add new fields then using Liferay custom fields will be the way go. You can define custom fields for User and make them editable and then add the into the login.jsp file using this tag
<div class="exp-ctrl-holder">
<liferay-ui:custom-attribute
className="<%=User.class.getName()%>"
classPK="<%=0%>"
editable="<%=true%>"
label="<%=true%>"
name="FieldName" />
</div>
This edit should be done using a hook
or
if you want to add additional logic to the login action then using the Liferay Extension environment is the best solution.

Liferay 6: How to custom display Portals On Successful login

I am using Liferay 6 for development .
I have developed a Custom Login Portlet using Struts2 .
I am able to display my Custom Login page , On click of the Submit Button after validating the credentials aganist our MYSQL Databse , please tell me how can i display my 4 other Custom Portlets on entering valid credentials ??
please guide me what is the concept i should refer for this in liferay
( I am using Liferay 6 for development )
Okay, the way I would suggest you do this is by:
adding the 4 other portlets to your Custom Login page (or add a redirect on successful login, and them to the page you redirect to)
Set the permissions of your Custom Portlets to be viewable by only authenticated users. This can be done by removing Guest "View" permissions. This way a non-authenticated user or "Guest" won't see your portlets when the go to the page.
Does this answer your question?
~~ EDIT IN RESPONSE TO COMMENT ~~
Okay, so if you're using Struts, instead of redirecting to a JSP file, you want to redirect to a URL instead. So instead of /view/result.jsp it should be something like http://yoursite.com/page_with_4_portlets_on_it or just a relative URL /page_with_4_portlets_on_it (if the two pages are on the same Navigation level.
HOWEVER:
If you're new to Liferay then I would strongly suggest you use Liferay's inbuilt Portlet architecture using their MVCPortlet class. This will handle all the mappings, and workings that you have to manually write for using Struts. Then you can implement a doPost() method and do a ActionResponse.sendRedirect("/page_with_4_portlets_on_it");
Then this means that when your form action completes Liferay will redirect the user to the page you've specified.
The best place to get started with Liferay 6 portlets, the Liferay way is here.

How can I make Liferay login portlet redirect to maximized version to display validation errors?

I've got a theme which has a login portlet embedded in the header and I dont wish for validation messages to appear on this login portlet, instead I want Liferay to redirect to the maximized version of the login portlet with the validation errors.
Is there any easy way to do this through the Velocity template files?
The best workaround I can come up with is to hardcode a HTML form which posts to the login struts action which seems to show validation errors on a maximized loging portlet
Thank you
I don't believe Liferay 6.0 has the capability to overwrite portlet code using a VM. It is, however, a new feature in the upcoming 6.1 release.
But if you're tied into Liferay 6.0, you may create a hook plugin to tackle this problem.
Create a hook plugin.
In your hook.xml define:
<hook>
<custom-jsp-dir>/META-INF/custom_jsps</custom-jsp-dir>
</hook>
In copy the original login.jsp from Liferay Portal to /META-INF/custom_jsps/html/portlet/login.jsp.
You'll want to modify the form action's URL to have window state maximized. You can do so by adding the windowState attribute to the tag lib that generates the URL. For Example:
<portlet:actionURL windowState="<%= LiferayWindowState.MAXIMIZED.toString() %>" />
After deploying this hook plugin, the logins should go to a maximized state unless redirected by a successful login.

Resources