Fórumok
JSF portlet generating different Id for different environment
siddharth mishra, módosítva 11 év-val korábban
JSF portlet generating different Id for different environment
Junior Member Bejegyzések: 31 Csatlakozás dátuma: 2010.01.06. Legújabb bejegyzések
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.
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, módosítva 11 év-val korábban
RE: JSF portlet generating different Id for different environment (Válasz)
Liferay Master Bejegyzések: 894 Csatlakozás dátuma: 2009.02.18. Legújabb bejegyzések
Hi Siddharth,
you should never hard-code the element ids because as you see they can change .
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
you should never hard-code the element ids because as you see they can change .
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, módosítva 11 év-val korábban
RE: JSF portlet generating different Id for different environment
Junior Member Bejegyzések: 31 Csatlakozás dátuma: 2010.01.06. Legújabb bejegyzések
Hi Oliver,
Yes how silly of me to use hardcoded ids..so i implemented it using ajax calls like you mentioned.
Thanks,
Sid
Yes how silly of me to use hardcoded ids..so i implemented it using ajax calls like you mentioned.
Thanks,
Sid
Oliver Bayer, módosítva 11 év-val korábban
RE: JSF portlet generating different Id for different environment
Liferay Master Bejegyzések: 894 Csatlakozás dátuma: 2009.02.18. Legújabb bejegyzések
Hi Siddharth,
no problem, I'm glad I could help . 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
no problem, I'm glad I could help . 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