我试图引用gatein-resources.xml es.xml中每个portlet的JS脚本。https://docs.jboss.org/author/display/GTNPORTAL34/GDG-JavaScript+Resource+Management如何将它们引用到每个portlet?我试图使用portlet作用域,但不确定如何引用它们。是按名字还是按路线?即
在example.jsp中
<script src="<%=request.getContextPath()%>/js/lib/modules/pagination.js"></script>在gatein-resources.xml es.xml中
<portlet>
<name>/jsp/example.jsp</name>
<module>
<script>
<name>pagination</name>
<path>/js/lib/modules/pagination.js</path>
</script>
</module>
</portlet>编辑:
如果我只想独立地添加portlet使用它们的所有javascript资源,我可以像下面的片段那样添加所有这些资源吗?(我有多个jsp文件共享不同的javascript文件)。只是尽量减少代码的数量/不确定哪个portlet使用哪个jsp文件,所以只需要一次添加所有这些文件。这些jsp文件需要添加到portlet.xml中吗?我对这些jsp文件与portlet.xml中的portlet.xml portlet之间的区别感到困惑。这些jsp文件也是portlet吗?很抱歉我缺乏理解。
<scripts>
<name>first_resource</name>
<script>
<name>ABC_script</name>
<path>/abc.js</path>
</script>
<name>second_resource</name>
<script>
<name>XYZ_script</name>
<path>/xyz.js</path>
</script>
</scripts>或者也可以为上面列出的所有脚本添加标记。资源:https://docs.jboss.org/author/display/GTNPORTAL34/GDG-JavaScript+Resource+Management中的共享范围
谢谢!
发布于 2014-10-26 11:11:24
您需要提供portlet名称,即portlet描述符中的名称(WEB/portlet.xml)。它应该类似于下面的片段:
<?xml version="1.0" encoding="UTF-8"?>
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" version="2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd
http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd">
<portlet>
<description xml:lang="EN">A sample portlet</description>
<portlet-name>MyPortletName</portlet-name> <!-- This is the name to mention -->
<display-name xml:lang="EN">My Portlet</display-name>
<portlet-class>some.package.name.MyPortlet</portlet-class>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>view</portlet-mode>
</supports>
<portlet-info>
<title>Sample Portlet to showcase GateIn AMD modules</title>
</portlet-info>
</portlet>
</portlet-app>然后,在gatein-resources.xml es.xml文件下,您将按照您的方式声明JS模块,但是使用portlet名称的。
<?xml version="1.0" encoding="ISO-8859-1" ?>
<gatein-resources
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.gatein.org/xml/ns/gatein_resources_1_5 http://www.gatein.org/xml/ns/gatein_resources_1_5"
xmlns="http://www.gatein.org/xml/ns/gatein_resources_1_5">
<portlet>
<name>MyPortletName</name>
<module>
<script>
<name>pagination</name>
<path>/js/lib/modules/pagination.js</path>
</script>
</module>
</portlet>
</gatein-resources>当portlet容器注入portlet时,后者将非常小心地调用您声明为该portlet依赖项的所有必需模块(JS),它使用gatein-Resoures.xml(在内部使用RequireJS ),即不需要手动调用脚本使用<script>元素。就用它吧。
编辑
如果您需要有共同的依赖项,当提到公共时,我们指的是portlets而不是文件之间的公共,您可以声明一个公共模块并在所有需要它的portlets下使用它:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<gatein-resources
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.gatein.org/xml/ns/gatein_resources_1_5 http://www.gatein.org/xml/ns/gatein_resources_1_5"
xmlns="http://www.gatein.org/xml/ns/gatein_resources_1_5">
<portlet>
<name>MyPortletName1</name>
<depends>
<module>
<name>pagination</nam>
</module>
</depends>
</portlet>
<portlet>
<name>MyPortletName2</name>
<depends>
<module>
<name>pagination</nam>
</module>
</depends>
</portlet>
<module>
<name>pagination</name>
<script>
<path>/js/lib/modules/pagination.js</path>
</script>
</module>
</gatein-resources>当portlet容器注入时,将所有JS依赖项注入portlet,因此,在此portlet生命周期内返回的任何JSP页面都将被注入JS文件。没有必要向您声明任何JSP,因为所有这些都是在服务器端无缝地完成的,这要归功于GateIn框架。
https://stackoverflow.com/questions/26551002
复制相似问题