Jxbrowser: how to replicate this code from v6, to acces dom and set inputs and clicks, to v7.15? - dom

im trying to make a google maps clone (schoolproject) with my own searchbar in swing. I have been playing with the latest version of jxbrowser. And i am trying to access the "doc" to set inputs to the dom html using findById and setting with value with "value". I know how it is setup in v6:
private void kButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_kButton2ActionPerformed
DOMDocument doc = browser.getDocument();
DOMElement address_element = doc.findElement(By.id("address"));
DOMElement search_element = doc.findElement(By.id("submit"));
DOMElement button = (DOMElement) search_element;
DOMInputElement address = (DOMInputElement) address_element;
address.setValue(searchbar.getText());
button.click();
But how do i replicate this code in v7.15?
My Code in v7.15
//How do i do browser.getDocument(); ?
browser.mainFrame().ifPresent(frame ->
frame.document().ifPresent(document -> {
String baseUri = document.baseUri();
}));
//how do i write this part, it cant resolve documentElement
documentElement.findElementById("address").ifPresent(element ->
((InputElement) element).value(new address));
documentElement.findElementById("sumbit").ifPresent(element ->
((InputElement) element).click
/// how do i button.click?

browser.mainFrame().flatMap(Frame::document).ifPresent(document -> {
String baseUri = document.baseUri();
System.out.println(searchLocationA.getText());
System.out.println(searchLocationB.getText());
document.findElementById("departure").ifPresent(element -> ((InputElement) element).value(searchLocationA.getText()));
document.findElementById("destination").ifPresent(element -> ((InputElement) element).value(searchLocationB.getText()));
document.findElementById("submit").ifPresent(Node::click);
System.out.println("buttons work");
});
the solution

Related

How do I update a MongoDB document with new value using reactors Mono? (Kotlin)

So the context is that I require to update a value in a single document, I have a Mono, the parameter Object contains values such as username (to find the correct user by unique username) and an amount value.
The problem is that this value (due to other components of my application) is the value by which I need to increase/decrease the users balance, as opposed to passing a new balance. I intend to do this using two Monos where one finds the user, then this is combined to the other Mono with the inbound request, where I can then perform a simple sum (i.e balance + changeRequest.amount) then return this to the document database.
override fun increaseBalance(changeRequest: Mono<ChangeBalanceRequestResource>): Mono<ChangeBalanceResponse> {
val changeAmount: Mono<Decimal128> = changeRequest.map { it.transactionAmount }
val user: Mono<User> = changeRequest.flatMap { rxUserRepository.findByUsername(it.username)
val newBalace = user.map {
val r = changeAmount.block()
it.balance = sumBalance(it.balance!!, r!!)
rxUserRepository.save(it)
}
.flatMap { it }
.map { it.balance!! }
return Mono.just(ChangeBalanceResponse("success", newBalace.block()!!))
}
Obviously I'm trying to achieve this in a non-blocking fashion. I'm also open to using only a single Mono if that's possible/optimal. I also appreciate I've truly butchered the example and used .block as a placeholder to illustrate what I'm trying to achieve.
P.S this is my first post, so any tips on how to express my problem clearer would be useful.
Here's how I would do this in Java (Using Double instead of Decimal128):
public Mono<ChangeBalanceResponse> increaseBalance(Mono<ChangeBalanceRequestResource> changeRequest) {
Mono<Double> changeAmount = changeRequest.map(a -> a.transactionAmount());
Mono<User> user = changeRequest.map(a -> a.username()).flatMap(RxUserRepository::findByUsername);
return Mono.zip(changeAmount,user).flatMap(t2 -> {
Double changeAmount = t2.getT1();
User user = t2.getT2();
//assumes User is chained
return rxUserRepository.save(user.balance(sumBalance(changeAmount,user.balance())));
}).map(res -> new ChangeBalanceResponse("success",res.newBalance()))
}

takeWhile with subscribing to new Single each time

I have a data source fun getData(page : Int) : Single<List<Data>>.
I'd like to create a behaviour where I could subscribe to that source each time with different parameters each time until conditionCheck() returns true.
I imagine something like this:
getData(page)
.doOnNext { page++ }
.doOnNext { /* manipulate data */ }
.takeWhile { conditionCheck() }
.subscribe({
print "Completed"
})
Here is a different way to think about it (pseudocode-ish):
initialPage = Observable.just(1);
futurePages = PublishSubject.create();
allPossiblePages = Observable.concat(initialPage, futurePages);
allPossibleData = allPossiblePages
.map(page -> getData(page))
.do(page -> futurePages.onNext(/* manipulate page data */));
dataYouWant = allPossibleData
.filter(data -> conditionCheck(data))
.takeFirst()
.subscribe( /* data should be here */);
Maybe this isn't the best way to do this, someone will speak up if that's the case. I'm not a big fan of the line .do(page -> futurePages.onNext ..), but something like this might work.
I put together an example that runs using rxjs (easiest to prototype/demo) here: https://plnkr.co/edit/uXE53ygo8REzpbMJdvsD

How to send (pass) variables from client to server (within the mapReduce function in server) in Meteor?

I am working on GeoSpatial project which I am using MongoDB as database and Meteor for creating my app. I have used mapReduce in my query. in order to visualize the result of query I put Google map API in the meteor. To make long story short, I want to get some location as an Input from meteor app and when I click on the button, see the result in Google Map API (which is placed in Meteor app.
Now my problem is that I cannot pass the variables (the ones that I got from textbox) from client function to server side in meteor.
Here is some part of my code in client side (here I have passed text1 and text2 as an argument in call function):
var text2 = document.getElementById("coords2").value;
var text1 = document.getElementById("coords1").value;
Meteor.call("doMapReducePointQuery", text1, text2, function(error, result){
if(error){
console.error(error)
}
else{
console.log("It works!");
}....// continued
and here is the part of the code in server side:
if (Meteor.isServer) {
Meteor.methods({
'doMapReducePointQuery': function(txt1,txt2) {
pxx=parseInt(txt1);
pyy=parseInt(txt2);
console.log(pxx); **// here I can see the pxx and pyy**
console.log(pyy);
var mapFn = function () { **// in this function I cannot get the pxx and pyy**
var px = -83.215; // here I just manually set the number, here where i want to get value from the text box and set it to px and py
var py = 41.53;
var key= this._id;
var value={
id:this._id,
type: this.type,
};
if (this.geometry.minlon <= px && px <= this.geometry.maxlon && this.geometry.minlat <= py && py <= this.geometry.maxlat) {
emit(key, value);
}
};
var reduceFn = function (key, value) { ....... // continued
As I mentioned in comments within the code, I can pass txt1 and txt2 to the doMapReducePointQuery method but the I cannot access then access the coordinates within my mapReduce mapFn function. I need to use txt1 (px) and txt2 (py) values in mapFn.
I did some research about how to make a variable, global in meteor, some of the people used "scope", but they did not mentioned how.
I would be really appreciated if somebody help me!

Issues in store-fed dijit/form/Select by setting preselected value in dojo 1.8

There is another issue when I try to set the preselected (or any) value of my store-fed dijit/form/Select widget.
The markup code is:
<div data-dojo-type="dijit/form/Select" jsId="editOptionsDialog_select" id="editOptionsDialog_select"></div>
and the js:
function editOptionsDialog_fetchData(cId, fieldName, vId) {
var store;
var def;
var return_def = new Deferred();
store = new degreeStore();
def = store.getJsonData();
def.then(function(data) {
store.data = data.items;
editOptionsDialog_select.setStore(new ObjectStore({
objectStore : store
}));
editOptionsDialog_select.value = vId;
editOptionsDialog_select.startup();
editOptionsDialog_select.set('value', 5);
console.info(editOptionsDialog_select);
// here, firebug still shows value = 1
return_def.resolve();
});
return return_def;
}
thx in advance
Greetings
Finally found a solution to the problem:
Since the selection-element DOES NOT support numerical indexes, the indexes had to be casted to strings. With that, a editOptionsDialog_select.set('value', vId.toString()) has finally worked!
Be sure to feed your store by casted numerical ids or then textual-keys by default -> (String)id where id is an integer.
Greetings

Calling class function within a constructor isn't being recognised

Answer:
It turns out I had neglected to use the new keyword when creating the class instance. The code in the question itself is fine.
Question:
I have a fairly simple class where the constructor calls another method on the class (editor_for_node). The call happens inside a jQuery each() loop, but I've also tried moving it outside.
define ['jquery'], ($) ->
class Editor
constructor: (#node, #data, #template) ->
#node.widgets().each (i, elem) =>
data = if #data then #data[i] else null
node = $(elem)
#editor_for_node node, data
editor_for_node: (node, data) ->
console.log 'hello!'
return {
'Editor': Editor,
}
When the line #editor_for_node node, data gets called, I get an error (in Firebug) saying this.editor_for_node is not a function.
I really can't see why this isn't working properly, the only possible source of weirdness that I can see is my use of require.js's define function at the start.
Edit: Generated output
(function() {
define(['jquery'], function($) {
var Editor;
Editor = (function() {
Editor.name = 'Editor';
function Editor(node, data, template) {
var _this = this;
this.node = node;
this.data = data;
this.template = template;
this.node.widgets().each(function(i, elem) {
data = _this.data ? _this.data[i] : null;
node = $(elem);
return _this.editor_for_node(node, data);
});
}
Editor.prototype.editor_for_node = function(node, data) {
return console.log('hello!');
};
return Editor;
})();
return {
'Editor': Editor
};
});
}).call(this);
First: Which version of CoffeeScript are you using? The fat arrow has been a source of bugs in certain previous releases.
If you're using the latest (1.3.1), then I'm going to go ahead and say that this is an indentation issue. When I copy and paste your code, it works fine. Are you mixing tabs and spaces? Verify that the compiled output contains the line
Editor.prototype.editor_for_node = ...
Update: See the comments on this answer. Turns out the problem was that the new keyword wasn't being used when invoking the constructor.