Hit event on before every action in liferay means pre action event - liferay

I need to call the one method before action method calls in portlet controller.
So here I am using a hook like:
Create Hook
Create a class and extend Action.
Override run method write my own logic.
Create portal.properties file and added following line
servlet.service.events.pre=com.liferay.sample.hook.LoginAction
Pointing it fron liferay-hook.xml
Every thing was went fine but here the problem with this one is the created hook is executed each and every time page load but I want execute this hook is only when I click on the Action buttons(Action urls) in any portlet.
Can any help me out on it?
Thanks in Advance.
Naresh Kallamadi

The property you are using relates to service actions, which are invoked before or after every Action. From my experience service actions happens every time a page loads. This would explain the behavior you are seeing.
For more in-depth understanding, the article Overriding Events and working with preactions and postactions in EXT will help.
I think you may want to dig more into the portlet actions and phases to achieve what you may need. Please post back if you have more details (code example of what you have tried etc.) on the exact behavior in the portlet you need help with.
Hope this helps.

Related

How to add custom logging to TrackJS

I have a page redirect happening on a certain page that I need to watch for in an angular 5 app. I need to get the url while it is happening. How / Where can I add such things in TrackJs. Which API should I be using
You'll either need to instrument the destination page and log the referrer so that you know the source, or add a hook before navigation occurs and check the destination.
For a hook, you'll need to know how the navigation happens: either a click, form post, or window.open. For each of these, you can add an eventListener to look for the event and log.
You'll utilize the standard TrackJS API to track() a custom error when the right event occurs.

Orchard Dynamic Forms Workflow not invoked

I made a simple workflow in Orchard 1.9.1 to notify when a dynamic forms is submitted.
I didn't set any prpoperty/data on the Start Activity so that it can capture all Dynamic Forms submission. However there seems an issue and the workflow is NOT being invoked.
I followed steps from here: http://docs.orchardproject.net/Documentation/Workflows
But this notify activity or may be even the start activity doesn't seem to be invoked/working . What More settings are required to get this workflow in action ?
Also, I have set the redirect URL in "Forms" element properties but the form isn't redirecting. What can be the issue here as well ?
I have not seen this problem with a workflow before. I assume there's nothing in the logs?
My first guess would be that it's your form that is not submitting properly, try to remove that redirect, also make sure there's isn't some validation error blocking it, if you placed recaptcha element remove it and try again.
Second guess which is not very likely is that you have somehow managed to hide notification zone, either with CSS or in layout view #Zone(Model.Messages)

Liferay - Intermediate page after login and landing

I am looking to have two factor authentication. That is after login, i want to show an intermediate page. Only after some action has been done on the second page, user is taken to the landing page.
I have logic for second factor authentication ready. Its basically a jsp with some action.
However I am not sure what is the right approach to insert this intermediate page.
I have seen terms of use page, wherein the flag is maintained in db and the code is there in actual implementation class. I dont want to use extension plugin to do this. So I ruled out that option.
Second way is to have a Service Pre Action hook and do the necessary check here. But when I place the code in here, it goes to infinite loop.
Any other way I can do this? Hook is my preference.
Second way is to have a Service Pre Action hook and do the necessary
check here. But when I place the code in here, it goes to infinite
loop.
Not sure why this would happen, may be you would need to add a check or a flag which would execute your code only if the second tier authentication fails else it should just normally run the ServicePreAction code.
Another way I can think of is to use a custom struts-action to show your JSP and do the desired action in the custom action class.
Hope this helps.
I have not checked how to achieve that, but my guess is that extending the login portlet in a hook is the best way.
you can store the redirection url, redirect to the intermediate page and then load the stored url.
Regards.

How to avoid BusyConversationException in jsf

I'm getting BusyConversationException while navigating through pages in my jsf project. This mostly happens if the user tries to navigate to another page during an ajax call. This also happens when the user clicks on a link right after clicking on another link without waiting for loading of the page.
For example if the user clicks on more than one link which are generated through a code similar to below one we definitely get this exception. Another example is, lets say the user enter a query on a text field, and our application make an ajax call for searching this query. During that query if the user click on some button to navigate to another page BusyConversationException occurs too.
<h:commandLink value="#{theProfile.profileName}"
title="#{theProfile.profileName}"
action="#{profileBean.aProfileSelected}">
<f:setPropertyActionListener target="#{currentProfileWebBean.theProfile}" value="#{theProfile}"/>
</h:commandLink>
I can catch this type of exception in an ExceptionHandler class which extends ExceptionHandlerWrapper class but I can't save my current state and the best I can do for this case is to redirect to main page when this exception occurs.
Is there any solution for avoiding this? Thanks in advance for answers and comments.
As mentioned in the other answers, this happens if an ajax request is still being processed or if an ajax event is triggered prior to the actual click on the submitting commandLink or commandButton (for instance by a change event on an input field).
Therfore it is not possible to avoid BusyConversationExceptions with onclick="preventEventPropagation(event)";, since the AJAX events are not triggered via propagation.
The issue can easily be avoided by listening for running ajax requests and blocking submits until the pending ajax events have been completed.
The issue and solution are explained in more detail in this blog post JSF2 AJAX/Submit conversation issue.
i found this,
Indicates that the container has rejected a request because a concurrent request is associated with the same conversation context.
The container ensures that a long-running conversation may be associated with at most one request at a time, by blocking or rejecting concurrent requests. If the container rejects a request, it must associate the request with a new transient conversation and throw an exception of type BusyConversationException from the restore view phase of the JSF lifecycle.
refer here
I've been seeing this occasionally too. I'm starting to think it's a good idea to put some effort into serializing access to conversations:
Avoid propagating the conversation ID (cid) when you don't need that conversation instance for the target view. Specifically, unrelated navigation links/buttons should suppress the cid parameter (haven't thought about exactly how to do that)
When starting a request that uses an active conversation, disable other UI elements that propagate the conversation and could therefore cause concurrent access. The PrimeFaces or (even better) PrimeFaces Extensions blockUI components work well as a translucent overlay, along with a PrimeFaces p:ajaxStatus to show the busy status.
Begin conversations as late as possible. This will minimize the cases where a long-running conversation would be propagated.
I don't think that any of this is a complete solution, though. As soon as the cid ends up in the location bar (which happens when you do a non-ajax post back of a form when a conversation is active), you potentially lose control over the timing of access to that conversation due to multiple tabs/windows, bookmarks, etc.
I also faced the same problem, when I used to click the .
I have read in one of the book, busyConevrsation happens with that event two actions are happening, so they said use : onclick="preventEventPropagation(event)"; in commandLink to prevent the event propagation for that click. So I have used the same and it's working for me.
So now am not getting the BusyConversationException :)

How to pass a value to SharePoint list event receiver?

I have a SharePoint site page with a document library web part on it, once a document is uploaded to this library, some of the library fields need to be updated according to a parameter of the page url.
I tried doing this with Event Receiver binding on the library, only to find that I cannot get the page url, or rather the parameter, in the Event Receiver. Then Session occurred to my mind, but after asking around and searching a lot, I can only get HttpContext in itemAdding but not itemAdded, what's worse, HttpContext.Current.Session always give me nulll and I'm sure I have put some value into session earlier in somewhere else.
Can someone shed some light on this, any help or advise is deeply appreciated.
SharePoint allows synchronous and asynchronous event receivers. You can get access to HttpContext and SPContext in synchronous receiver, as it runs in worker thread. Read more for accessing HttpContext and how to bind synchronous receiver programmatically.
It's a bit late but for reference I've just seen solution on this page.
It leverages custom control in master page and stores the information into HttpRuntime.Cache. Then access it from within the synchronous event.
The event receiver is not called in the page context. Therefor you can't access the page information. The only approach to this that I can see is to write custom code that prefills the values of the page before you save the item.

Resources