草庐IT

java - Liferay portlet 中没有编辑模式

coder 2024-04-02 原文

我正在关注 Liferay In Action 一书。我正处于向 portlet 添加编辑模式的部分。 portlet 部署成功,我已经添加了 portlet,现在书上说单击 portlet 中的 Spanner 并单击首选项链接,但我没有首选项链接。 View 工作正常。

这是我的portlet.xml:

<?xml version="1.0"?>

<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" 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" version="2.0">
<portlet>
    <portlet-name>hello-john</portlet-name>
    <display-name>Hello John</display-name>
    <portlet-class>com.liferaytest.portlet.HelloJohnPortlet</portlet-class>
    <init-param>
        <name>view-jsp</name>
        <value>/view.jsp</value>
    </init-param>
    <init-param>
        <name>edit-jsp</name>
        <value>/edit.jsp</value>
    </init-param>
    <expiration-cache>0</expiration-cache>
    <supports>
        <mime-type>text/html</mime-type>
        <portlet-mode>view</portlet-mode>
        <portlet-mode>edit</portlet-mode>
    </supports>
    <portlet-info>
        <title>Hello John</title>
        <short-title>Hello John</short-title>
        <keywords>Hello John</keywords>
    </portlet-info>
    <security-role-ref>
        <role-name>administrator</role-name>
    </security-role-ref>
    <security-role-ref>
        <role-name>guest</role-name>
    </security-role-ref>
    <security-role-ref>
        <role-name>power-user</role-name>
    </security-role-ref>
    <security-role-ref>
        <role-name>user</role-name>
    </security-role-ref>
</portlet>

我的edit.jsp:

<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>

<jsp:useBean class="java.lang.String" id="addNameURL" scope="request" />

<portlet:defineObjects />

<form 
id ="<portlet:namespace />helloForm" 
action="<%= addNameURL %>" 
method="post">
<table>
    <tr>
        <td>Name:</td>
        <td><input type="text" name ="username"></td>
    </tr>
</table>
<input type="submit" id="nameButton" title="Add Name" value="Add Name">
</form>

我的 doEdit 方法:

public void doEdit(RenderRequest renderRequest, RenderResponse renderResponse)
    throws IOException, PortletException {
    renderResponse.setContentType("text/html");
    PortletURL addNameURL = renderResponse.createActionURL();
    addNameURL.setParameter("addName", "addName");
    renderRequest.setAttribute("addNameURL", addNameURL.toString());
    include(editJSP, renderRequest, renderResponse);
}

最佳答案

要在 Liferay 的 portlet 中拥有首选项(配置)页面,您必须实现 com.liferay.portal.kernel.portlet.ConfigurationAction 接口(interface)并在 liferay-portlet.xml 中配置 portlet 以使用您的类.

<portlet>
  <portlet-name>MyPortlet</portlet-name>
  <configuration-action-class>com.mydomain.myportlet.ClassThatImplementsConfigurationAction</configuration-action-class>
  <instanceable>false</instanceable>
  ...
</portlet>

您还应该知道,在那个类中,您是在 Liferay 的配置 portlet 中,而不是您的 portlet。所以得到喜欢的偏好

portletRequest.getPreferences();

产生 Liferay-s 配置 portlet 的首选项。

要获取您的 portlet 的首选项,请将此方法添加到您的类中

protected PortletPreferences getPortletPreferences(final PortletRequest p_portletRequest) throws Exception {
    String portletResource = ParamUtil.getString(p_portletRequest, "portletResource");
    PortletPreferences prefs = PortletPreferencesFactoryUtil.getPortletSetup(p_portletRequest, portletResource);
    return prefs;
}

并从已实现的方法中调用它

public void processAction(PortletConfig portletConfig, ActionRequest actionRequest,
        ActionResponse actionResponse) throws Exception;

public String render(PortletConfig portletConfig, RenderRequest renderRequest,
        RenderResponse renderResponse) throws Exception;

关于java - Liferay portlet 中没有编辑模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9266619/

有关java - Liferay portlet 中没有编辑模式的更多相关文章

  1. ruby-on-rails - Rails - 子类化模型的设计模式是什么? - 2

    我有一个模型:classItem项目有一个属性“商店”基于存储的值,我希望Item对象对特定方法具有不同的行为。Rails中是否有针对此的通用设计模式?如果方法中没有大的if-else语句,这是如何干净利落地完成的? 最佳答案 通常通过Single-TableInheritance. 关于ruby-on-rails-Rails-子类化模型的设计模式是什么?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.co

  2. ruby-on-rails - Rails 编辑表单不显示嵌套项 - 2

    我得到了一个包含嵌套链接的表单。编辑时链接字段为空的问题。这是我的表格:Editingkategori{:action=>'update',:id=>@konkurrancer.id})do|f|%>'Trackingurl',:style=>'width:500;'%>'Editkonkurrence'%>|我的konkurrencer模型:has_one:link我的链接模型:classLink我的konkurrancer编辑操作:defedit@konkurrancer=Konkurrancer.find(params[:id])@konkurrancer.link_attrib

  3. ruby - 解析 RDFa、微数据等的最佳方式是什么,使用统一的模式/词汇(例如 schema.org)存储和显示信息 - 2

    我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i

  4. ruby - 难道Lua没有和Ruby的method_missing相媲美的东西吗? - 2

    我好像记得Lua有类似Ruby的method_missing的东西。还是我记错了? 最佳答案 表的metatable的__index和__newindex可以用于与Ruby的method_missing相同的效果。 关于ruby-难道Lua没有和Ruby的method_missing相媲美的东西吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/7732154/

  5. ruby-on-rails - rails 目前在重启后没有安装 - 2

    我有一个奇怪的问题:我在rvm上安装了ruby​​onrails。一切正常,我可以创建项目。但是在我输入“railsnew”时重新启动后,我有“程序'rails'当前未安装。”。SystemUbuntu12.04ruby-v"1.9.3p194"gemlistactionmailer(3.2.5)actionpack(3.2.5)activemodel(3.2.5)activerecord(3.2.5)activeresource(3.2.5)activesupport(3.2.5)arel(3.0.2)builder(3.0.0)bundler(1.1.4)coffee-rails(

  6. ruby - 如何在续集中重新加载表模式? - 2

    鉴于我有以下迁移:Sequel.migrationdoupdoalter_table:usersdoadd_column:is_admin,:default=>falseend#SequelrunsaDESCRIBEtablestatement,whenthemodelisloaded.#Atthispoint,itdoesnotknowthatusershaveais_adminflag.#Soitfails.@user=User.find(:email=>"admin@fancy-startup.example")@user.is_admin=true@user.save!ende

  7. ruby - 在没有 sass 引擎的情况下使用 sass 颜色函数 - 2

    我想在一个没有Sass引擎的类中使用Sass颜色函数。我已经在项目中使用了sassgem,所以我认为搭载会像以下一样简单:classRectangleincludeSass::Script::FunctionsdefcolorSass::Script::Color.new([0x82,0x39,0x06])enddefrender#hamlengineexecutedwithcontextofself#sothatwithintemlateicouldcall#%stop{offset:'0%',stop:{color:lighten(color)}}endend更新:参见上面的#re

  8. java - 等价于 Java 中的 Ruby Hash - 2

    我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/

  9. java - 从 JRuby 调用 Java 类的问题 - 2

    我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www

  10. 没有类的 Ruby 方法? - 2

    大家好!我想知道Ruby中未使用语法ClassName.method_name调用的方法是如何工作的。我头脑中的一些是puts、print、gets、chomp。可以在不使用点运算符的情况下调用这些方法。为什么是这样?他们来自哪里?我怎样才能看到这些方法的完整列表? 最佳答案 Kernel中的所有方法都可用于Object类的所有对象或从Object派生的任何类。您可以使用Kernel.instance_methods列出它们。 关于没有类的Ruby方法?,我们在StackOverflow

随机推荐