How can I add my ExtWebComponent to a JSP? - extwebcomponents

I would like to add my web components to my JSP. How do I wire up my ExtWebComponents to do this?
My server side runs in a Servlet Container.

I have a project example showing how to do just that. The client side is the ExtWebComponents and a server side is Java.
Project Notes
Maven multi-module project
Java servlet container on the backend
The client is an ExtWebComponents project, using the pom.xml only to import it easily as a module into an IDE. And to fire off npm builds.
Example Project
JSP Example
<!DOCTYPE HTML>
<html manifest="">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=10, user-scalable=yes">
<title>Sandbox Project</title>
<link rel="icon" type="image/x-icon" href="resources/favicon.ico">
<script src="webcomponents-bundle.js"></script>
<link href="ext/ext.css" rel="stylesheet">
</head>
<body>
Testing
<my-sandbox-view></my-sandbox-view>
<%
out.write("<h2>Test jsp<h2>");
%>
<!-- The webpacked resource bundle is imported here -->
<script type="text/javascript" src="ext/ext.js"></script><script type="text/javascript" src="app.js"></script></body>
</html>
Example Source
Resources from Client to Server
You have to tell webpack to copy the resources to your web app directory so they can be used in your Java project. For example this is how it could be done using a custom plugin, and then using webpack --watch.
// This causes infinite loop, so I can't use this plugin.
// new CopyWebpackPlugin([{
// from: __dirname + '/build/',
// to: __dirname + '/../sandbox-server/target/test1'
// }]),
// Inline custom plugin - will copy to the target web app folder
// 1. Run npm install fs-extra
// 2. Fix the path, so that it copies to the server's build webapp folder
{
apply: (compiler) => {
compiler.hooks.afterEmit.tap('AfterEmitPlugin', (compilation) => {
// Debugging
console.log("########-------------->>>>> Finished Ext JS Compile <<<<<------------#######");
let source = __dirname + '/build/';
// TODO Set the path to your webapp build
let destination = __dirname + '/../sandbox-server/target/sandbox';
let options = {
overwrite: true
};
fs.copy(source, destination, options, err => {
if (err) return console.error(err)
console.log('Copy build success!');
})
});
}
}
Example Source

Related

vue project not working when change the base url in index.html file to my website url

This is my index.html file
when I change the base url to my website domain "https://new.weservio.com/" this error appears
Uncaught TypeError: Failed to resolve module specifier "vue". Relative references must start with either "/", "./", or "../". when I try to import vue according to this solution https://microeducate.tech/importing-a-package-in-es6-failed-to-resolve-module-specifier-vue/ .other modules can't be resolved too.
<html lang='en'>
<head>
<meta charset='UTF-8' />
<link href='images/logo.png' rel='icon' />
<meta content='width=device-width, initial-scale=1.0' name='viewport' />
<link href='https://fonts.googleapis.com' rel='preconnect'>
<link crossorigin href='https://fonts.gstatic.com' rel='preconnect'>
<link href='https://fonts.googleapis.com/css2?family=Poppins:wght#300;400;500;700;900&family=Tajawal:wght#300;400;500;700;900&display=swap'
rel='stylesheet'>
<link href=' https://cdnjs.cloudflare.com/ajax/libs/vue/3.0.0-beta.14/vue.esm-browser.js' >
<title></title>
<!--
EDIT THE FOLLOWING CODE INSIDE THE BASE TAG
'http://localhost:3000/' ==> 'REPLACE IT WITH YOUR BASE URL'
-->
<base href='https://new.weservio.com/'>
</head>
<body class='rtl:font-tajawal font-poppins overflow-x-hidden'>
<div id='app'></div>
notice: when I leave the url as "http://localhost:3000/" and run the project locally with npm run dev .The website is working fine.
notice: This site was working correctly before on same domain url ,but I was tring to use ftp-simple extention on vs code to load automaticllay after save to server from my working directory .then the website is not working anymore .I don't know if this related.

Peerjs is not retrieved in vue js

I am trying to use peerjs in vue app. So I added the cdn script in vue index.html file's header like this.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta data-n-head="true" name="viewport" content="width=device-width, initial-scale=1.0">
<title>peer</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/peerjs/0.3.9/peer.min.js"></script>
</head>
<body>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>
Now in a components' mounted hook, I am doing this to just console the id
var peer1 = new Peer();
peer1.on('open', function(id) {
console.log('My peer1 ID is: ' + id);
});
Nothing happens.
I then created a simple html file and run that html file I was able to see the id.
Next I tired to see XHR tab, I see when running a plain html file, two ajax calls is sent and in the result an ID is returned. But in vue, there is nothing like this. All I get a socket that returns this values
{websocket: true, origins: ["*:*"], cookie_needed: false, entropy: 1058218289}
cookie_needed
:
false
entropy
:
1058218289
origins
:
[":"]
websocket
:
true
One more thing, peers js documentations says to use api key, but if I use api key nothing happens in vue or html. Without the key, in html file I get the id.
Anyone knows please help me. Thank you.

dart content_shell does not run browser http-client request

I have Linux Ubuntu 12.04LTS and I'm trying to make dart (sdk 1.17.1) test (0.12.13.+5) of such client-side code:
test.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>test</title>
<script type="application/dart" src="test.dart"></script>
<script src="packages/browser/dart.js"></script>
<script src="packages/test/dart.js"></script>
<link rel="x-dart-test" href="test.dart">
</head>
<body></body>
</html>
test.dart:
#TestOn('browser')
import 'package:http/browser_client.dart';
import 'package:test/test.dart';
void main() {
test('client.get', () {
var client = new BrowserClient();
return client.get('https://hacker-news.firebaseio.com')
.then((result) {
expect(result.statusCode, 200);
});
});
}
With
pub run test -p dartium test/test.dart
test passed OK and there is data exchange between test runner and remote server (firebaseio.com).
But with
pub run test -p content-shell test/test.dart
test failed by timeout and there is no any data exchange with remote server. Why? How to solve this problem?

(Dojo 1.10) URL returned by dojoLoader seems wrong/inconsistent, how can I configure this correctly?

We recently updated our server with signed certificates and changed the base URL from https://servername/ to https://servername.domain.info/ . This has broken module loading in Dojo and I can't seem to correct it. The current config looks like this:
var dojoConfig = {
async: true,
packages: [
{
name: "js",
location: location.pathname.replace(/\/[^/]+$/, "") + 'Scripts'
},
{
name: "widgets",
location: location.pathname.replace(/\/[^/]+$/, "") + 'Scripts/widgets'
},
{
name: "dgrid",
location: location.pathname.replace(/\/[^/]+$/, "") + 'Scripts/3.14/dgrid'
},
{
name: "dijit",
location: location.pathname.replace(/\/[^/]+$/, "") + 'Scripts/3.14/dijit'
}
]
};
This used to work, and it still works on my dev machine when the root URL is just 'localhost'. Looking at the errors in the console it seems to be trying to find the modules at https://servername/ instead of https://servername.domain.info/ and I've tried everything I could find to point it in the right direction, including setting baseUrl: 'https://servername.domain.info' explicitly. Anything I've tried results in different URL strings, sometimes just the pathname and no base URL, sometimes pathname plus protocol with no domain info, etc. For reference, I also tried just adding the server URL to each location's URL string and I get the same error that seems to drop all but the first word from the server domain name.
I'm not sure what I'm doing wrong and I'm baffled by what dojoLoader decides to drop. I've read and reread the documentation but not much is said about how the base URL is calculated as far as I can find, just stuff on how to set baseUrl in the config to something.
edit: Per the comment below, I realize more info is needed. I am using Visual Studio 2015 and publishing to Windows Server 2012 R2 running IIS (v7 iirc). It does look like maybe Visual Studio is messing with the URL somehow, Dojo is not to blame. I was able to work around it by editing the file directly on the server and setting a location URL for every package (and their dependencies). I'd still like to know why it's happening and how I can set it up correctly.
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>#ViewBag.Title - ProjectName</title>
<link rel="stylesheet" href="~/Content/font-awesome.min.css" />
<link rel="stylesheet" href="~/Content/jquery-ui-1.10.3.custom.css" />
<link rel="stylesheet" href="~/Scripts/3.14/esri/css/esri.css" />
<link rel="stylesheet" href="~/Content/bootstrap-datetimepicker.min.css" />
#Scripts.Render("~/bundles/modernizr")
<link rel="stylesheet" href="~/Content/map.css" />
#Styles.Render("~/Content/css")
</head>

Using (NEW) Famo.us Engine with RequireJS and EJS Templates

Before Famo.us completely changed their architecture I was developing some Apps using Famo.us, RequireJS, EJS Templates, Node and some other stuff.
But now when I come to replace the old Famo.us architecture with the new Famo.us 'Engine' I am getting errors - which tells me the architecture is wrong for the new approach - so wondered if you guys can help me.
Background
Server is Node.js, Express 4 and some other stuff
Client will be Famo.us, EJS Templates and some other stuff
The current approach is that the '/' Router calls an 'ejs' template.
index.ejs:
<!DOCTYPE HTML>
<html>
<head>
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1.0, maximum-scale=1.0, minimal-ui" />
<meta name="mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<link rel="stylesheet" type="text/css" href="/css/famous.css" />
<link rel="stylesheet" type="text/css" href="/css/style.css" />
</head>
<body>
<script data-main="/js/webmain.js" src="/js/vendor/requirejs/require.js"></script>
</body>
</html>
This worked fine with old Famo.us architecture...and would call the webmain.js script using RequireJS.
webmain.js:
/* globals require */
require.config({
baseUrl: "js",
nodeRequire: require,
paths: {
"famous": "vendor/famous",
"famous-flex": "vendor/famous-flex/src",
json2: "vendor/json2",
"requirejs": "vendor/requirejs/require",
"socketcluster": "vendor/socketcluster",
"ua-parser" : "vendor/ua-parser.min",
"uuid": "vendor/uuid"
}
});
require(["platform"]);
The 'platform.js' script would contain the following:
define('platform', function(require, exports, module) {
'use strict';
var Engine = require("famous/core/Engine");
var contentContext = Engine.createContext();
var Widget = require('app/widgets/DefaultWidget');
var mainView = new Widget();
var contextSize = [undefined, undefined];
contentContext.setPerspective(1);
Engine.nextTick(function() {
contextSize = contentContext.getSize();
mainView.setOptions({size: [contextSize[0], contextSize[1]]});
contentContext.add(mainView);
});
contentContext.on('resize', function(e) {
contextSize = contentContext.getSize();
if (mainView) mainView.setOptions({size: [contextSize[0]*1, contextSize[1]*1]});
}.bind(this));
});
But the new version of Famo.us will not work using this approach and I wanted to ask your thoughts as to why, or if there was another way they have not mentioned?
I have updated the Famou.us source code in 'vendor/famous' to use the 'Famo.us Engine' code from github. If I replace the old Famo.us code in the 'platform.js' script with new Famo.us code - like this:
define('platform', function(require, exports, module) {
'use strict';
var FamousEngine = require('famous/core/FamousEngine');
var DOMElement = require('famous/dom-renderables/DOMElement');
FamousEngine.init();
var scene = FamousEngine.createScene();
var node = scene.addChild();
var domEl = new DOMElement(node, {
content: 'Hello World',
properties: {
fontFamily: 'Arial'
}
});
});
I get the following errors:
Uncaught Error: Module name "Clock" has not been loaded yet for context: _. Use require([]) require.js:8
Uncaught Error: Module name "../utilities/CallbackStore" has not been loaded yet for context: _. Use require([]) require.js:8
Uncaught TypeError: Cannot read property 'init' of undefined platform.js:28
I guess I am trying to understand, when the RequireJS skeleton is pretty much the same, why it doesn't work? Why Famo.us is undefined, and why the new Famo.us architecture can break so much - and what the 'new' way of integrating famo.us would be?
I have asked questions on their 'slack' IRC but it doesn't seem to be a way to get answers and a really poor 'help'.
Any help would be greatly appreciated as I am really stuck from moving forward at the moment.
Thanks again.
Famo.us version 0.3.5 and earlier used RequireJS using AMD.
The new version 0.5.0+ uses the node.js flavor of CommonJS and uses Browserify to build a bundle of your javascript application for the browser.
The following from an Answer in this question sums it up. More about their similarities and differences in the answers.
RequireJS implements the AMD API (source).
CommonJS is a way of defining modules with the help of an exports object, that defines the module contents.