console message captured by onConsoleMessage is incomplete - java

I have WebView into which I'm loading a webpage, I have set the custom WebChromeClient to capture console logs but I've found it is incomplete comparing to the console in browser. The message returned by cm.message() doesnt contain all values passed to the console methods.
console.log("Test");//Test
will work but following will only display first param
console.log("test", 1);//test - expected test 1
is there any way to workaround it?

An interesting bug!
You can wrap console.log in your own function that concatenates all the arguments into a single string. The JavaScript code for doing this is below:
(function() {
var oldLog = console.log;
console.log = function() {
oldLog.call(console, Array.prototype.slice.call(arguments).join(" "));
}
})();
You can inject it into your page with WebView.loadUrl('javascript:...'), or WebView.evaluateJavascript.

Related

Passing javascript array tojava servlet

I have found other question regarding on this, but still im having a problem,When i check getParamerterValues, its always return null, and i think im having trouble redirecting it to my controller.Bare with me, in new to web app.
arr = [];
$(document).on("click","#idhere",function(){
$.post("servlet.html","ids="+arr+"",function(response){
});
});
or is there something like converting array of javascript to JSON of array in JSP so i can pass it to my servlet?
String arr [] = request.getParameterValues("ids");
if(arr != null){//this line doesnt return true even my array contains item}
change
String arr [] = request.getParameterValues("arr");
to
String arr [] = request.getParameterValues("ids");
Its always return null, and i think im having trouble redirecting it to my controller
I couldnt see any code to pass the values to the controller. In your jquery function , you have something like this $.post("servlet.html","ids="+arr+"",function(response){
It is not possible to post a value to the other html file from jsp. if you are trying to pass the values to the servlet.
try something like this ,
$(document).on("click","#idhere",function(){
$.post("servletName","ids="+arr+"",function(response){
});
});
Note: servletName refers to the url , mapped in your web.xml for the servlet you are trying to post the data.
Also make sure you jquery function is posting the data correctly to the controller through the browser console .
As the examples below show, the post method wants an json object as the data parameter.
This should do the job
$.post("servlet.html",{"ids": arr.join()},function(response){
});
Examples: Example: Request the test.php page, but ignore the return
results.
1 $.post( "test.php" ); Example: Request the test.php page and send
some additional data along (while still ignoring the return results).
1 $.post( "test.php", { name: "John", time: "2pm" } ); Example: Pass
arrays of data to the server (while still ignoring the return
results).
1 $.post( "test.php", { 'choices[]': [ "Jon", "Susan" ] } ); Example:
Send form data using ajax requests
1 $.post( "test.php", $( "#testform" ).serialize() );
see http://api.jquery.com/jquery.post/

Need Native Android/Java Method to Query Online Search Field

I'd like to query a .cfm page via Android but I'm not sure what method I should be using to do so - any suggestions?
Example:
http://www.sheriff.org/apps/arrest/results.cfm?lname=smith&fname=
P.S.
Would I use something along the lines of this?
http://androidexample.com/AsyncroTask_Example_To_Get_Server_Data_-_Android_Example/index.php?view=article_discription&aid=59&aaid=84
use an ajax call with the url with the appropriate first and last name parameters, and then extract the result table from the return value.
see a working jsfiddle sample here: http://jsfiddle.net/FhHXK/
code:
$('#get').click(function () {
$.ajax({
url:'http://www.sheriff.org/apps/arrest/results.cfm?lname=a&fname=b',
type: 'GET'
}).done(function (data){
var result = $(data).find('table.datagrid');
console.log(result.html());
$('body').append(result);
});
});

preventing string concatenation in javascript function during JSP compilation

var result = null;
function setSendButton(userInput){
var clicked=userInput;
result = "<%=mb.myMethod(clicked)%>";
}
where myMethod is a java method called through using jsp tags. it is defined as:
public boolean myMethod(String isClicked){
if(isClicked.equals("true")){
return true;
}else{
return false;
}
}
for some reason stepping i got a JSP compilation error that compiles the code where var clicked value of "true" is not passed and clicked becomes a string during JSP compilation like so: mb.myMethod(clicked) instead of mb.myMethod("true")
It can't work like that.
The Java code in JSP is translated and compiled on the server side before sending to the client's browser. The javascript variable is available only after the JSP is translated and compiled to become a HTML file and sent to the client browser. At that time, The mb.myMethod is already already executed on the server side.
In short, you can passed java code to js assignment but not the other way around.
Wouldn't this work?
var result = null;
function setSendButton(){
result = "<%=mb.myMethod(true)%>";
}

can not read some string from struts.properties

I have define variable error in struts.properties as follows:
error=this is an error
Now I can call this error as follows:
ErrorMsg = "<s:property value='getText(\"error\")'/>";
and it works, the result is: ErrorMsg=this is an error
How to get the text of variable instead of string?
I tried the following:
var m="error";
error1 = "<s:property value='getText(m)'/>";
error2 = "<s:property value='getText(\"m\")'/>";
I use firebug debugger and error1 and error2 are displyed as follows:
error1=""
error2=""
Any Idea?
thank you in advance
You appear to be mixing server side and client side code.
The s:property tags will be evaluated first on the server side, long before any value of m is valid, as that is client side JavaScript code.
If you post what you're trying to achieve then I or someone else may be able to help further.
HTH

struts validation problem in IE

I am using Struts 2.1.8 and facing validation problem in IE. I am getting the following error
An exception occurred: Error. Error message: Invalid argument.
I tried out to figure out the cause and found the following. My generated javascript code is:
field = form.elements['district.name'];
var error = "Enter only alphabets for district";
if (continueValidation && field.value != null && !field.value.match("^[a-zA-Z ]*$")) {
addError(field, error);
errors = true;
}
I tried to mock up by putting the same code in a function and calling it in onclick event. The method addError() throws the exception and the reason is field variable. If I change it to field[0], it works fine. How to fix this error?
Check the generated HTML source. Open the page in webbrowser, rightclick and choose View Source. Is the input field's name really district.name? Isn't it prefixed/suffixed with some other autogenerated key (possibly the ID/name of the <form>) like as many other MVC frameworks do? If so, you'll need to change the JavaScript code accordingly that it uses the right element name as it appears in the HTML DOM tree. You know, JavaScript runs at the client machine and only sees the generated HTML DOM tree, not the "original" server-side code which is responsible for generating the HTML.

Categories