How to set Portlet Preferences via JavaScript - liferay

I am currently using ExtJS 3.4 to create the components of my portlet, and upon saving I wish to set the information into PortletPreferences. I understand how to set and get them via the Java code, but I am struggling to set and get the preferences via JavaScript.
I encode my JavaScript object by using Ext.encode(), but then I am stuck on saving that JSON String.
Any help is appreciated :)

Unless LifeRay provides an AJAX API to save portlet preferences you will need to create something similar yourself.
The serveResource method is there to help manage AJAX requests for portlets. You can send the portlet preferences you want saved to a resourceURL and process them serverside in the serveResource method.
That's the closest way you can save them via JavaScript. Otherwise the typical method is to submit a form to an ActionURL and save the preferences in a processAction method.

Related

Expose String to Velocity Theme in Liferay for Social Media Tags (Open Graph)

I would like to expose some Strings to the a velocity theme in the liferay framework in order to write some HTTP headers used for social network sharing. What is important is that my Controller has to put these Strings to the velocity theme during the render phase.
How can this be done please?
You can always create a custom hook and add custom variable that will be available in theme. Check this link http://www.opensourceforlife.com/2012/06/custom-velocity-variable-in-liferay-61.html
I think the utility class VelocityVariablesUtil should help you insert some variables or custom helper utilities to be accessed from the template (*.vm) file of theme.
You can use the insertVariables() method of this class in your controller to achieve what you need.
Let me know if this works.

Can' call XSP functions in XPINC

I try to call XSP._isDirty() for XPINC but it does not work. In the browser everything works fine. Is there a trick how i can use it.
Is there a way how i can see clientside errors when i'm executing XPages in the Notesclient?
Two questions here.
Q1. XSP._isDirty()
XSP._isDirty() is an internal call. From the XPages portable command guide (page 156).
XSP._isDirty() : Used internally by the Dirty Save feature— see the <xp:view> properties for enableModifiedFlag. This is a private function.
Code for this call is in the file xspClientDojo.js (look for the uncompressed file on Domino/Notes).
As it is an internal call it is used at risk. There is no guarantee it will work as expected in later versions.
The enableModifiedFlag is an XPage attribute that allows you to mark the page as dirty and prevent the user accidentally leaving the page. There are more details about this on the Infocenter.
Q2. Client side debugging.
You can review client side errors using the developer panel of most modern browsers, or something like the firebug plugin. The XPages extension library comes with a Firebug Lite component you can use as well.
For SSJS and XSP engine issues you can review these in the Notes client by reading the XPages logs in the IBM_TECHNICAL_SUPPORT folder contained in the Notes data folder.
For a "live" method of this is to modify the shortcut that launches notes as follows:
Target: C:\Lotus\Notes\notes.exe -RPARAMS -console -debug -separateSysLogFiles -consoleLog
Start In : C:\Lotus\Notes\framework\
Change the path to match your clients install.

call sharepoint 2010 webpart methods

I am creating a SharePoint site through visual studio and I created a user control(ascx).I have written some methods on user control code behind file(axcs.cs). How can I call those methods through jquery ajax since methods on ascx.cs cannot be called by jquery ajax directly? Could you please help me?
Actually you cannot call a control's server methods from javascript (jquery/ajax).
However, depending on the logic that needs to be called you have options. For one, you can create a *.ashx handler that will handle requests from you javascript code and call server-side logic.

Why does JSF process the entire form

We are developing web application using JSF. We are using rich faces on Jboss server. We have a4j command buttons , command links and a4j js functions to invoke server actions.
We have set limit render to true, render only required components. And I also set execute to "#this" . We are observing a strange behavior , All the actions associated with the form are also executed along with the button clicked, even though we have not specified the execute value to "#this". This is bringing down the performance drastically.
Is this the way JSF process POST requests or is there something else we are missing?
What you're currently describing in the question is definitely not the default behaviour of JSF nor RichFaces.
Your concrete problem is caused elsewhere. As per the comments, you seem to have created a PhaseListener for logging purposes which is re-executing the entire view for some reason. You'd need to turn off this PhaseListener or to fix its implementation.

Is there a way to have a JSF page automatically update a webpage when bean values change?

(Using JEE6) Is it possible to have a webpage automatically update (or listen) to values from within a bean/class and display them on the JSF when these changes happen?
As KayKay mentioned you can implement some sort of polling methodology using javascript to ask the server periodically to send updates if there are any. And unless you use ajax you will have to be content with only complete page refreshes.
JSF as good as it is, sits on top of basic stateless web technology. As such unless you use Ajax or some custom code the server will only respond to a request from the client. Some libraries like icefaces have incorporated a "push" component that allows what you are looking for (from what I understand, this is a fundamental part of icefaxes). That is, to push server side changes to the client.
You have to set up a listener on your end so that your bean will be notified when a value change happens on the server (like in your backing bean which is on the server). When the change happens you can ask say, 'icefaces push' (or another library like primefaces, which you indicate you don't want to use) to send a notice to the client. The client side code (usually ajax/javascript) will process the notice and then send a request for the whole object per normal request response. That is the notice tells the client something it's interested in changed so the client can ask for an update. Aside from the notice, still request/response.
I mention icefaces push because it seems to be the favoured library for this now. But others have this as well. I don't believe the standard JSF 2.0 AJAX libraries have this.
Here are a couple of resources to look at:
(The video is a good start to get the idea of what is going on, then use the rest of the site)
http://www.icesoft.org/demos/icepush-demos.jsf
Older but I think still relevant IBM tutorial on what you want to do, using inventory changes as an example:
http://www.ibm.com/developerworks/web/library/wa-aj-dynamic/index.html
And another stack question related:
Is there a better Ajax Push for JSF 2.0 than Icefaces
Unfortunately it looks like you cannot do this with just JSF, you will have to use one of these libraries or even harder, roll your own push mechanism.
I don't know of a JSF feature to do so. I would simply do some javascript polling, using for example jquery load method to refresh the parts of the page where the values are displayed.
It would help to know what you want to do : refresh the whole page when there is a change, update somes values that are displayed from the start, or add new values to the page.

Resources