How to enable already disabled a4j:commandLink?
pro4nist Nov 21, 2010 1:40 PMHi. Please help me in this issue. I want to enable a4j:commandLink already disabled from backing bean (toDisableSaveLink = true).
<a4j:commandLink id="${itemIndex}Save"
action="#{bean.save}"
ajaxSingle="false" limitToList="true"
disabled="${bean.toDisableSaveLink}"
styleClass="#{bean.toDisableSaveLink ? 'linkDisabled' : 'linkEnabled'}"
reRender="contentTabPanell"
rendered="${bean.toRenderSaveLink}">
<h:graphicImage value="/images/Save.gif"
styleClass="#{bean.toDisableSaveLink ? 'linkDisabled' : 'linkImageEnabled'}"></h:graphicImage>
<h:outputText value="#{globalizationBean.label['save']}"
styleClass="#{bean.toDisableSaveLink ? 'linkDisabled' : 'linkEnabled'}"></h:outputText>
</a4j:commandLink>
I tried to do it per javascript function which change styleClasses for html components (<a> and childs: <img>, <span>) to EnabledClasses and change attribut onclick for the component <a> to the value which richfaces assigned when a4j:commandLink is enabled from backing bean.
function enabledSaveLink(saveLinkId)
{
var saveLink = document.getElementById(saveLinkId);
var stringOnClick = "A4J.AJAX.Submit(\'contentTabPanel',event," +
"{\'similarityGroupingId\':\'" + saveLinkId + "\'," +
"\'parameters\':{\'" + saveLinkId + "\':" +
"\'" + saveLinkId + "\'} } );return false;";
if(window.event) //IE
{
saveLink.onclick = new Function ('onclick', stringOnClick);
}
else //FF
{
for( var i = 0; i < saveLink.attributes.length; i++ )
{
if( saveLink.attributes[i].nodeName.toLowerCase() == 'onclick' )
{
saveLink.attributes[i].value = stringOnClick;
break;
}
}
}
saveLink.className = 'linkEnabled';
var childArray = saveLink.children;
for(var i=0; i<childArray.length; i++)
{
if(childArray[i].tagName.toLowerCase() == 'img')
{
childArray[i].className = 'linkImageEnabled';
}
else
{
childArray[i].className = 'linkEnabled';
}
}
}
In this case works only simple submit (toDisableSaveLink get/set) but action="#{bean.save}" does not works.
Please prompt, may be there is more simple way to do enable/disable a4j:commandLink on client?!