2014-01-28 53 views
2

在Liferay中,配置操作類是在liferay-portlet.xml中定義的 問題是,如果我使用任何彈簧依賴注入,它不起作用。Liferay配置操作類 - 彈簧依賴注入

<portlet> 
    <portlet-name>search</portlet-name> 
    <icon>/icon.png</icon> 
    <configuration-action-class>com.mypack.MyConfigurationAction</configuration-action-class> 
    <header-portlet-css>/css/main.css</header-portlet-css> 
    <footer-portlet-javascript>/js/main.js</footer-portlet-javascript> 
    <css-class-wrapper>search-portlet</css-class-wrapper> 
    <add-default-resource>true</add-default-resource> 
</portlet> 

Action類實現

public class MyConfigurationAction extends DefaultConfigurationAction { 

    private @Value("${test.property1}") String property1; 
    private @Value("${test.property2}") String property2; 
} 

如何注入這些屬性到這個Action類,而不使用ClassPathXmlApplicationContext和硬編碼spring.xml文件中的類

回答

2

有兩種方式保存在Portlet開發[在Liferay中]喜好,

  1. 通過Liferay的具體方式,其採用的Liferay-portlet.xml的條目。不能用春天來管理。

  2. JSR-286 [portal agnostic],portlet編輯模式。

使用Spring MVC框架開發portlet時,建議使用portlet編輯模式。

在Spring MVC portlet框架中,可以通過portlet模式映射portlet請求。

例如:創建控制器類,如下所示,它將映射到編輯模式請求。

@Controller 
@RequestMapping("EDIT") 
public class PreferencesController 

用兩種方法,一種方法與註釋@RenderMapping,負責視圖和其他方法與註釋@的ActionMapping/@ RequestMapping負責存儲偏好。

希望這會有所幫助。

+0

我在portlet.xml中啓用了編輯模式,並按照您的說法完成。但是這個類沒有被調用。只有當我點擊配置時,請求總是以VIEW模式發送。如果我點擊首選項,它就完全生成異常,並且沒有調用控制器 – Reddy

+1

不,你必須單擊首選項,以及什麼異常它的生成 –

1

試試這個

portlet.xml 

<supports> 
..... 
<portlet-mode>edit</portlet-mode> 
</supports> 

控制器類

@Controller 
@RequestMapping(value = "EDIT") 
public class XYZ{ 
} 

HTH

0

首先,「配置」不是「編輯」模式。如果您啓用編輯模式(如其他人所建議的那樣),您將在您的portlet菜單中獲得「首選項」按鈕。這是一項Liferay功能,您可以根據您的要求進行覆蓋。

我自己沒有嘗試過這個,但是你可以嘗試使用@Autowired來AutoWire你的MyConfigurationAction類(如果需要的話可以使用@Required註解?)。如果尚未完成,請不要忘記將<context:annotation-config/>放入applicationContext.xml文件中。

+1

第一件事情是配置類[bean]不是由Spring創建的,因此Spring不能注入任何依賴關係,即使你用任何註釋標記,並把額外的條件 – Reddy

+0

我想你自己回答它。如果我能找到一種方法來實現這一點,我也檢查了Liferay源碼,但是該類由EditConfigurationAction類實例化。所以它不會以這種方式工作。 –