GlideAjax is not defined in UI macro - macros

I'm calling GlideAjax from UI Macro , but I'm facing below error:
org.mozilla.javascript.EcmaError: "GlideAjax" is not defined.
Caused by error in at line 2
1:
==> 2: var ga = new GlideAjax('global.GetHostName');
3: ga.getXMLWait();
4: var hostName = ga.getAnswer();
5:
My UI Macro looks like below:
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:evaluate>
var ga = new GlideAjax('global.GetHostName');
ga.getXMLWait();
var hostName = ga.getAnswer();
</g:evaluate>
<!--<j:set var="jvar_inc" value="${help_sysid}" />-->
<span id="asp-cms-user-salutation">
${gs.getMessage('Welcome')},
<j:if test="${!gs.getUser().isXML()}">
<span id="asp-cms-user-name">${gs.getUserDisplayName()}</span>
<span id="asp-cms-user-sysname">${hostName}</span>
</j:if>
</span>
</j:jelly>
What I'm doing wrong here ??

GlideAjax is a client-side api used to make your browser make an ajax request.
The <g:evaluate> tag in jelly is a server-side script. Assuming GetHostName is a Script include name, you can just directly call the script include like:
<g:evaluate>
var hostNameGetter = new global.GetHostName();
var hostName = hostNameGetter.getValue(); // replace getValue() with whatever your method name is in GetHostname
</g:evaluate>

Related

Angular dataTables with Ajax Source

I'm trying to load data from an ajax source into angular datatable but it's not even hitting the ajax call.
var analyzer=angular.module('analyzer', ['datatables']);
analyzer.controller('WithAjaxCtrl', WithAjaxCtrl);
function WithAjaxCtrl(DTOptionsBuilder, DTColumnBuilder) {
var vm = this;
$scope.dtOptions = DTOptionsBuilder.fromSource('/analyzer/List')
$scope.dtColumns = [
DTColumnBuilder.newColumn('BuildName').withTitle('Name'),
DTColumnBuilder.newColumn('Total').withTitle('Total'),
DTColumnBuilder.newColumn('Passed').withTitle('Passed'),
DTColumnBuilder.newColumn('Failed').withTitle('Failed')
];
}
Here's the html code for the table-
<div ng-controller="WithAjaxCtrl">
<table datatable="" dt-options="dtOptions" dt-columns="dtColumns" class="row-border hover"></table>
</div>
data from ajax source is in the form -
{"responseCode":0,"responseData":[{"Name":"Rob","Total":6273,"Passed":5874,"Failed":399}]}
So will i have to define the datasrc ?
Yes, you need to specify the dataSrc since your rows is contained in responseData, not in the default or expected data property. In angular dataTables there is an option setter named withDataProp() :
$scope.dtOptions = DTOptionsBuilder.fromSource('/analyzer/List')
.withDataProp('responseData')
Cannot link directly but look at https://l-lin.github.io/angular-datatables/#/api

How to Use sendkeys when input type is number with Chrome

HTML
<ion-input [(ngModel)]="login.username" ngControl="username1" type="number" #username1="ngForm" id="userName" required>
</ion-input>
PROTRACTOR TEST CODE
let usern: ElementFinder = element.all(by.css('.text-input')).get(0);
usern.sendKeys('error');
expect(usern.getAttribute("value")).toEqual("error");
browser.sleep(500);
usern.clear();
browser.sleep(1000);
usern.sendKeys('12345');
The element is found but no text is entered into the field. If I change the element to type="text" the protractor command works.And the page view is 'e' and can't be clear.
Secondly if I send string like this: "we2124will", the actually send data is '2124' and the result from getAttribute("value") is 2124.
Thirdly even if I changed the sendKeys to number, the result is not full number string. For example:
Failures:
1) Login page should input username and password
Message:
Expected '125' to equal '12345'.
Stack:
Error: Failed expectation
There are some number missing.
Since you're using an <ion-input>, the actual HTML <input> tag will be nested within, and it won't have an id attribute. The effect is that the wrong element can get selected.
Try something like below to grab the nested input tag:
let username = element(by.id('userName')).all(by.tagName('input')).first();
username.sendKeys('fakeUser');
That worked for me.
As a workaround, you can introduce a reusable function that would perform a slow type by adding delays between send every key.
First of all, add a custom sleep() browser action, put this to onPrepare():
protractor.ActionSequence.prototype.sleep = function (delay) {
var driver = this.driver_;
this.schedule_("sleep", function () { driver.sleep(delay); });
return this;
};
Then, create a reusable function:
function slowSendKeys(elm, text) {
var actions = browser.actions();
for (var i = 0, len = text.length; i < len; i++) {
actions = actions.sendKeys(str[i]).sleep(300);
}
return actions.perform();
}
Usage:
var elm = $("ion-input#userName");
slowSendKeys(elm, "12345");
What version of protractor are you using?
Not sure this is the issue but try grabbing the element by ng-model
var elem = element(by.model('login.username'));
elem.sendKeys('error');
expect(elem.getAttribute("value")).toEqual("error");
elem.clear();
elem.sendKeys('12345');
expect(elem.getAttribute("value")).toEqual("12345");

Flask request not returning any info from select

I'm trying to set up a simple select dropdown form with Flask. Based on the option chosen, I grab different data from my database, and display it back into a div on my html template. But I can't seem to get the Flask request to register any of the select options. When I print request.form or request.args, I always get empty Dicts. It's probably something simple I'm missing but I can't seem to find the problem. I've gotten this to work with several input and button forms, but I can't get it to work right for selects.
Here is a bit of my html template code, with the form and select. I've tried both GET and POST method in the form.
<div class="options" id="options">
<form class="form-horizontal container-fluid" role="form" method="GET" action="exploresn2.html">
<div class="form-group">
<label for="xaxis" class="col-sm-2 control-label">X-axis:</label>
<div class="col-sm-2">
<select name="xaxis" class="form-control" id="xaxis">
<option selected value="mjd" id="mjd">MJD</option>
<option value="seeing" id="seeing">Seeing</option>
<option value="airmass" id="airmass">Airmass</option>
<option value="hourangle" id="hourangle">Hour Angle</option>
</select>
</div>
</div>
</form>
</div>
In Flask, at first, I tried inside my app
import flask
from flask import request, render_template, send_from_directory, current_app
explore_page = flask.Blueprint("explore_page", __name__)
#explore_page.route('/exploresn2.html', methods=['GET','POST'])
def explore():
xaxis = str(request.args.get("xaxis", "any"))
.... [populate new xaxis variable based on request option selected]
exploreDict['xaxis'] = xaxis
return render_template("exploresn2.html", **exploreDict)
or
mjd = valueFromRequest(key='mjd', request=request, default=None)
if mjd:
mjds = [int(exp.platedbExposure.start_time/(24*3600)) for exp in exposures]
xaxis = mjds
exploreDict['xaxis'] = xaxis
to look for and grab a specific values, or in the first case, any value select. The valueFromRequest is function that grabs data from either GET or POST requests.
but this returns nothing, and then I tried just printing the entire request.args (or request.form) and it returns and empty Dict. Everything I try it still returns empty Dicts. So I'm missing some set up somewhere I think but the form looks right to me?
I'm not sure if this is the actual answer to this problem that I was looking for, but here is what I came up with. I couldn't actually get the Flask to accept a GET request into the original explore method defined, so I implemented a new method in Flask to return a JSON object
#explore_page.route('/getdata', methods=['GET','POST'])
def getData(name=None):
name = str(request.args.get("xaxis", "mjd"))
xaxis = 'populate new xaxis data based on value of name'
data = '(x,y) data array filled with values for plotting'
axisrange = range of x,y data for axes for plot
return jsonify(result=data, range=axisrange)
and then I just made a GET request via javascript to that method whenever the select button changes. So in my exploresn2.html template I have (using Flot for plotting)
$("#xaxis").change(function(){
var newname = $("#xaxis :selected").text();
var axes = plot.getAxes();
options = plot.getOptions();
var plotdata = plot.getData();
// make a GET request and return new data
$.getJSON($SCRIPT_ROOT + '/getdata', {'xaxis':$("#xaxis :selected").val()},
function(newdata){
// set new data
for (var i = 0; i < plotdata.length; ++i) {
plotdata[i].data = newdata.result[plotdata[i].label];
}
// set new axes
axes.xaxis.options.panRange = [newdata.range[0]-50,newdata.range[1]+50];
axes.xaxis.options.axisLabel = newname;
axes.xaxis.options.min = newdata.range[0]-1;
axes.xaxis.options.max = newdata.range[1]+1;
axes.yaxis.options.min = newdata.range[2];
axes.yaxis.options.max = newdata.range[3];
// redraw plot
plot.setData(plotdata);
plot.setupGrid();
plot.draw();
});
});

how to pass parameters from jsp to java class using RESTFUL

i hav created a jsp page from which i m taking some values and on submit it should pass the parameters to the java class using rest.
< form id="payment" method="post" action="addtogroup">
< ol style="padding: 0;">
< li>< label for="groupId">Group id:< /label>
< input type="text" id="groupId" name="groupId"/>
< br />
< li>< label for="vendorId">Profile Id :< /label>
< input type="text" id="vendorId" name="vendorId"/>
< li>
< input type="submit" value="Submit"/>
< br />
< /ol>
< /form>
and the java code is:
#RequestMapping(value = "/addtogroup/{groupId}/{vendorId}",method = RequestMethod.POST)
public String addtoGroup(#ModelAttribute("groupId") String groupId,#ModelAttribute("vendorId") String profileId){
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
String username = auth.getName();
System.out.println("group id is="+groupId);
System.out.println("profileId is="+profileId);
System.out.println("username is="+username);
grpDao.addToGroup(groupId,profileId,username);
return "addtogroup";
}
when i type [http://localhost:8080/biznex/rest/addtogroup/2/13] in the address bar directly the code is executed.
but when i click submit button in the jsp i get page not found error.
plz help me out.
< form id="payment" method="post" action="addtogroup"> This statement means submit the FORM data using POST method to the url "currentpath"/"addtogroup"
However, your RESTFUL Server side component expects the url in the form of /addtogoup/{groupid}/{vendorid} in a GET method
I would suggest you to have a JavaScript method which converts your form fields to the URI path- using jQuery or plain JavaScript
As thewhiterabbit wrote, you have to pass the complete REST url with the groupid and vendorid.
In order to build it you don't need to use JS, it's enough the spring tag library. Here, how it works:
<spring:url value="/addtogoup/${form.groupid}/${form.vendorid}" var="actionURL"/>
<form:form method="POST" action="${actionURL}" modelAttribute="form">

Form Validation: Select

I'm trying to display an error message if the select button in my form is not changed. It works fine for the rest but not the select, please help! and I know that the image wont work like that, I cant post images as a new member.
Html is:
<div id='first_name_error' class='error'><image code here></div>
<div><input type='text' name='first_name' id='first_name' placeholder="YOUR FIRST NAME*"></div>
Number of Guests:*<div id='guests_error' class='error'><img src='img/booking/error.png'></div>
<div><select name='guests' id='guests' style="margin:0px;" SIZE="1"><OPTION SELECTED value="guests">Guests<OPTION>2<OPTION>3<OPTION>4</SELECT></div>
Code Is
var error = false;
var first_name = $('#first_name').val();
var second_name = $('#second_name').val();
var email = $('#email').val();
var number = $('#number').val();
var guests = $('#guests').val();
var message = $('#message').val();
if(first_name.length == 0){var error = true;$('#first_name_error').fadeIn(500);}else{$('#first_name_error').fadeOut(500);}
if(guests.value == Guests){var error = true;$('#guests_error').fadeIn(500);}else{$('#guests_error').fadeOut(500);}
Notice that your "guests" variable is already set to the value of the select element (using jQuery val()). There is no need to attempt to access the "value" property of the "guests" variable.
Second, the comparison you are making is to the identifier Guests, not to the string "Guests". You'll want to put quotes around that to make it a string literal.
You can see an example of this here: http://jsfiddle.net/tbuCJ/