function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SachinSankadSachinSankad 

Clear function not working properly

Hi All,

 

I want to clear two picklist values & one textfield value on click event of command link.

 

I have used actionFunction to call controllers method to clear the fields.

 

But whenever i click clear link on VF page, values vanish for 1-2 sec & again previous values are set in picklists as well as textfield.

 

I want to implement it through Apex only.

 

Can anybody tell me possible reason for this??

 

Thanks

Sachin.

swatKatswatKat

Why havent u used the action property of the command link to call the controller method ? Just use the action and rerender your field section. 

SachinSankadSachinSankad

Hi swatkat,

 

Thank you for your reply.

 

As i want to clear row by passing it's index from VF page, I didn't use action property of the commandlink.

 

So i need to use actionfunction with param tag passing index to it & using same in controller's method.

 

Do you have any solution for this??

 

Thanks,

Sachin.

 

 

swatKatswatKat

You can use apex param within the command link tag as well. Like this :

 

<apex:commandLink id="commandLink" action="{!displayName}" value="Show my name">
<apex:param name="Name" value="myName"/>
</apex:commandLink>

 

Bhawani SharmaBhawani Sharma
Create a variable to hold the index in controller. User aprx;param tag and bind that variable using addignTo attribute.
Now in action method, get property from index variable and clear it.
listVariable[Integer.valueOf(index_variable)].PicklistField__c = null;
listVariable[Integer.valueOf(index_variable)].TextField__c = null;

Rerender your section
SachinSankadSachinSankad

Hi Bhawani,

 

Thanks for your solution.

 

I tried it but it's not working for me.

 

I am using inner class. Here by I am pasting my clear function & inner class as well.

 

Clear function :- 

 

public void clear()
{
System.debug('>>>>>>>>>>>>>>>In Clear<<<<<<<<<<<<<<<<<');
Integer indexCount = Integer.valueOf(ApexPages.currentPage().getParameters().get('index'));
//clearmap=new map<string,string>();
System.debug('>>>>>>>>>>>>>>>>Size of list<<<<<<<<<<<<<<<<<'+lstInner.size());
for(innerClass clearobj:lstInner)
{
System.debug('****************In For loop of clear function******************');
System.debug('>>>>>>>>>>>>Value of recCount<<<<<<<<<<<<'+clearobj.recCount);

System.debug('>>>>>>>>>>>>Value of indexCount<<<<<<<<<<<<'+indexCount);
if(indexCount == clearobj.recCount)
{
System.debug('================In if loop of clear function================');
//clearmap.put(clearobj.field,clearobj.value);
//fieldopermap.put(clearobj.field,clearobj.operator);

System.debug('=======Field before clearing======='+clearobj.field);
clearobj.field='--None--';
System.debug('=======Field after clearing======='+clearobj.field);
System.debug('=======Operator before clearing======'+clearobj.operator);
clearobj.operator='';
System.debug('=======Operator after clearing======'+clearobj.operator);
System.debug('=======Value before clearing======='+clearobj.value);
clearobj.value='';
System.debug('=======Value after clearing======='+clearobj.value);
}
}
}

 

Inner Class :-

public class innerClass
{
/*recCount acts as a index for a row. This will be helpful to identify the row to be deleted */
public Integer recCount{get;set;}
public string field;
public string operator;
public string value;
public list<SelectOption> supportedoperator{get;set;}
public String getfield()
{
return field;
}

public void setfield(String new1)
{
field=new1;
//operaterlist.add(new1);
// system.debug('operaterlist<<<<<<<<<<<<<'+operaterlist);
}

public String getoperator()
{
return operator;
}

public void setoperator(String new2)
{
operator=new2;
// system.debug('selected field list<<<<<<<<<<<<<'+SelectedFieldlist);
}

public String getvalue()
{
return value;
}

public void setvalue(String new3)
{
value=new3;
// Valuelist.add(new3);
}

/*Inner Class Constructor*/
public innerClass(Integer intCount)
{
system.debug('<<<<<<<<<inside inner class construnctor<<<<<<<<<<');
recCount = intCount;
}/*End Inner class Constructor*/
}/*End inner Class*/

 

VF Page :-

<apex:page controller="GDCDelete" sidebar="false">
<apex:form id="formId">
<apex:actionFunction name="ObjectFileds" action="{!ObjectFields}" reRender="block"/>
<apex:actionFunction name="oper" action="{!op}" rerender="block">
<apex:param name="index" value=""/>
</apex:actionFunction>
<apex:actionFunction name="clear1" action="{!clear}" rerender="formId">
<apex:param name="index" value=""/>
</apex:actionFunction>
<!-- <apex:actionFunction name="oper1" action="{!op1}"> -->
<!-- </apex:actionFunction> -->
<apex:sectionHeader title="Ultra Data Analyzer"/>
<apex:pageBlock id="block">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Select Object:</b>
<apex:selectList multiselect="false" size="1" value="{!SelectedObject}" onChange="ObjectFileds();">
<apex:selectoptions value="{!supportedObject}" />
</apex:selectlist>
<table>
<tr>
<th> </th>
<th>Field</th>
<th>Operator</th>
<th>Value</th>
</tr>
<apex:repeat value="{!lstInner}" var="e1" id="therepeat">
<tr>

<td>
<h3>{!e1.recCount}.</h3>
</td>
<td>
<apex:selectList id="selectionBlock" multiselect="false" style="width:150px;" size="1" value="{!e1.field}" onChange="oper('{!e1.recCount}');" disabled="{!isDisabled}">
<apex:selectoptions value="{!supportedFields}" />
</apex:selectlist>
</td>

<td>
<apex:selectList size="1" style="width:150px;" value="{!e1.operator}" disabled="{!isDisabled}">
<apex:selectOptions value="{!e1.supportedoperator}" />
</apex:selectList>
</td>


<td>
<apex:inputText value="{!e1.value}" disabled="{!isDisabled}"/>
</td>

<td>
<apex:commandbutton value="delete" action="{!delete1}" rerender="block" disabled="{!isDisabled}">
<apex:param name="rowToBeDeleted" value="{!e1.recCount}" assignTo="{!selectedRowIndex}" ></apex:param>
</apex:commandButton>
</td>

<td>
<apex:commandlink value="Clear" onclick="clear1('{!e1.recCount}');" reRender="block" />
</td>

</tr>
</apex:repeat>
</table>

</apex:pageblock>

</apex:form>

</apex:page>

 

Please help to solve this issue.

Bhawani SharmaBhawani Sharma
Can you put your debug log also ?
SachinSankadSachinSankad

Hi Bhawani,

 

Here is my debug log.

 

Thanks,

Sachin

 

12:09:40.042 (42679000)|CODE_UNIT_STARTED|[EXTERNAL]|01p90000002kqEh|GDCDelete invoke(clear)
12:09:40.042 (42730000)|SYSTEM_MODE_ENTER|false
12:09:40.042 (42769000)|SYSTEM_METHOD_ENTRY|[393]|System.debug(ANY)
12:09:40.042 (42789000)|USER_DEBUG|[393]|DEBUG|>>>>>>>>>>>>>>>In Clear<<<<<<<<<<<<<<<<<
12:09:40.042 (42798000)|SYSTEM_METHOD_EXIT|[393]|System.debug(ANY)
12:09:40.042 (42812000)|SYSTEM_METHOD_ENTRY|[394]|ApexPages.currentPage()
12:09:40.042 (42903000)|SYSTEM_METHOD_EXIT|[394]|ApexPages.currentPage()
12:09:40.042 (42930000)|SYSTEM_METHOD_ENTRY|[394]|System.PageReference.getParameters()
12:09:40.042 (42999000)|SYSTEM_METHOD_EXIT|[394]|System.PageReference.getParameters()
12:09:40.043 (43037000)|SYSTEM_METHOD_ENTRY|[394]|MAP<String,String>.get(Object)
12:09:40.043 (43057000)|SYSTEM_METHOD_EXIT|[394]|MAP<String,String>.get(Object)
12:09:40.043 (43075000)|SYSTEM_METHOD_ENTRY|[394]|Integer.valueOf(String)
12:09:40.043 (43085000)|SYSTEM_METHOD_EXIT|[394]|Integer.valueOf(String)
12:09:40.043 (43102000)|METHOD_ENTRY|[396]|01p90000002kqEh|GDCDelete.__sfdc_lstInner()
12:09:40.043 (43119000)|METHOD_EXIT|[396]|01p90000002kqEh|GDCDelete.__sfdc_lstInner()
12:09:40.043 (43187000)|SYSTEM_METHOD_ENTRY|[396]|LIST<GDCDelete.innerClass>.size()
12:09:40.043 (43199000)|SYSTEM_METHOD_EXIT|[396]|LIST<GDCDelete.innerClass>.size()
12:09:40.043 (43220000)|SYSTEM_METHOD_ENTRY|[396]|String.valueOf(Object)
12:09:40.043 (43231000)|SYSTEM_METHOD_EXIT|[396]|String.valueOf(Object)
12:09:40.043 (43247000)|SYSTEM_METHOD_ENTRY|[396]|System.debug(ANY)
12:09:40.043 (43253000)|USER_DEBUG|[396]|DEBUG|>>>>>>>>>>>>>>>>Size of list<<<<<<<<<<<<<<<<<1
12:09:40.043 (43259000)|SYSTEM_METHOD_EXIT|[396]|System.debug(ANY)
12:09:40.043 (43266000)|METHOD_ENTRY|[397]|01p90000002kqEh|GDCDelete.__sfdc_lstInner()
12:09:40.043 (43280000)|METHOD_EXIT|[397]|01p90000002kqEh|GDCDelete.__sfdc_lstInner()
12:09:40.043 (43290000)|SYSTEM_METHOD_ENTRY|[397]|LIST<GDCDelete.innerClass>.iterator()
12:09:40.043 (43533000)|SYSTEM_METHOD_EXIT|[397]|LIST<GDCDelete.innerClass>.iterator()
12:09:40.043 (43562000)|SYSTEM_METHOD_ENTRY|[397]|system.ListIterator.hasNext()
12:09:40.043 (43592000)|SYSTEM_METHOD_EXIT|[397]|system.ListIterator.hasNext()
12:09:40.043 (43622000)|SYSTEM_METHOD_ENTRY|[399]|System.debug(ANY)
12:09:40.043 (43637000)|USER_DEBUG|[399]|DEBUG|****************In For loop of clear function******************
12:09:40.043 (43644000)|SYSTEM_METHOD_EXIT|[399]|System.debug(ANY)
12:09:40.043 (43663000)|METHOD_ENTRY|[400]|01p90000002kqEh|GDCDelete.innerClass.__sfdc_recCount()
12:09:40.043 (43691000)|METHOD_EXIT|[400]|01p90000002kqEh|GDCDelete.innerClass.__sfdc_recCount()
12:09:40.043 (43706000)|SYSTEM_METHOD_ENTRY|[400]|String.valueOf(Object)
12:09:40.043 (43716000)|SYSTEM_METHOD_EXIT|[400]|String.valueOf(Object)
12:09:40.043 (43726000)|SYSTEM_METHOD_ENTRY|[400]|System.debug(ANY)
12:09:40.043 (43732000)|USER_DEBUG|[400]|DEBUG|>>>>>>>>>>>>Value of recCount<<<<<<<<<<<<1
12:09:40.043 (43737000)|SYSTEM_METHOD_EXIT|[400]|System.debug(ANY)
12:09:40.043 (43749000)|SYSTEM_METHOD_ENTRY|[402]|String.valueOf(Object)
12:09:40.043 (43764000)|SYSTEM_METHOD_EXIT|[402]|String.valueOf(Object)
12:09:40.043 (43775000)|SYSTEM_METHOD_ENTRY|[402]|System.debug(ANY)
12:09:40.043 (43779000)|USER_DEBUG|[402]|DEBUG|>>>>>>>>>>>>Value of indexCount<<<<<<<<<<<<1
12:09:40.043 (43785000)|SYSTEM_METHOD_EXIT|[402]|System.debug(ANY)
12:09:40.043 (43795000)|METHOD_ENTRY|[403]|01p90000002kqEh|GDCDelete.innerClass.__sfdc_recCount()
12:09:40.043 (43807000)|METHOD_EXIT|[403]|01p90000002kqEh|GDCDelete.innerClass.__sfdc_recCount()
12:09:40.043 (43822000)|SYSTEM_METHOD_ENTRY|[405]|System.debug(ANY)
12:09:40.043 (43832000)|USER_DEBUG|[405]|DEBUG|================In if loop of clear function================
12:09:40.043 (43839000)|SYSTEM_METHOD_EXIT|[405]|System.debug(ANY)
12:09:40.043 (43856000)|SYSTEM_METHOD_ENTRY|[409]|System.debug(ANY)
12:09:40.043 (43866000)|USER_DEBUG|[409]|DEBUG|=======Field before clearing=======BillingCity
12:09:40.043 (43872000)|SYSTEM_METHOD_EXIT|[409]|System.debug(ANY)
12:09:40.043 (43888000)|SYSTEM_METHOD_ENTRY|[411]|System.debug(ANY)
12:09:40.043 (43898000)|USER_DEBUG|[411]|DEBUG|=======Field after clearing=======
12:09:40.043 (43904000)|SYSTEM_METHOD_EXIT|[411]|System.debug(ANY)
12:09:40.043 (43918000)|SYSTEM_METHOD_ENTRY|[412]|System.debug(ANY)
12:09:40.043 (43929000)|USER_DEBUG|[412]|DEBUG|=======Operator before clearing======equals
12:09:40.043 (43938000)|SYSTEM_METHOD_EXIT|[412]|System.debug(ANY)
12:09:40.043 (43957000)|SYSTEM_METHOD_ENTRY|[414]|System.debug(ANY)
12:09:40.043 (43968000)|USER_DEBUG|[414]|DEBUG|=======Operator after clearing======
12:09:40.043 (43974000)|SYSTEM_METHOD_EXIT|[414]|System.debug(ANY)
12:09:40.043 (43989000)|SYSTEM_METHOD_ENTRY|[415]|System.debug(ANY)
12:09:40.043 (43998000)|USER_DEBUG|[415]|DEBUG|=======Value before clearing=======pune
12:09:40.044 (44004000)|SYSTEM_METHOD_EXIT|[415]|System.debug(ANY)
12:09:40.044 (44022000)|SYSTEM_METHOD_ENTRY|[417]|System.debug(ANY)
12:09:40.044 (44032000)|USER_DEBUG|[417]|DEBUG|=======Value after clearing=======
12:09:40.044 (44038000)|SYSTEM_METHOD_EXIT|[417]|System.debug(ANY)
12:09:40.044 (44047000)|SYSTEM_METHOD_ENTRY|[397]|system.ListIterator.hasNext()
12:09:40.044 (44060000)|SYSTEM_METHOD_EXIT|[397]|system.ListIterator.hasNext()
12:09:40.044 (44068000)|SYSTEM_MODE_EXIT|false
12:09:40.044 (44103000)|CODE_UNIT_FINISHED|GDCDelete invoke(clear)
12:09:40.044 (44139000)|VF_APEX_CALL|j_id4|{!clear}|PageReference: none
12:09:40.049 (49575000)|CODE_UNIT_STARTED|[EXTERNAL]|01p90000002kqEh|GDCDelete get(lstInner)
12:09:40.049 (49590000)|SYSTEM_MODE_ENTER|true
12:09:40.049 (49599000)|CODE_UNIT_STARTED|[EXTERNAL]|01p90000002kqEh|lstInner
12:09:40.049 (49612000)|CODE_UNIT_FINISHED|lstInner
12:09:40.049 (49618000)|CODE_UNIT_FINISHED|GDCDelete get(lstInner)
12:09:40.049 (49973000)|CODE_UNIT_STARTED|[EXTERNAL]|01p90000002kqEh|GDCDelete get(slst)
12:09:40.049 (49983000)|SYSTEM_MODE_ENTER|true
12:09:40.049 (49990000)|CODE_UNIT_STARTED|[EXTERNAL]|01p90000002kqEh|slst
12:09:40.050 (50000000)|CODE_UNIT_FINISHED|slst
12:09:40.050 (50006000)|CODE_UNIT_FINISHED|GDCDelete get(slst)
12:09:40.052 (52182000)|CODE_UNIT_STARTED|[EXTERNAL]|01p90000002kqEh|GDCDelete get(supportedObject)
12:09:40.052 (52194000)|SYSTEM_MODE_ENTER|true
12:09:40.052 (52202000)|CODE_UNIT_STARTED|[EXTERNAL]|01p90000002kqEh|supportedObject
12:09:40.052 (52213000)|CODE_UNIT_FINISHED|supportedObject
12:09:40.052 (52219000)|CODE_UNIT_FINISHED|GDCDelete get(supportedObject)
12:09:40.052 (52380000)|CODE_UNIT_STARTED|[EXTERNAL]|01p90000002kqEh|GDCDelete get(SelectedObject)
12:09:40.052 (52390000)|SYSTEM_MODE_ENTER|true
12:09:40.052 (52397000)|CODE_UNIT_STARTED|[EXTERNAL]|01p90000002kqEh|SelectedObject
12:09:40.052 (52406000)|CODE_UNIT_FINISHED|SelectedObject
12:09:40.052 (52412000)|CODE_UNIT_FINISHED|GDCDelete get(SelectedObject)
12:09:40.053 (53094000)|CODE_UNIT_STARTED|[EXTERNAL]|01p90000002kqEh|recCount
12:09:40.053 (53109000)|CODE_UNIT_FINISHED|recCount
12:09:40.053 (53148000)|CODE_UNIT_STARTED|[EXTERNAL]|01p90000002kqEh|GDCDelete get(supportedFields)
12:09:40.053 (53155000)|SYSTEM_MODE_ENTER|true
12:09:40.053 (53161000)|CODE_UNIT_STARTED|[EXTERNAL]|01p90000002kqEh|supportedFields
12:09:40.053 (53170000)|CODE_UNIT_FINISHED|supportedFields
12:09:40.053 (53176000)|CODE_UNIT_FINISHED|GDCDelete get(supportedFields)
12:09:40.053 (53336000)|CODE_UNIT_STARTED|[EXTERNAL]|01p90000002kqEh|GDCDelete get(isDisabled)
12:09:40.053 (53345000)|SYSTEM_MODE_ENTER|true
12:09:40.053 (53352000)|CODE_UNIT_STARTED|[EXTERNAL]|01p90000002kqEh|isDisabled
12:09:40.053 (53362000)|CODE_UNIT_FINISHED|isDisabled
12:09:40.053 (53367000)|CODE_UNIT_FINISHED|GDCDelete get(isDisabled)
12:09:40.053 (53401000)|CODE_UNIT_STARTED|[EXTERNAL]|01p90000002kqEh|innerClass invoke(getfield)
12:09:40.053 (53456000)|CODE_UNIT_FINISHED|innerClass invoke(getfield)
12:09:40.054 (54570000)|CODE_UNIT_STARTED|[EXTERNAL]|01p90000002kqEh|supportedoperator
12:09:40.054 (54584000)|CODE_UNIT_FINISHED|supportedoperator
12:09:40.054 (54703000)|CODE_UNIT_STARTED|[EXTERNAL]|01p90000002kqEh|innerClass invoke(getoperator)
12:09:40.054 (54746000)|CODE_UNIT_FINISHED|innerClass invoke(getoperator)
12:09:40.054 (54905000)|CODE_UNIT_STARTED|[EXTERNAL]|01p90000002kqEh|innerClass invoke(getvalue)
12:09:40.054 (54950000)|CODE_UNIT_FINISHED|innerClass invoke(getvalue)
12:09:40.056 (56141000)|CODE_UNIT_STARTED|[EXTERNAL]|01p90000002kqEh|GDCDelete get(isBtnDisabled)
12:09:40.056 (56153000)|SYSTEM_MODE_ENTER|true
12:09:40.056 (56161000)|CODE_UNIT_STARTED|[EXTERNAL]|01p90000002kqEh|isBtnDisabled
12:09:40.056 (56171000)|CODE_UNIT_FINISHED|isBtnDisabled
12:09:40.056 (56177000)|CODE_UNIT_FINISHED|GDCDelete get(isBtnDisabled)
12:09:40.057 (57859000)|VF_SERIALIZE_VIEWSTATE_BEGIN|06690000002faIb
12:09:40.087 (87788000)|VF_SERIALIZE_VIEWSTATE_END
12:09:40.725 (725755000)|CODE_UNIT_STARTED|[EXTERNAL]|Generate Metadata
12:09:40.923 (923890000)|CODE_UNIT_FINISHED|Generate Metadata
12:09:41.719 (940705000)|CUMULATIVE_LIMIT_USAGE
12:09:41.719|LIMIT_USAGE_FOR_NS|(default)
Avidev9Avidev9

You doesnt seem to be have used to assignTo with params in ur code

 

<apex:actionFunction name="clear1" action="{!clear}" rerender="formId">
         <apex:param name="index" value="" assignTo="{!variableName}"/>
      </apex:actionFunction>