i'm trying to set portlet preferences, without touch the portlet.xml.
Here is my portlet :
-myportletclass
-myportletjsp
-myconclass
-myconfjsp
When I click on preferences, I can see the confjsp, wich display a form for my preferences. And, when I submit it, set the preferences to the values in the form.
But I don't have any default values, without modify the portlet.xml.
What shoul I add and where?
I saw some do it in the render of the config class, but it doesn't work their way.
Regards. Thank you.
edit : the way i set my preferences :
first, i have a simple form i my conf jsp, basic, no need to add it; Then, i have the 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";
}
}
And then, in my portlet i have this to get the value:
mylink= preferences.getValue("mylink", mylink);
if(null==mylink){
mylink= mydefaultUrl;
}
And then i can use mylink
First of all: portlet.xml is an excellent place to have default portlet preferences.
If you absolutely don't want this for some reason, of course you can check if the preference is null, then assume your defaults. Simply do this whereever you retrieve the portlet preferences - in the action-, render-, event- or resource-phase.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With