我正在尝试在gatein-resources.xml中为每个portlet引用JS scrips。 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中
<portlet>
<name>/jsp/example.jsp</name>
<module>
<script>
<name>pagination</name>
<path>/js/lib/modules/pagination.js</path>
</script>
</module>
</portlet>
编辑:
如果我只想从portlet使用它们中独立添加所有javascript资源,我可以像下面的代码片段一样添加所有这些资源吗? (我有多个共享不同javascript文件的jsp文件)。只是尝试最小化代码量/不确定哪个portlet使用哪个jsp文件,所以只是尝试一次添加所有这些。这些jsp文件是否需要添加到portlet.xml?我对这些jsp文件和portlet.xml中的.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
中的共享范围谢谢!
答案 0 :(得分:0)
您需要提供portlet名称,即portlet描述符中的名称( WEB-INF / 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 文件下,您可以按照自己的方式声明JS模块,但使用 portlet-name :
<?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-resources.xml (在内部使用RequireJS),即不需要手动调用脚本来使用<script>
元素。只需使用它。
如果您需要具有公共依赖项,在引用common时我们的意思是在portlet之间是通用的而不是 JSP 文件,您可以声明一个公共模块并在其下使用它所有需要它的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>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 AMD框架。