RE: RE: JSP customization by using 'Dynamic includes' approach

txapeldot ., modified 2 Years ago. Junior Member Posts: 91 Join Date: 1/15/15 Recent Posts

Regarding the 'Dynamic includes' approach Liferay encourages to use for JSP customization, is it possible to add '<liferay-util:dynamic-include>' additional tags wherever you want within a .jsp file, or, on the contrary, are you forced to work with the '<liferay-util:dynamic-include>' tags included by default within the .jsp file?

Thanks.

thumbnail
Olaf Kock, modified 2 Years ago. Liferay Legend Posts: 6441 Join Date: 9/23/08 Recent Posts

You can totally add your own tags (or rather those tags with your own keys) - to Liferay's as well as to your own JSPs.

Personally, if I really really really have to override a JSP, I even prefer to leave the original JSP as unchanged as possible, and introduce everything I need in a dynamic include. Sometimes the nature of the change makes it work, sometimes it doesn't.

However, if adding a single DI is easy, typically writing a portlet filter is similarly easy. And that filter is - at least typically, for me - easier to maintain.

txapeldot ., modified 2 Years ago. Junior Member Posts: 91 Join Date: 1/15/15 Recent Posts

Thanks for your reply.

Maybe I didn't express myself correctly, I didn't talk about adding my own tags into a own JSP file but adding the '<liferay-util:dynamic-include>' tag in other places within a .jsp file of a Liferay portlet, other that the top and bottom places where they are already placed.

Just for setting out a concrete example, what I'm facing is the customization of the jsp(s) files in charge of displaying the documents in the Liferay's Documents & Media portlet. Let's suppose (on the basis that the documents are displayed on a table-displaying setting), I want to remove the 'status' column and I want to add an additional column showing a value from an expando (for instance).

I concluded (I might be wrong) it's not possible to accomplish the intended task on the basis of a 'Dynamic include' approach, mainly because I need to remove elements of a .jsp file.

Do you think the Liferay's'Portlet Filter' approach is valid for the intended task?

thumbnail
David H Nebinger, modified 2 Years ago. Liferay Legend Posts: 14933 Join Date: 9/2/06 Recent Posts

I would not use a portlet filter for this. The portlet filter needs to basically buffer the rendered response from the portlet, then it needs to manipulate it without breaking it...

It's a recipe for disaster.

Using the D&M as your example, you can see where the entries are being handled by the view_entries.jsp file. So if you added or removed columns, a JSP fragment bundle gets the job done.

It doesn't need to be overly complicated and have all kinds of "dynamic includes" to support changing the columns. Adding that in for your own implementation just makes things more complicated and is typically not something that users of your portlet will take advantage of.

You know how many "dynamic includes" I have written for my many years of Liferay development? Zero. They're typically at the wrong place, don't allow me to remove things that shouldn't be there and basically they have zero benefit to me as a customizer.

You know how many fragment bundles I have written? Too many to keep track of. If I need to manipulate a JSP, the fragment bundle is the right way to do it and the only way to have total control over what is changed.

You can promote this by decomposing a single page w/ all columns into individual JSP files that are included by a main one, or you can just have the table managed by a single JSP that's easy to override. Either way, it is better taking this route than trying to figure out what someone might want to do with a dynamic include.

txapeldot ., modified 2 Years ago. Junior Member Posts: 91 Join Date: 1/15/15 Recent Posts

As for the Portlet Filter based solution, I was thinking about trasforming the text-based response to an XML-based response, so that it can be easily manipulable; then, and once removed/added the intended/needed xml elements, converting the modified XML-based response to a text-based response to be sent to the client. But it might still be being a recipe for a disaster...

Regarding the Fragment Bundle based solution you propose, I see your point! And the idea of decomposing a single page into individual pages is more than an elegant solution. Thanks a lot.

thumbnail
txapeldot ., modified 2 Years ago. Liferay Legend Posts: 14933 Join Date: 9/2/06 Recent Posts

Dynamic includes work for Liferay JSPs that already support them. It allows you to inject code (typically at the top and bottom of the JSP page), but won't allow you to change the content of the JSP itself.

You can add dynamic includes to existing pages, but you'd need to use a fragment bundle to override the JSP to do that. And then you need to ask yourself, if I'm already doing a fragment bundle to change the JSP, why just insert a dynamic include when I can just put my changes directly in and be done with it?

Finally, you might also consider adding a dynamic include into your own JSP files. There's nothing wrong with that and may allow you to ship a portlet and let customizers have the chance to introduce JSP w/o having to override your portlet. But the use cases here are going to be pretty few, yeah? I mean, if you write a custom portlet you already have control over the JSP, so adding a dynamic include would only complicate your portlet, so you would only do this if you really needed that kind of flexibility.

txapeldot ., modified 2 Years ago. Junior Member Posts: 91 Join Date: 1/15/15 Recent Posts

Thank you very much for your reply.

Maybe my initial question was very general, and I think I should narrow it, because when I talk about customization of .jsp files, I mean customization of .jsp files of Liferay portlets. Setting out a concrete example, what I'm facing is the customization of the jsp(s) files in charge of displaying the documents in the Liferay's Documents & Media portlet.

Let's suppose (on the basis that the documents are displayed on a table-displaying setting), I want to remove the 'status' column and I want to add an additional column showing a value from an expando (for instance).

From your reply, I know I won't be allowed to change the content of the corresponding JSP, so the Liferay's 'Dynamic include' approach is not a valid approach for the intended task. Moreover, the '<liferay-util:dynamic-include>' tags are placed at the top and bottom of the JSP page, which is useless for the intended task.

In your opinion, what is the rigth approach I should embrace to accomplish the intended task? Maybe 'Fragment bundles'? BTW, when you say 'fragment bundle' you mean 'OSGi fragments', don't you? But this approach is discouraged by Liferay, isn't it?.

thumbnail
David H Nebinger, modified 2 Years ago. Liferay Legend Posts: 14933 Join Date: 9/2/06 Recent Posts

So the "liferay way" (if we could call it that) is to use a separate jsp(f) file for the column guys.

That way, if you needed to change the columns, a simple fragment bundle will get you there.

But again, I wouldn't do this for code that you own. I mean, you have the code for the original, just fix the original code and mark it as done.

This kind of thing is only useful when someone else, who doesn't have the code for the original, wants to affect their own changes. But separating it out to its own JSP means it can be easily changed (from the column perspective) to include/exclude what you want via a fragment bundle.

Personally, though, I'd forget all of this. I'd have portlet configuration set up so you could show/hide some columns and then leverage that configuration for the rendering of the portlet. If end users need some control over which columns are displayed, you can give them that ability without having them code up some sort of JSP solution to get the job done.

txapeldot ., modified 2 Years ago. Junior Member Posts: 91 Join Date: 1/15/15 Recent Posts

Hi David, thanks for your reply.

I'm really sorry but I don't see your point. You suggest I fix the original code, but the original code is the code of the Liferay's out-of-the-box Document and Media Portlet; it sounds kind a intimidating doing such a thing like that.

Since I'm a newcomer to world of the customization of Liferay's Portlets, I think I'm going to embrace the Fragment Bundle based solution. When I become a more experienced developer I'll come back to the portlet configuration based solution you propose. Thanks.