Binding a controll parameter to a Porlet Include preference

Hello,

I need to implement a behavior but I’m facing some issues.Maybe I’m missing something.

I have a portlet view with a boolean variable (part of the pagebean).
This portlet view contains a Portlet Include control. I need to pass this variable to the portlet included.
So what I did is add a control parameter to Portlet Include Control and bound it to the boolean variable.
And then I’ve added a preference (of boolean type) in the included portlet with the same name of the Control Parameter.
But unfotunately, the preference doesn’t get the value of the boolean variable.(It’s value is null)

Am I missing something here? Can anyone help me please?

Thanks in advance.
Appreciate your help.

Hello,

I’s really a blocking point for me.
Can someone help on this please?

Thanks in advance.
Appreciate your help.

Reda

Did yoy add that boolean as a preference in the included portlet?

Did you try to use an “Import Template View” control instead.

Regards.
Norberto.

Hello Norberto,

Yes, I’ve already added the boolean preference in the included portlet with same name as the control parameter.
Normally, it should work with Include Portlet control as for the Import Template View.
I would have tried to replace the Include Portlet with Import Template View but the probem is that the Include Portlet control is used in like 50 task views, so i have to replace them all.

Any suggestions from your part?

Thanks in advance.

Apreciate your help.

Hello ,

I was doing some tests, and I’ve switched the type of my variable to a string.
And then Ive created a new preference in the included portlet of type string, and it worked fine.
I’ve ended by thinking that the problem comes from the boolean type of the variable, since I’ve followed the same steps in both implementations, only the type of the variable differes.

Can this be an issue of the control parameter, that it does not handle the boolean variables?

Appreciate your point of view.

Thanks in advance.

Yes, per the Portlet 1.0 specification, the value of portlet preferences are either a String or String data type. If you pass some other data type it would be ignored.

So you would want to pass the value as a string for the “Portlet Include” parameter.

The portlet managed bean getter method that was generated by CAF for that preference should take care of converting the string passed in back to a boolean for use in the binding expressions of your portlet UI.

Thank you Eric for your response.

I see your point but I don’t know how I’ll convert the preference to a boolean variable since it’s created as a string preference.
Do you mean I’ll have to use another variable or adapt the get method to convert the type?

The get method of the preference is as follow:

public String getMyVariable() throws Exception {
return (String) getPreferenceValue(“myVariable”,String.class);
}

Appreciate your help.

Thanks.

In adition of my previous post.

The variable to pass to the included portlet is of a Boolean type, so is it ok to bind it as a Boolean in the Control Paramter and then store it in a String preference ?

Thanks for your help.

Let me try to explain my response better:

In your portlets you can create your portlet preferences with the type specified as ‘Boolean’. All this is actually doing is changing how the getter and setter methods are generated in your portlet preferences managed bean. In the internal implementation details of the portlet property bag, the preference values are always stored as String or String.

You should see something like the following snippet in the portlet managed bean where the “getPreferenceValue(…)” call in the getter method is doing the work to convert the preference value from the String value that is stored and passed around to a Boolean object. This is just a convenience to make it easier to use the preference value from java code or in binding expressions.


	public Boolean getBooleanPrefOne() throws Exception {
		return (Boolean) getPreferenceValue("booleanPrefOne", Boolean.class);
	}

	public void setBooleanPrefOne(Boolean booleanPrefOne) throws Exception {
		setPreferenceValue("booleanPrefOne", booleanPrefOne);
	}

Now, in your source portlet where you are specifying the parameter that you want to send to the included portlet, that value must be sent as either a String or String to comply with the portlet 1.0 specification.

If your original “value” binding expression resolves to something other than a string like a boolean or number then one way to do make it a String is to let the expression language do the conversion by appending the boolean value to the end of an empty string.

For example:
If you previously specified the parameter value as something like this:

#{TestDefaultviewView.test.booleanPrefOne}

Change it to something like this so it resolves to a String instead of a boolean:

#{""}#{TestDefaultviewView.test.booleanPrefOne}

Basically the portlet include parameter is sent as a string, and then the target portlet usually already has the code that does the conversion from that string to a Boolean whenever the target portlet uses the “getter” method from the portlet managed bean.

Hopefully that makes sense.

Hello Eric,

Thank you very much. Your post was very helpful.

I’ve tried what you suggested, and it worked as expected.

I would have spent a lot of time trying to resolve this problem. Thanks again.