Not able to set value in JSTL - jstl

from ajax response i am getting json string:
{"{\"nodeName\":\"abc\"}":[{"url":"abc","status":true},{"url":"abc","status":true}]," {\"nodeName\":\"pqr\"}":[{"url":"abc","status":true},{"url":"abc","status":true}]}
and i am parsing that json string from below mentioned code:
$.each(obj, function(key, arr) {
$.each(arr, function(_, v) {
alert(key +" "+ v.url +" "+v.status);
});
});
till now it works fine.
Now, using jstl i am setting the value of key, v.url and v.status inside $.each like this
<c:set var="status" value="${v.status}"/>
<c:set var="url" value="${v.url}"/>
<c:set var="nodeName" value="${key}"/>
alert("url =" +'${status}' + " key =" + '${nodeName}' + " status ="+ '${url}');
i am able to get the value of key(${nodeName}) on alert but no value for url and status.
Please suggest..

Related

Dynamic field validation message issue

1.I have added dynamic array field which changes on the dropdown. and I have added "required" in html
$.each(data.result, function (key, value) {
if (typeof value['filter'] !== "undefined") {
var id = value['filter']['id'];
var name = value['filter']['name'];
$(".label_filter2").append('<div class="form-group m-form__group"><label class="custom_form_label">' + name + '<span class="error_msg">*</span></label><input type="text" class="form-control m-input m-input--air filter_specification" name="filter[' + id + ']" placeholder="Enter ' + name + '" data-toggle="m-tooltip" required title="' + name + '"></div>');
}
});
2.Its totally work, but problem is validation message same like label.
https://www.screencast.com/t/Hqawm0Tae
3.I need "this field is require" message.I hope you are understand my question.Please help me.

WebSphere Portal Theme: Access page metadata

I am trying to fetch the page metadata using JSP file. I am using below code to fetch the page metadata.
<%!
public void testMeta(PageContext pageContext, String nodeId) {
Map<String, Object> parentMeta = (Map<String, Object>)pageContext.getAttribute(nodeId, PageContext.REQUEST_SCOPE);
//System.out.println("Meta Object " + nodeId + ": " + parentMeta);
Set<Map.Entry<String, Object>> entry1 = parentMeta.entrySet();
//System.out.println("No. of elements: " + entry1.size());
for (Map.Entry<String, Object> entry: entry1 ) {
System.out.println("Key: " + entry.getKey() + ", Value: " + entry.getValue());
}
Set<String> keySet = parentMeta.keySet();
if (keySet != null ){
System.out.println("Keyset contains something");
} else {
//System.out.println("Keyset is NULL");
}
}
%>
<c:if test="${empty parentID}">
<c:set var="parentID" value="${param.parentID}" />
</c:if>
<c:set var="showHidden" value="${param.showHidden}" />
<c:set var="parentNode" value="${wp.navigationModel[parentID]}"/>
<c:if test="${curLevel==1}">
<c:set var="dirMeta" value="${parentNode.metadata}" scope="request" />
{
"ishidden":"parentNode.metadata['com.ibm.portal.Hidden']" //this is working
"attributes": {
<% testMeta(pageContext, "dirMeta"); %>
}
}
</c:if>
In above code, I am passing page identifier from client side fetch the metadata of the page and its children. I am getting object of NavigationNodeBean using wp.navigationModel bean.
I am always getting empty Map in the testMeta method, the size of entry1 set is always 0 though there are number of metadata entries present on the page.
Does any one have faced this kind of issue?
Note:
I cannot use as I am not using the portal's rendering, I am using portal theme with angular, which gets the page content as and when necessary. I am using angular's router to decide which page to render, and in this case portal doesn't have any of the state information about the page I am rendering.

Spring dojo request issue

I am quite new to Spring framework and i have a problem.
I have a page A.jsp and in this page i have a link to page B.jsp
<c:url value="${pageContext.request.contextPath}" var="contextPath" />
Click here
And in controller
#RequestMapping("pageB")
public String pageBlink(SitePreference sitePreference, Device device, Model model) {
return "pageB";
}
Now on page B.jsp i want to invoke an Ajax call.
I have a link Send request
function myFunction(){
dojo.xhrGet({
// The URL of the request
url: "requestPage",
method: "POST",
handleAs: "json",
// The success callback with result from server
load: function(jsonData) {
var content = "";
dojo.forEach(jsonData.newsItems,function(locationPoint) {
// Build data from the JSON
content += "<p>" + locationPoint.name + "</p>";
content += "<p>" + locationPoint.latitude + "</p>";
content += "<p>" + locationPoint.longitude + "</p>";
content += "<p>" + locationPoint.number + "</p>";
});
},
// The error handler
error: function() {
// Do nothing -- keep old content there
},
// generate an extra GET variable to prevent browsers from caching
preventCache: true
});
}
And add into controller
#RequestMapping(value="requestPage", method = RequestMethod.GET)
public MyObj returnEVSELocations(){
logger.log(Level.INFO, "return evse locations --------------");
MyObj myObj = new MyObj();
// add some stuff into the obj
return myObj;
}
But this request a requestPage.jps ... i want just to work in my page (B.jsp).
Any help is more than welcome.
Thanks!
I found the issue.
In fact there was 2 problems
1. In Ajax call i must have
dojo.forEach(jsonData, ...) instead dojo.forEach(jsonData.newsItems, ...)
2. In the controller in on my method i must add the annotation
public #ResponseBody MyObj
I hope this help someone to front the same issue.

Passing values as bash file arguments through a JSP page

I am writting this code for a JSP page that reads from an text input and passes the variables' values to a bash file as parameters, but it seems like the bash file doesn't take variables, it only worked when I passed real values instead of variables.
How to pass a variable to this bash file?
Here is the code:
<%
String myArgument = "";
if (request.getParameter("submit")==null)
{
%>
<form method="POST" action="/tomcat/webapps/project/jsp/runCMD.jsp" id=form2>
<input type=text id=first value="${first}" Title="IP adress here" >
<input type="submit" value="Submit Changes" name="submit"
onClick="if(runOnSubmit()){getSomethingWithAjax('ChangeIP.jsp'+
getAllFormElementsAndMakeIntoURI(true),'',
'hereIsTheMainHeaderSpan',false,false);}">
<%
}//end if
//else if submitted
else {
request.setAttribute("myArgument", myArgument);
try {
Process p = Runtime.getRuntime().exec("/root/script.cmd myArgument );
p.waitFor();
System.out.println("Waiting for the System to reboot" + p.exitValue());
} catch (Exception e) {
System.out.println(e.getMessage());
out.println("There was an error while submitting ");
}
}//end else
%>
Note that when passing a value to the script it got executed with the code below:
Process p = Runtime.getRuntime().exec("/root/changeip.cmd 10.0.100.18");
What you want is:
Process p = Runtime.getRuntime().exec("/root/script.cmd " + myArgument );
P.S.
Actually I don't see where do you assign a value to myArgument after declaring it:
String myArgument = "";
Not really related, but you are doing it kind of PHP style. Read this: https://stackoverflow.com/a/3180202/814702

pass dropdown selected values(list) as a parameter via Ajax to controller

He all,
i have a dropdown combo box , i need to send the selected value as a list to my controller.
i have tried something like this.
dropdown :
<g:select name="clientId" id="clientId" multiple = "yes" size = "4" from="${com.springpeople.steer.partymodel.roles.ClientRole.list()}" class = "filter_combo" optionKey="id" />
method to call on changing :
$("#clientId").change(function(){
var clientId = $("#clientId").val(); // it gives clientId = 1,2,3
var department = document.getElementById("departmentId");
department.options.length=0;
fillDepartment(clientId,"filter_department","${createLink(controller:'report', action:'fillDepartments')}")
}
fillDepartmentInFilter ajax call method:
function fillDepartment(clientId,department_div_id,fillDepartmentUrl,selectedDepartmentIds){
$.ajax({
url:fillDepartmentUrl,
data: ({clientId :clientId,departmentId:selectedDepartmentIds}),
dataType: "html",
success: function(data) {
$("#"+department_div_id).html("");
$("#"+department_div_id).attr("disabled", true);
$("#"+department_div_id).attr("color")
$("#"+department_div_id).html(data);
}
});
}
i want to get the clientId values as a list in controller.. how can i do it.. right now when i am trying to print the value of parameters it gives me value like this
fillDepartments :: parameters = [clientId[]:[3, 13, 9], action:fillDepartments, controller:report]
fillDepartments :: clientid = null
First get all of selected indexes and then fetch them as a string to your AJAX. In your server-side script code split them with the splitter that you defined like ',' at below:
var cmb = document.getElementById('clientID');
var selItems = "";
for(i=0;i<cmb.options.length;i+=1){
if(cmb.options[i].selected){
selItems = selItems + cmb.options[i].value + ",";
}
}
// Remove the last splitter
selItems = selItems.substr(0,selItems.length-1);
Then pass the selItems to your data parameter in jQuery's AJAX.
Hope my code would be correct, I didn't tested it.

Resources