3
我試圖設置portlet首選項,而不需要觸摸portlet.xml。設置默認的portlet首選項
這裏是我的portlet:
-myportletclass
-myportletjsp
-myconclass
-myconfjsp
當我點擊的喜好,我可以看到confjsp,至極顯示形式爲我的喜好。而且,當我提交它時,將首選項設置爲表單中的值。
但我沒有任何默認值,沒有修改portlet.xml。
我要添加什麼和在哪裏?
我看到一些在配置類的渲染,但它不工作的方式。
問候。 謝謝。
編輯:我把我的喜好的方式:
第一,我有一個簡單的形式,我在我的conf JSP,基本的,沒有必要添加它; 然後,我有ConfController:
@Controller
@RequestMapping("EDIT")
public class ConfigurationController {
@ModelAttribute("validatePref")
public ValidatePrefForm getValidatePrefForm() {
ValidatePrefForm form = new ValidatePrefForm();
return form;
}
@ActionMapping(params = "action=validatePref")
public void processAction(@ModelAttribute("validatePref") ValidatePrefForm form,
PortletPreferences portletPreferences, ActionResponse response)
throws Exception {
String mylink = form.getMylink();
if (null != mylink && !mylink .equals("")) {
portletPreferences.setValue("mylink ", mylink);
}
portletPreferences.store();
}
@RenderMapping
public String render() throws Exception {
return "myportletjsp.jsp";
}
}
,然後在我的門戶我有這樣得到的數值:
mylink= preferences.getValue("mylink", mylink);
if(null==mylink){
mylink= mydefaultUrl;
}
,然後我可以使用myLink的
但在第二種方式,似乎當我添加一個新的portlet實例時,它保留了我爲portlet設置的首選項已經在頁面中。我該如何解決這個問題:當我在頁面中擁有portlet時,有默認值。謝謝。編輯:如果可能,我prefere方式不使用portlet.xml,但我不排除它。 –
@Jean:你如何設定你的偏好?因爲我認爲portlet首選項是爲添加到頁面的每個portlet實例設置的,而不是整個portlet或用戶。 Liferay還爲首選項設置默認值,您可以檢查Liferay的內置Portlet的'init.jsp'(如果有源代碼的話)。 –
我爲你編輯我的問題Prakash。 –