Liferay以编程方式从文件导入来宾布局
我试图通过创建一个在启动钩子()中扩展SimpleAction的类,将一些来宾布局从中的larFile(从另一个实例导出)导入到liferay实例(可以是已安装的\u和\u配置的,也可以是新安装的)然后在portal-ext.properties文件中将“application.startup.events”指向此类。我希望每次服务器启动时都能运行这个程序,因为我的larFile版本可能会随着时间的推移而改变。我的代码如下Liferay以编程方式从文件导入来宾布局,liferay,Liferay,我试图通过创建一个在启动钩子()中扩展SimpleAction的类,将一些来宾布局从中的larFile(从另一个实例导出)导入到liferay实例(可以是已安装的\u和\u配置的,也可以是新安装的)然后在portal-ext.properties文件中将“application.startup.events”指向此类。我希望每次服务器启动时都能运行这个程序,因为我的larFile版本可能会随着时间的推移而改变。我的代码如下 File larFile=new File("/Users/grai00
File larFile=new File("/Users/grai001/Desktop/default_guest_public_new_light.lar");
//using absolute path for now -need help in accessing the relative path to ${liferay.home}??
Group guestGroup = GroupLocalServiceUtil.getGroup(1, GroupConstants.GUEST);
LayoutLocalServiceUtil.importLayouts(guestGroup.getCreatorUserId(), guestGroup.getGroupId(), false, new HashMap<String,String[]>(), larFile);
//I want them to be a public layouts which are visible to every one even when a user is not logged in - like the default WHAT-WE-DO kind ofpages in liferay6.1 - I am using 6.1GA2 at both ends
现在执行LayoutLocalServiceUtil.importLayouts(guestGroup.getCreatorUserId(),guestGroup.getGroupId(),true,new HashMap(),larFile)代码>
ie…将它们作为私有布局导入工作正常-不幸的是,我希望它们是公开的,并且对每个人都可见。同时以门户管理员和
从UI导入公共布局效果良好。我多么希望以自动化的方式完成此操作
在过去的一周里,我一直在努力解决这个问题——做了足够的研究——但仍然无法解决。感谢您的任何帮助
提前感谢public void larTest(){
public void larTest() {
LiferayFacesContext liferayFacesContext = LiferayFacesContext
.getInstance();
ActionRequest request = (ActionRequest) liferayFacesContext
.getPortletRequest();
ThemeDisplay td = (ThemeDisplay) request
.getAttribute(WebKeys.THEME_DISPLAY);
long userId = td.getUserId();
long groupId = td.getScopeGroupId();
File larFile=new File("C:\\Users\\youssef\\dahar\\Downloads\\ok.lar");
//using absolute path for now -need help in accessing the relative path to ${liferay.home}??
Group guestGroup = null;
try {
guestGroup = GroupLocalServiceUtil.getGroup(groupId);
} catch (Exception e) {
System.out.println("catch 1");
e.printStackTrace();
}
try {
LayoutLocalServiceUtil.importLayouts(guestGroup.getCreatorUserId(), guestGroup.getGroupId(), false, new HashMap<String,String[]>(), larFile);
} catch (PortalException e) {
System.out.println("catch 2");
e.printStackTrace();
} catch (SystemException e) {
System.out.println("catch 3");
e.printStackTrace();
}
//I want them to be a public layouts which are visible to every one even when a user is not logged in - like the default WHAT-WE-DO kind ofpages in liferay6.1 - I am using 6.1GA2 at both ends
}
LiferayFacesContext LiferayFacesContext=LiferayFacesContext
.getInstance();
ActionRequest=(ActionRequest)liferayFacesContext
.getPortletRequest();
主题显示td=(主题显示)请求
.getAttribute(WebKeys.THEME_显示);
long userId=td.getUserId();
long groupId=td.getScopeGroupId();
File larFile=新文件(“C:\\Users\\youssef\\dahar\\Downloads\\ok.lar”);
//现在使用绝对路径-需要帮助访问${liferay.home}的相对路径吗??
组guestGroup=null;
试一试{
guestGroup=GroupLocalServiceUtil.getGroup(groupId);
}捕获(例外e){
系统输出打印项次(“第1条”);
e、 printStackTrace();
}
试一试{
LayoutLocalServiceUtil.importLayouts(guestGroup.getCreatorUserId()、guestGroup.getGroupId()、false、new HashMap()、larFile);
}捕获(PortalException e){
System.out.println(“第二条军规”);
e、 printStackTrace();
}捕获(系统异常e){
系统输出打印项次(“第3条”);
e、 printStackTrace();
}
//我希望它们是一个公共布局,每个人都可以看到,即使用户没有登录-就像liferay6.1中默认的“我们做什么”页面一样-我在两端都使用6.1GA2
}
可能是可以帮助您完成此功能
它有时对我有效,有时对我无效:)您可能希望检查根本原因stacktrace(因为它将给出实际的NullpointerException位置)或调试到此过程中。如果您有一个钩子,那么您很可能可以在调试器中运行它—向其中添加Liferay源代码,并在点击导入例程(断点)后,在NullpointerException上设置一个异常断点。这将给你一些其他的想法去看。你必须按照Olaf Kock的建议调试NullPonterException。在LayoutLocalServiceUtil.importLayouts中(guestGroup.getCreatorUserId()、guestGroup.getGroupId()、true、new HashMap()、larFile);将第三个参数作为false传递以导入到public中。几天前,我们终于能够对其进行远程调试。问题是我用paramsMap传递了一些参数(记不清了)。你们找到解决方案了吗?我也有类似的问题。
public void larTest() {
LiferayFacesContext liferayFacesContext = LiferayFacesContext
.getInstance();
ActionRequest request = (ActionRequest) liferayFacesContext
.getPortletRequest();
ThemeDisplay td = (ThemeDisplay) request
.getAttribute(WebKeys.THEME_DISPLAY);
long userId = td.getUserId();
long groupId = td.getScopeGroupId();
File larFile=new File("C:\\Users\\youssef\\dahar\\Downloads\\ok.lar");
//using absolute path for now -need help in accessing the relative path to ${liferay.home}??
Group guestGroup = null;
try {
guestGroup = GroupLocalServiceUtil.getGroup(groupId);
} catch (Exception e) {
System.out.println("catch 1");
e.printStackTrace();
}
try {
LayoutLocalServiceUtil.importLayouts(guestGroup.getCreatorUserId(), guestGroup.getGroupId(), false, new HashMap<String,String[]>(), larFile);
} catch (PortalException e) {
System.out.println("catch 2");
e.printStackTrace();
} catch (SystemException e) {
System.out.println("catch 3");
e.printStackTrace();
}
//I want them to be a public layouts which are visible to every one even when a user is not logged in - like the default WHAT-WE-DO kind ofpages in liferay6.1 - I am using 6.1GA2 at both ends
}