How to pass a parameter through to a Rest Service in Xpages - rest

XPages Dojo Data Grid and Custom REST Service
*** Note: Mine is an XPINC application!
I've managed to get the above method working, but I want to pass a parameter through to the Rest Service in order to build a better return set.
In the above example it the script looks like this:
<script>
var jsonStore = new dojo.store.JsonRest(
{target:"CURRENT_PAGE_NAME_HERE.xsp/gridData"}
);
var dataStore = dojo.data.ObjectStore({objectStore: jsonStore});
</script>
But, I want to do something like this:
<script>
var jsonStore = new dojo.store.JsonRest(
{target:"CURRENT_PAGE_NAME_HERE.xsp/gridData?OpenXpage&para1=Value1&para2=Value2"}
);
var dataStore = dojo.data.ObjectStore({objectStore: jsonStore});
</script>
I've tried a number of methods, but no success.
Method 1 - Use Request/View/SessionScope variable
On the "CURRENT_PAGE_NAME_HERE.xsp" I've added a "xp:this.beforePageLoad" event to create Scope variable to hold para1 and para2 taken from the paramValues of the URL.
I thought a simple requestScope would store them so I could pick them up when the "CURRENT_PAGE_NAME_HERE.xsp/gridData" was called. However, the Rest Service is called in the "onClientLoad" event of the page and the Scope variables don't seem to be available at this time.
Method 2 - Inline Javascript
I've also tried "${javascript:viewScope.para1;}" to pass it through:
<script>
var jsonStore = new dojo.store.JsonRest(
{target:"CURRENT_PAGE_NAME_HERE.xsp/gridData?OpenXpage&para1=${javascript:viewScope.para1;}&para2=${javascript:viewScope.para2;}"}
);
var dataStore = dojo.data.ObjectStore({objectStore: jsonStore});
</script>
This didn't work.
Method 3 - Hardcoding
I have hardcoded the values.
<script>
var jsonStore = new dojo.store.JsonRest(
{target:"CURRENT_PAGE_NAME_HERE.xsp/gridData?OpenXpage&para1=Apples&para2=Oringes"}
);
var dataStore = dojo.data.ObjectStore({objectStore: jsonStore});
</script>
This works! But, only for Apples & Oranges
I'm starting to look at using an Environment Variable to pass the values, but this just seems to be more of a hack than a solution.
Any help or guidance would be appriciated.

Dan,
You may have a couple of things to check.
First thing is that you need to use # instead of $ to avoid
evaluating the expression on page load
In some cases you cannot inject SSJS into the CSJS - if this is "evaluated" at page load time. You could be hitting this.... An easy
way to check is to create a couple of local variables and assign the
values from your SSJS. That'll make it easy to debug in the browser.
I guess you could do something like this (and then you can set a breakpoint in your browser and see if the values are as expected).
<script>
var p1 = "#{javascript:viewScope.para1;}";
var p2 = "#{javascript:viewScope.para2;}";
var jsonStore = new dojo.store.JsonRest(
{target:"CURRENT_PAGE_NAME_HERE.xsp/gridData?OpenXpage&para1=" + p1 + "&para2=" + p2}
);
var dataStore = dojo.data.ObjectStore({objectStore: jsonStore});
</script>
If this does not work then I suggest creating a script block in the beginning of your page with a simple little "getter" method for each variable (or the entire arg. string) and then use the SSJS there.
Happy coding!
/John

As this is an XPINC appplication, I felt it was safe to just use an Environment Variable.
On the view action button that calls the XPage, I write the Environment variable down onto the system. Then when I open the Xpage in the client, the Rest Service is hardwired to:
var param1:String = session.getEnvironmentString("Param!");
I still think this feels more like a hack, but with Notes, I'm getting used to it. LOL

Related

syncfusion ej grid javascript method

I am very new to syncfusion controls for mvc. While exploring how to set dynamic datasource to grid, I came across this line of javascript code which I cannot understand. I have been through the javascript api docs for ej grid but couldn't find the meaning.
var obj = $("#Grid").ejGrid("instance");
If someone can explain the meaning and point out some reference documentation, I will be highly grateful.
The example I came across
https://help.syncfusion.com/aspnetmvc/grid/how-to
The javascript api I have been through
https://help.syncfusion.com/api/js/ejgrid#members:datasource
P.s: I know from a comment I came across that this has something to do with current instance of ej grid but I would like a solid understanding via a reference so I can understand.
From my little experience with Syncfusion controls the documentation explaining how to perform tasks is not well stated. If you have a license you can ask questions in their forum but I can tell you what little I learned perusing their forum.
In their JS 1 version
var obj = $("#Grid").ejGrid("instance");
and in their JS 2 version
var obj = document.getElementById('Grid').ej2_instances[0];
The variable obj appears to get an object reference to the grid identified by the id Grid. I am not sure what the instance value refers to other than the examples in the documentation show it and it works when it is used.
Not sure if I was much help.
In the Below code example Grid – Grid ID and you can take the Grid instance using the above code example. From the instance you can get the details regarding the column, dataSource, filterSettings, sortSettings etc currently applied to ejGrid. We have given support to customize the Grid using several public method. You can call those method by taking the Grid instance.
#(Html.EJ().Grid<EJGrid.Models.Order>("Grid")
.Datasource((IEnumerable<object>)ViewBag.datasource)
.AllowPaging()
.Columns(col =>
{ col.Field("OrderID").HeaderText("Order ID").TextAlign(TextAlign.Right).Width(75).Add();
col.Field("EmployeeID").HeaderText("Employee ID").TextAlign(TextAlign.Right).Width(90).Add();
col.Field("Freight").HeaderText("Freight").Format("{0:c}").TextAlign(TextAlign.Right).Width(90).Add();
col.Field("ShipCity").HeaderText("Ship City").Width(90).Add();
col.Field("Child.Test").HeaderText("TEst").Format("{0:c}").Width(90).Add();
col.Field("ShipCountry").HeaderText("Ship Country").Width(90).Add();
})
)
<script>
var obj = $("#Grid").ejGrid("instance");
var value = $("#colValue").val();
//Add custom parameter to the server
var query = new ej.Query().addParams("EmployeeID", value);
//Creating ejDataManager with UrlAdaptor
var dataManager = ej.DataManager({ url: "/Home/GetData", adaptor: new ej.UrlAdaptor() });
var promise = dataManager.executeQuery(query); promise.done(function (e) {
//Assign the result to the grid dataSource using "dataSource" method.
obj.dataSource(e.result);
</script>
To update the Grid, you can use dataSource() method. To call that method you need to take the Grid instance and call that method.
Refer the below API documentation for your reference
https://help.syncfusion.com/api/js/ejgrid#methods:datasource - used to update the Grid dataSource dynamically
https://help.syncfusion.com/api/js/ejgrid#members:datasource - returns the Grid dataSource.
Please get back to us if you have further queries.

Internationalization in SAPUI5

I have problem with Internationalization in SAPUI5.
I have a folder i18n and it has a file i18n.properties and inside it has NAME=app name
SERVER= server name
I have a shell and inside onInit I have this code :
var oModel = new sap.ui.model.resource.ResourceModel({bundleUrl:"./i18n/i18n.properties"});
sap.ui.getCore().setModel(oModel, "i18n");
then I go to my View and and use it in my shell like this:
oShell = new sap.ui.ux3.Shell({
id:"main-shell",
appTitle:"{i18n>NAME}",
showPane:false,
showLogoutButton:false,
showTools:false,
});
this works fine.But when I go to another view and use it to get the server address it doesn't work for example i go to another controller and use it like this:
var URL="{i18n>SERVER}";
this code doesn't get resolved and stay the same as it is.
You are trying to bind the value to a varaible, what you need to do is read from the bundle directly, one way to get the value is
var URL = sap.ui.getCore().getModel("i18n").getResourceBundle().getText("SERVER");

Accessing value by javascript Play Framework/Scala

First of all I am using Play framework with scala.
I am creating a graph and with the node id I would like to show some information at the same page.
In order to do that, first I need to get node.name but for some reasons #node.name function is not working. When searching for it I learnt that it's because play is server-side and js is client-side. However I need to get the data somehow.
I also cannot access:
var html = "<h4>" + node.name + "</h4><b> connections:</b><ul><li>"
How can I access this through the view?
My second question is after reaching the js node.name, I need to access to controller and do the same action one more time but this time with the new node.name .
View Part:
onClick: function(node) {
#node.name
}
1) Is this code in your controller? And are the node variable in scope? If so this should be perfectly legal code, since it will be evaluated as pure scala.
2) The templates are a different story however. You probably know they parse everything as normal html, unless escaped. To use a variable you have to bring it into scope by either:
defining a 'constructor' for the template at the absolute beginning of the file:
#(node : Node)
...
#node.name // later in the file
See http://www.playframework.com/documentation/2.0/ScalaTemplates
or define a variable inside the template:
#defining( Get.node.from.somewhere ) { node =>
#node.name
}
See Play! framework: define a variable in template?
If you did either of the two, you should have no problem accessing the node variable. Even in scripts. But note that external scripts does not have access to the same variables. It is thus very common to use inline scripts or import it as another template if you need to access a variable from JavaScript.
Edit: I've made a gist of a template, controller and routes file: https://gist.github.com/Jegp/5732033

AngularJS - binding input file scope to a different scope

Wasn't sure how to properly title my question, I guess in my case it can also be titled "DOM manipulation not being detected by the scope", but it all depends on the approach of my problem.
To start off, I followed an official example on AngularJS main website with the Projects app which connects with Mongolab. The only difference is I want to add a file input, that reads file name and its lastModifiedDate properties and then applies those values to my form. To make file input work I followed this example here.
I made it work, but the problem is that when values get applied to my form scope is not picking up the changes.
I am doing DOM manipulation in my .apply() function and using $compile too, but something is missing. Or perhaps there's an easier way altogether without doing DOM manipulation?
Here's what I have so far, please take a look at this plunker - http://plnkr.co/edit/mkc4K4?p=preview
(Just click on the plus sign icon to add new entry, then try choosing a file.)
You need to add a watch statement in the CreateCtrl
function CreateCtrl($scope, $location, Movie) {
$scope.inputfile = {};
$scope.movie = {};
$scope.$watch('inputfile.file', function(value){
$scope.movie.filename = value ? value.name : '';
$scope.movie.dateadded = value ? value.lastModifiedDate : '';
})
$scope.save = function() {
Movie.save($scope.movie, function(movie) {
$location.path('/edit/' + movie._id.$oid);
});
};
}
Demo: Sample

YUI3 DOM is undefined?

I am newcomer to Javascript and have been tasked with migrating our product's UI from YUI2 to YUI3.
It doesn't look like there's a migration guide anywhere, so I'm browsing internet posts and the yui docs for now.
In my global scope, I've temporarily added something like var Y = YUI().use('*',function(Y){});
I've encountered a YAHOO.util.Dom.get(...) elsewhere which doesn't work with YUI3, and it looks like Y.DOM.byId(...) is the recommended migration. But, I'm getting the error that "Y.DOM" is undefined!
Whoever's using Y.DOM.(...), how did this get resolved?
I don't know where you found the idea of Y.DOM.byId
Try
var node = Y.one('#elementID');
or if you want to use classes:
var nodes = Y.all('.className');
For more information on how to get nodes in YUI3, see their documentation
EDIT:
<script>
YUI().use('node', function (Y) {
var node = Y.one('#elementID');
});
</script>