Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set default portlet Preferences

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

like image 342
provençal le breton Avatar asked Apr 21 '26 14:04

provençal le breton


1 Answers

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.

like image 136
Olaf Kock Avatar answered Apr 28 '26 06:04

Olaf Kock