我正在尝试设置portlet首选项,而不触及portlet.xml.
这是我的portlet:
-myportletclass
-myportletjsp
-myconclass
-myconfjsp
Run Code Online (Sandbox Code Playgroud)
当我点击偏好时,我可以看到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";
}
}
Run Code Online (Sandbox Code Playgroud)
然后,在我的portlet中我得到了这个值:
mylink= preferences.getValue("mylink", mylink);
if(null==mylink){
mylink= mydefaultUrl;
}
Run Code Online (Sandbox Code Playgroud)
然后我可以使用mylink
首先:portlet.xml是一个拥有默认portlet首选项的好地方.
如果您出于某种原因绝对不想要这个,当然您可以检查首选项是否为null,然后假定您的默认值.只需在检索portlet首选项时执行此操作 - 在操作,渲染,事件或资源阶段.
| 归档时间: |
|
| 查看次数: |
2635 次 |
| 最近记录: |