Setting portlet size on Runtime

You might have worked with setting size of a portlet on page from portal admin.If not, have a look at Setting Size of portlet on page.
But, did you ever think about setting portlet size on Runtime?

Here i tell you how you can set your portlet size on Runtime with these steps...
In short, this machanism will require you to change your applied/current skin jsp and putting 2 lines of javascript code to your portlet jsp, and that's it you are done...

Here you go....

1) Open UnlayeredContainer-H.jsp, located under
<WP-Profile>/installedApps//wps.ear/wps.war/skins/html/<Skin Name>
Here i am making changes to IBM skin.

2) Add an id for the first table element on this file.
for example:- <table id="neerajtableid" class="layoutRow" cellpadding="0" cellspacing="0">

3) Save the file.

4) In your portlet JSP, get the table element with the ID and get the rows and cell of portlet and set the width.

For me, i have kept two portlets on pages and page property is set to two columns container.

Java script code to be written on your portlet jsp's.

<script language="javascript">
var tableElement = document.getElementById("neerajtableid");


tableElement.rows[0].cells[1].width = "37%";
</script>

Here, rows[0].cell[1] shows portlet placed on first row second column, which is horizontally second portlet.

No comments: