我正在尝试设置 Portlet 首选项,而无需触摸 Portlet.xml。
这是我的端口:
-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";
}
}
然后,在我的 portlet 中,我有这个来获取值:
mylink= preferences.getValue("mylink", mylink);
if(null==mylink){
mylink= mydefaultUrl;
}
然后我可以使用我的链接
首先:portlet.xml 是使用默认 portlet 首选项的绝佳位置。
如果您出于某种原因绝对不希望这样做,当然您可以检查首选项是否null
,然后假设您的默认值。只需在检索 Portlet 首选项的任何地方执行此操作 - 在操作、呈现、事件或资源阶段。