Reactjs 使用jsp集成进行响应
我无法在liferay portlet jsp中加载react bundle index.js。我正在做的是将我的react组件捆绑在index.js中,并尝试在liferay门户jsp中呈现该react组件,但在部署portlet时,我无法在liferay中看到我的react组件呈现 请找到my view.jspReactjs 使用jsp集成进行响应,reactjs,jsp,liferay,liferay-6,spring-portlet-mvc,Reactjs,Jsp,Liferay,Liferay 6,Spring Portlet Mvc,我无法在liferay portlet jsp中加载react bundle index.js。我正在做的是将我的react组件捆绑在index.js中,并尝试在liferay门户jsp中呈现该react组件,但在部署portlet时,我无法在liferay中看到我的react组件呈现 请找到my view.jsp <%@ include file="/WEB-INF/jsp/init.jsp" %> <!DOCTYPE html> <html lang=
<%@ include file="/WEB-INF/jsp/init.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
<b><liferay-ui:message key="react-springmvc-portlet.caption"/></b>
</head>
<body>
<div id="content"></div>
</body>
<script type="text/javascript" src="/dist/index.js"></script>
</html>
my index.html
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta charset="UTF-8">
<title>Grommet</title>
<meta name="description" content="" />
<meta name="fragment" content="!" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta name="mobile-web-app-capable" content="yes">
<link rel="shortcut icon" type="image/png" href="/img/shortcut-icon.png" />
<link rel="apple-touch-icon" sizes="196x196" type="image/png" href="/img/mobile-app-icon.png">
<link rel="stylesheet" type="text/css" href="/index.css">
<style>
body.loading {margin: 0px; width: 100vw; height: 100vh;
background-image: radial-gradient(circle at 50% 15%, #fff, #fff 30%, #ccc);
}
body.loading #content {
position: relative;
width: 100%;
height: 100%;
font-size: 0px;
}
body.loading #logo {
position: absolute; display: block; width: 140px; height: 140px;
top: calc(50vh - 70px); left: calc(50vw - 70px);
}
div.t {
display: inline-block;
box-sizing: border-box;
margin: 0px;
width: 10vw;
height: 10vh;
background-color: #e2e2e2;
}
div.t.on {
-webkit-animation: pulse 3s infinite linear alternate;
-moz-animation: pulse 3s infinite linear alternate;
animation: pulse 3s infinite linear alternate;
}
div.t.on:hover {
-webkit-animation: none;
background-color: #ccc;
}
@-webkit-keyframes pulse {
100% { background-color: #fff; }
}
@-moz-keyframes pulse {
100% { background-color: #fff; }
}
@keyframes pulse {
100% { background-color: #fff; }
</style>
</head>
<body class="loading">
<div id="content" tabindex="-1" style="outline: none;">
<svg id="logo" viewBox="0 0 182 182" version="1.1" role="img">
<path role="presentation"
d="M 91,91 m 0,-82 a 82,82 0 1,1 0,164 a 82,82 0 1,1 0,-164"
stroke-width="18" stroke="#865CD6" fill="none"></path>
</svg>
<script>
var c = document.getElementById("content");
for (var i = 0; i < 100; i += 1) {
c.insertAdjacentHTML('beforeend', '<div class="t off"></div>');
}
var timer = setInterval(function () {
var again = false;
if (document.body.classList.contains('loading')) {
var ts = c.querySelectorAll('div.t.off');
if (ts.length > 0) {
var index = Math.floor(Math.random() * ts.length);
ts[index].classList.remove('off');
ts[index].classList.add('on');
if (ts.length > 1) {
again = true;
}
}
}
if (! again) {
clearInterval(timer);
}
}, 100)
</script>
</div>
<script async src="/index.js"></script>
</body>
</html>
索环
车身承载{余量:0px;宽度:100vw;高度:100vh;
背景图像:径向梯度(50%15%的圆,#fff,#fff 30%,#ccc);
}
body.loading#内容{
位置:相对位置;
宽度:100%;
身高:100%;
字体大小:0px;
}
body.loading#徽标{
位置:绝对;显示:块;宽度:140px;高度:140px;
顶部:计算器(50vh-70px);左侧:计算器(50vw-70px);
}
t组{
显示:内联块;
框大小:边框框;
边际:0px;
宽度:10vw;
高度:10vh;
背景色:#E2;
}
电视台{
-webkit动画:脉冲3s无限线性交替;
-moz动画:脉冲3s无限线性交替;
动画:脉冲3s无限线性交替;
}
分区t.on:悬停{
-webkit动画:无;
背景色:#ccc;
}
@-webkit关键帧脉冲{
100%{背景色:#fff;}
}
@-moz关键帧脉冲{
100%{背景色:#fff;}
}
@关键帧脉冲{
100%{背景色:#fff;}
var c=document.getElementById(“内容”);
对于(变量i=0;i<100;i+=1){
c、 insertAdjacentHTML('beforeed','';
}
变量计时器=设置间隔(函数(){
var=假;
if(document.body.classList.contains('loading')){
变量ts=c.querySelectorAll('div.t.off');
如果(ts.length>0){
var index=Math.floor(Math.random()*ts.length);
ts[index].classList.remove('off');
ts[index].classList.add('on');
如果(ts.length>1){
再次=正确;
}
}
}
如果(!再次){
清除间隔(计时器);
}
}, 100)
根据您编写JSP的方式,并在JSP路径中包含/WEB-INF/
,我假设您正在使用Liferay 6.x
我无法完全帮助您做出反应,但可能会引导您走向正确的方向:
首先:在门户世界中,portlet的view.jsp不能有
、
和
标记,因为portlet只能作为页面的一部分呈现
接下来,验证view.jsp中的JS include-很可能会导致404错误:当view.jsp发送到浏览器时,其URL将与Liferay相关,而不是与插件的Web应用程序上下文相关。因此,您必须手动重新创建该上下文,在您的情况下是/dist/index.JS
。请使用浏览器的从中请求页面并进行调整的开发人员工具
处理此问题的最佳方法是只为需要包含在liferay-portlet.xml中的JS包含一个适当的声明。DTD可用并有良好的文档记录,以查找适当的项(例如,检查或搜索其他“javascript”事件,根据您使用的实际版本调整URL)
我不确定如何从index.js转换到index.html。再次-如果文件包含在页面中:您不需要
和
标记。如果它最终在iframe中呈现,则需要。再次检查开发人员工具中的404错误,以便您可以找出如何处理html文件