2/15/2011

getElementByID and Liferay

If you ever used AlloyUIs aui:input or the equivalent Liferay Tag to render an input field, you will surely have noticed, that Liferay adds the portlet id to all ids of all elements on the page. This makes sure, that two portlets with the same ids can coexist on the same portlet page without interferring with each other.
But how do you address them in javascript ? 


Just use the following standard liferay tag:<portlet:namespace />


Example:



<aui:input name="name" type="text" id="someid"/>


This will render to :



<input class="aui-field-input aui-field-input-text"  id="_44_someid" name="_44_name"   type="text" value=""   />

To address this with javascript use the following snippet



ishcpElement = document.getElementById("<portlet:namespace />someid");



If you liked this tutorial it would be very nice, if you could click on some of the google ads you see on the right side. It helps me run this block and motivates me ;)

If you have any questions, feel free to leave a comment.