Mailing List webobjects-dev@wocommunity.org Message #21
From: Samuel Pelletier <webobjects-dev@wocommunity.org>
Subject: Re: [WO-DEV] Communication between 2 different browers (but same application)
Date: Sat, 30 Jan 2021 08:51:31 -0500
To: WebObjects & WOnder Development <webobjects-dev@wocommunity.org>
Hi Markus,

Sorry for the delay, my original message bounced du to large size (syntax colored code...)

I just did something like this yesterday!

As Dennis wrote, you need to adjust based on your needs. In my case, I wanted to integrate a simple barcode scanner to a custom WO app used for a small retail store inventory, I wanted a wireless barcode scanner connected to the server to eliminate the complexity of bluetooth pairing and the less than optimal user interaction possible when using a web app and a device on the browser computer.

My solution is very simple but only works as is on a single instance application and uses pooling.

My scanner is connected to a Raspberry Pi that send the code to a direct action. My system can support multiple scanners. By default, received codes are simply discarded.

When I want to use a scanner, the component register an handler to a scanner (found by a name) with the method that should receive the code. To implement the user interface, I use a AjaxLongResponse. The principle is simple, the content of AjaxLongResponse is refreshed every second by default until isRunning is false.

Hope you will find your answer with Dennis and this, you have 2 solutions with completely opposite requirements and scallability.

Regards,

Samuel


Here is the html used to edit the UPC code for a product (AjaxLongResponse is a specialized  AjaxUpdateContainer) :
<wo:AjaxLongResponse id = "barcodeField" isRunning = "$waitingForCode">
  <label>codeUPC<wo:not condition = "$waitingForCode">
      <wo:AjaxUpdateLink class = "tiny button right noMargins" updateContainerID = "_parent" action = "$waitForCode">Scan code</wo:AjaxUpdateLink>
    </wo:not>
    <wo:textfield class = "text-right" value = "$format.codeUPC" />
  </label>
</wo:AjaxLongResponse>

Component Java code :
public boolean waitingForCode() {
return waitingForCode;
}

public WOActionResults waitForCode() {
waitingForCode = true;
BarCodeScanner.withName("sam").registerHandler(new BarCodeScanner.Handler() {
@Override
public boolean keepHandlerAfterProcessingCode(String code) {
format().setCodeUPC(code);
save();
waitingForCode = false;
return false;
}
});
return null;
}

My handler returns true if it should remain registered (to scan a list of item for example).

The direct action send the scanned code with this:
BarCodeScanner.withName(scannerName).processCode(newCode);

BarCodeScanner.java
public class BarCodeScanner {
static private Map<String, BarCodeScanner>scanners = new HashMap<>();
private String name;
private Handler handler;

public BarCodeScanner(String name) {
this.name = name;
}

static public BarCodeScanner withName(String name) {
BarCodeScanner scanner = scanners.get(name);
if (scanner == null) {
scanner = new BarCodeScanner(name);
scanners.put(name, scanner);
}
return scanner;
}

public String name() {
return name;
}

public void registerHandler(Handler handler) {
this.handler = handler;
}

public void processCode(String code) {
if (handler != null) {
if (handler.keepHandlerAfterProcessingCode(code) == false) {
handler = null;
}
}
}

public static abstract class Handler {
public abstract boolean keepHandlerAfterProcessingCode(String code);
}
}



> Le 28 janv. 2021 à 03:26, Markus Ruggiero (rucotec) <webobjects-dev@wocommunity.org> a écrit :
>
> I need some conceptual help.
>
> Let’s say you have a browser open to a Wonder app (component based session). Imagine you go to a different computer and open another session (maybe via direct action) to the same application. I want to have a button (or some such) in the first window that when clicked communicates to that second independent window and enables some form fields there. The user then submits data to the application from that second window. The first window registers the submission and continues with the user interaction.
>
> How would you do something like this? Is this possible at all? Possibly the second login could be from a mobile device and the presented browser page does not allow to do more interaction with the application than just enter some data and submit. The first session is required do wait for the data (or a cancel) and can then proceed.
>
> Thanks for any ideas / help
> —markus—
>
>
>
>
> Markus Ruggiero
>
> rucotec GmbH                        web https://rucotec.ch
> Steinenvorstadt 79                email markus.ruggiero@rucotec.ch
> 4051 Basel / Switzerland         mobile +41 79 508 4701
>
>
>
>
>
>
>
>

Subscribe (FEED) Subscribe (DIGEST) Subscribe (INDEX) Unsubscribe Mail to Listmaster