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。 –