You need to sign in to do that
Don't have an account?
Action method is not being called on one scenario. Why?
I am trying to build a custom dynamic lookup component. I have put this component in a form, choosing a record from object record list (from lookup) and lastly calling a method from commandButton to check record Id and name properly selected or not.
This is working fine when I am using it alone in a VF Page form. Getting the id and name what I am selecting in the method's system.debug(). But when I am trying this component multiple times in a PageBlockTable, it makes some problem. No issue on selecting record on each of this lookup. But when I am clicking the button to check all the lookups value in the controller's method, I found the method is not being called. In debug log, I couldn't even found the method name too.
I am providing my component, component controller, lookup page, component calling page and its cotroller.
// ==========================component ===============================================
<apex:component controller="mycompController">
<script>
function windowOpener(windowHeight, windowWidth, windowName, windowUri, lookupName, lookupId)
{
try{
var valueNm = document.getElementById(lookupName).value;
var valueId = document.getElementById(lookupId).value;
var centerWidth = (window.screen.width - windowWidth) / 2;
var centerHeight = (window.screen.height - windowHeight) / 2;
var windowUri = windowUri + '&providedValue=' + valueNm.ReplaceAll(" ", "_").ReplaceAll(" ", "_");
windowUri = windowUri + '&providedId=' + valueId;
newWindow = window.open(windowUri, windowName, 'scrollbars=yes,width=' + windowWidth +
',height=' + windowHeight +
',left=' + centerWidth +
',top=' + centerHeight);
newWindow.focus();
return newWindow.name;
}catch(e){
alert(e);
}
}
String.prototype.ReplaceAll = function(stringToFind, stringToReplace)
{
var temp = this;
var index = temp.indexOf(stringToFind);
while(index != -1)
{
temp = temp.replace(stringToFind,stringToReplace);
index = temp.indexOf(stringToFind);
}
return temp;
}
</script>
<apex:attribute name="data" description="This is the data value for the component." type="String" />
<apex:attribute name="type" description="This is the type for the component." type="String" required="true" default=" " />
<apex:attribute name="value" description="This is the value variable for the component." type="String" required="true" />
<apex:attribute name="valueId" description="This is the Id value for the Lookup component." type="String" />
<apex:attribute name="label" description="This is the label of the component." type="String" />
<apex:attribute name="required" description="This is the name of the component." type="Boolean" />
<apex:attribute name="fields" description="This is used for fields to be queried in Lookup" type="String"/>
<apex:attribute name="condition" description="This is used only condition required in Lookup" type="String"/>
<apex:outputPanel rendered="{!(type == 'Lookup')}">
<apex:inputText label="{!label}" value="{!value}" required="{!required}" id="lookupName"/>
<apex:inputHidden id="lookupId" value="{!valueId}"/>
<a title="Search" onclick="windowOpener(350, 650, 'Search', '/apex/LookupPage?Name={!$Component.lookupName}&Id={!$Component.lookupId}&ObjectAPI={!data}&ShowFields={!fields}&Condition={!condition}', '{!$Component.lookupName}', '{!$Component.lookupId}');">
<img class="lookupIcon" onmouseover="this.className = 'lookupIconOn';this.className = 'lookupIconOn';this.style.cursor = 'pointer';" onmouseout="this.className = 'lookupIcon';this.className = 'lookupIcon';" onfocus="this.className = 'lookupIconOn';" onblur="this.className = 'lookupIcon';" alt="Search" src="/s.gif"/>
</a>
</apex:outputPanel>
</apex:component>
// ==========================component controller =======================================
public class mycompController
{
public String searchText {get; set;}
public List<SObject> searchList {get; set;}
public Boolean showTable {get; set;}
public String table {get; set;}
public Map<String, String> searchNameIdMap = new Map<String, String>();
public mycompController()
{
searchText = '';
if(ApexPages.currentPage().getParameters().get('providedValue') != null && ApexPages.currentPage().getParameters().get('providedValue').trim() != '')
searchText = ApexPages.currentPage().getParameters().get('providedValue').trim().replaceAll('_', ' ');
if(ApexPages.currentPage().getParameters().get('providedId') != null && ApexPages.currentPage().getParameters().get('providedId').trim() != '')
searchNameIdMap.put(searchText, ApexPages.currentPage().getParameters().get('providedId').trim());
}
public void search()
{
System.debug('========>>'+ApexPages.currentPage().getParameters().get('ObjectAPI'));
String textName = ApexPages.currentPage().getParameters().get('Name');
String textId = ApexPages.currentPage().getParameters().get('Id');
String ObjectAPI = ApexPages.currentPage().getParameters().get('ObjectAPI');
String ShowFields = ApexPages.currentPage().getParameters().get('ShowFields');
String Condition = ApexPages.currentPage().getParameters().get('Condition');
String query = '';
table = '';
String queryFields = '';
if(ShowFields != null && ShowFields.trim() != '')
{
String tempQueryFields = '';
System.debug('----cond> '+tempQueryFields.toLowerCase().contains('id'));
if(!ShowFields.trim().toLowerCase().contains('id'))
{
tempQueryFields += 'Id, ';
}
if(!ShowFields.trim().toLowerCase().contains('name'))
{
tempQueryFields += 'Name, ';
}
tempQueryFields += ShowFields.trim();
queryFields = tempQueryFields;
}
else
queryFields = 'Id, Name';
query += 'select ' + queryFields + ' from ' + ObjectAPI;
if(Condition != null && Condition.trim() != '')
{
query += ' where ' + Condition; //.replaceAll(':', '=');
}
if(searchText != null && searchText.trim() != '')
{
if(query.contains(' where '))
query += ' and Name like \'%'+searchText+'%\'';
else
query += ' where Name like \'%'+searchText+'%\'';
if(searchNameIdMap.get(searchText) != null)
query += ' and Id = \'' + searchNameIdMap.get(searchText) + '\'';
}
query += ' order by Name limit 1000';
System.debug('------query> '+query);
Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
Map<String, Schema.SObjectField> M=new Map<String, Schema.SObjectField>();
M = gd.get(ObjectAPI).getDescribe().fields.getMap();
List<String> tableHeaderList = new List<String>();
List<String> tableDataList = new List<String>();
for(String val : queryFields.trim().split(','))
{
tableHeaderList.add(val.trim().replace('__c', '').replace('_', ' '));
tableDataList.add(val.trim());
}
table += '<table border="0" align="center" width="90%" id="lookupTable" class="tablesorter"><thead><tr>';
for(Integer i = 0; i < tableHeaderList.size(); i ++)
{
if(tableHeaderList[i].trim().toLowerCase() == 'id')
continue;
table += '<th>'+tableHeaderList[i]+'</th>';
}
table+='</tr></thead><tbody>';
searchList = database.query( query );
for(SObject u : searchList)
{
table += '<tr>';
Integer j = 0;
String lineId = '';
for(integer i = 0; i < tableDataList.size(); i ++)
{
if(i == 0 && tableDataList[i].trim().toLowerCase() == 'id')
{
lineId = String.valueOf(u.get(M.get(tableDataList[i])));
continue;
}
String val = '';
if(i == 1)
val = textName+':::'+textId+':::'+(u.get(M.get(tableDataList[i])) != null ? String.valueOf(u.get(M.get(tableDataList[i]))).replaceAll(' ', ' ').replaceAll('\'', '') : 'N/A')+':::'+lineId+':'+String.valueOf(u.get(M.get(tableDataList[i]))).replaceAll(' ', '_').replaceAll('\'', '');
if(j ++ == 0)
{
table += '<td>' +
'<a href="#" onclick=valueSetterCloser("'+val+'")>' +
'<span>' + String.valueOf(u.get(M.get(tableDataList[i]))).replaceAll('\'', '') + '</span>' +
'</a></td>';
}
else
table += '<td>' + (u.get(M.get(tableDataList[i])) != null ? String.valueOf(u.get(M.get(tableDataList[i]))).replaceAll('\'', '') : 'N/A') + '</td>';
}
table+='</tr>';
}
table+='</tbody></table>';
System.debug('------table> '+table);
}
}
//============================= calling page ==================================
<apex:page controller="ABCClass">
<apex:actionStatus id="wait">
<apex:facet name="start">Processing...</apex:facet>
</apex:actionStatus>
<apex:form >
<apex:pageBlock id="blk">
<apex:pageBlockTable value="{!tableContent}" var="curVal">
<apex:column >
<c:mycomp data="Contact" type="Lookup" value="{!curVal.val}" valueId="{!curVal.valId}" fields="Email, Phone" required="true" label="{!curVal.label}"/>
</apex:column>
</apex:pageBlockTable>
<!-- working fine -->
<!--<c:mycompdata="Contact" type="Lookup" value="{!curVal.val}" valueId="{!curVal.valId}" fields="Email, Phone" required="true" label="{!curVal.label}"/>-->
</apex:pageBlock>
<apex:commandButton value="Click" action="{!callM}" reRender="blk" status="wait" />
</apex:form>
</apex:page>
//=============================calling page controller ==========================
public class ABCClass
{
public String val {get; set;}
public String valId {get; set;}
public String val1 {get; set;}
public String valId1 {get; set;}
public Boolean chkVal {get; set;}
public String txtVal {get; set;}
public String txtAreaVal {get; set;}
public String pickVal {get; set;}
public List<MyClass> tableContent {get; set;}
public class MyClass
{
public String val {get; set;}
public String valId {get; set;}
public String label {get; set;}
public MyClass(String val, String valId, String label)
{
this.val = val;
this.valId = valId;
this.label = label;
}
}
public ABCClass()
{
val = '';
valId = '';
val1 = '';
valId1 = '';
chkVal = true;
txtVal = 'suman';
txtAreaVal = '';
pickVal = 'b';
tableContent = new List<MyClass>();
for(Integer i = 1; i <= 5; i ++)
{
tableContent.add(new MyClass('', '', 'My Lookup - '+i));
}
}
public void callM()
{
System.debug('------->>Lookup> '+val+', '+valId);
System.debug('------->>Lookup1> '+val1+', '+valId1);
System.debug('------->>Checkbox> '+chkVal);
System.debug('------->>Textbox> '+txtVal);
System.debug('------->>Textarea> '+txtAreaVal);
System.debug('------->>Picklist> '+pickVal);
for(MyClass mc : tableContent)
{
System.debug('------->>'+mc.label+'> '+mc.val+', '+mc.valId);
}
}
}
//============================= lookup page ==================================
<apex:page controller="DynamicComponentController" showHeader="false" sidebar="false" action="{!search}"> <apex:stylesheet value="{!URLFOR($Resource.TableSorter, '/TableSorter/themes/blue/style.css')}" /> <apex:includeScript value="{!URLFOR($Resource.TableSorter, '/TableSorter/js/jquery.js')}" /> <apex:includeScript value="{!URLFOR($Resource.TableSorter, '/TableSorter/js/jquery.tablesorter.js')}" /> <style> #wrapper {margin: 0 auto;width:1200px; margin-left:300px; } </style> <script> function valueSetterCloser(details) { //alert(details); var arr = details.split(":::") lookupName = arr[0] lookupId = arr[1] dataName = arr[2] dataId = arr[3] var arr1 = dataId.split(":") //alert(dataName+' => '+arr1[1]+', '+arr1[1].ReplaceAll("_", " ")); try{ top.window.opener.document.getElementById(lookupName).value=arr1[1].ReplaceAll("_", " "); //dataName; top.window.opener.document.getElementById(lookupId).value=arr1[0]; //dataId; top.window.opener.document.getElementById(lookupName).focus(); top.window.close(); } catch(e){alert(e);} } function abc() { document.getElementById('searchResultSection').innerHTML='{!table}'; $("#lookupTable").tablesorter({debug: true}); } window.onload=abc; String.prototype.ReplaceAll = function(stringToFind,stringToReplace) { var temp = this; var index = temp.indexOf(stringToFind); while(index != -1) { temp = temp.replace(stringToFind,stringToReplace); index = temp.indexOf(stringToFind); } return temp; } </script> <apex:sectionHeader title="Record Selector"/> <apex:pageBlock > <apex:form > <apex:pageBlockSection columns="1"> <apex:pageBlockSectionItem > <apex:outputLabel >Search For: </apex:outputLabel> <apex:outputPanel > <apex:inputText value="{!searchText}"/> <apex:commandButton value="Go" action="{!search}"/> </apex:outputPanel> </apex:pageBlockSectionItem> </apex:pageBlockSection> <div id="searchResultSection"> </div> </apex:form> </apex:pageBlock> </apex:page>
This is a huge one to debug . It would be better if you can simplify your problem .