Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
siddharth mishra
JSF portlet generating different Id for different environment
March 22, 2013 1:25 AM
Answer

siddharth mishra

Rank: Junior Member

Posts: 31

Join Date: January 6, 2010

Recent Posts

I am creating a dynamic form which hides/unhides fields based on selection of radio buttons. I was using normal javascript function as given below which is working fine in my portal environment(the ids are the JSF ids which i get by viewing source).

function printHiddenValue(){
alert("hello");
alert(document.getElementById('A1938:j_idt4:create-ticket:hiddenId').value);
if(document.getElementById('A1938:j_idt4:create-ticket:j_idt19:0').checked){
alert("incident sellected")
} else
{
alert("change sellected")

}

}

but fails when i deploy the war in different environment as differnrt ids are generated by the portal environment.
Oliver Bayer
RE: JSF portlet generating different Id for different environment
March 22, 2013 2:34 AM
Answer

Oliver Bayer

Rank: Liferay Master

Posts: 869

Join Date: February 18, 2009

Recent Posts

Hi Siddharth,

you should never hard-code the element ids because as you see they can change emoticon.

Use "<portlet:namespace />" or "<%= PortalUtil.getPortletNamespace(portletResource) %>" instead to get the id of the current portlet dynamically. Take a look at the ootb portlets like e.g. in "html \ portlet \ document_library \ configuration.jsp".

In JSF you can also write ajax calls to hide/ unhide elements of your form - which is the easier job to do I think. What you have to do is write a method which sets a boolean variable e.g. to false. Add a condition to the element you want to hide by using "rendered="myBean.shouldThisElementBeHidden"".

HTH Oli
siddharth mishra
RE: JSF portlet generating different Id for different environment
March 25, 2013 11:57 PM
Answer

siddharth mishra

Rank: Junior Member

Posts: 31

Join Date: January 6, 2010

Recent Posts

Hi Oliver,

Yes how silly of me to use hardcoded ids..so i implemented it using ajax calls like you mentioned.

Thanks,
Sid
Oliver Bayer
RE: JSF portlet generating different Id for different environment
March 26, 2013 2:18 AM
Answer

Oliver Bayer

Rank: Liferay Master

Posts: 869

Join Date: February 18, 2009

Recent Posts

Hi Siddharth,

no problem, I'm glad I could help emoticon. One thing I should have mentioned: You should add the "update" attribute to the element causing the ajax request and pass in the jsf id of the element you want to hide. If you have any other questions feel free to ask again.

Greets Oli