+ Start a Discussion
anup ramanup ram 

Actionfunction not called with param

Hi ,

actionfunction not called. whats the mistake. please correct me where i am doing mistake.

 

I dont know if i am in right approach. I am pulling out price from LIST of products user enters tjhe quantity and total amount to be displayed. I am using param and actionfunction to do it.

I dont know if it will work onchange for a row in the list.

  please guide me.

 

 

VF :

<apex:form > 

<apex:actionFunction id="paramcall" name="paramcall" action="{!totalcount}" rerender="my">

<apex:param name="f" value="" assignTo="{!a.prodprice}"/>

<apex:param name="q" value="" assignTo="{!a.quantity}"/>

</apex:actionfunction>

</apex:form>

 

  <apex:form id="my">

 

<apex:pageBlock > Enter Search Value :

<apex:inputText value="{!searchkey}"/> 

<apex:commandButton value="Search" action="{!priceproduct}"/>

 

<apex:pageblockTable value="{!prwrp}" var="a">

<apex:column headervalue="Selected"><apex:inputcheckbox value="{!a.issel}"/>

</apex:column>

<apex:column headervalue="Name" >{!a.prodname}

</apex:column>

<apex:column headerValue="unitprice">

          <apex:outputText id="unitPrice" value="{!a.prodprice}"/>

        </apex:column>

 

<apex:column headerValue="Quantity" >

<apex:inputtext id="quantity" value="{!a.quantity}" onchange="paramcall(yes!)"  />

 

</apex:column>

 

 

<apex:column headerValue="total">

          <apex:outputText id="total"/>{!a.totalamount}

        </apex:column>

</apex:pageblockTable>

 

Apex: 

public integer total{get;set;}

public integer f{get;set;}
public integer q{get;set;}
public pagereference totalcount()
{
total = f * q;
system.debug(' total ' + total);
return null;
}

asish1989asish1989

Hi

Please go through my post of this link.
http://boards.developerforce.com/t5/Apex-Code-Development/How-do-I-pass-value-of-apex-inputField-to-Custom-Controller/m-p/532931#M96614

 

Did this post answers your questions if so please mark it as solved and hit kudos icon for this post.

 

  Thanks

DaveHDaveH

I see a couple of things that could be wrong with your code.

 

1) In your action function declaration you have 2 params specified but when you call the paramcall() function you are only passing 1 argument.

2) using the onchange event on text inputs is not a valid cross browser solution and is only fired when the element is blurred. A better way to do it would be to use the onkeypress event and check for valid input in a handler JS function then call your action function if everything looks good.

3) Are the fields "prodprice" and quantity" defined for your custom object?

anup ramanup ram

I have still not found the solution. Please help me.

 

 

DaveHDaveH

Have you tried the suggestions above? Can you post the updated code? Did you check your console to see if you're getting any javascript errors?

anup ramanup ram

Yes I tried but I somehow missing on something... I am trying this for the first time ..

 Please help me with solving this...

 

 

apex controller code snippet :

 

 

public integer total{get;set;}
public integer f{get;set;}
public integer q{get;set;}
public pagereference totalcount()
{
f = integer.valueof(Apexpages.currentPage().getParameters().get('f'));
q = integer.valueof(Apexpages.currentPage().getParameters().get('q'));
total = f * q;
system.debug(' total ' + total);
return null;
}

 

 

vf page code:

 

 

<apex:page controller="pricefromproduct">

  <script type="text/javascript">

    function callActionMethod()

    {

    var f = document.getElementById("{!$Component.my.unitprice}").value;

    var q = document.getElementById("{!$Component.my.quantity}").value;

    /*Below Method is generated by "apex:actionFunction" which will call Apex Method "echoVal" */

    paramcall(f,q);

    }

    </script> 

 

  <h1>Congratulations price page</h1>

  This is your price page

<apex:form > 

 <apex:actionFunction id="paramcall" name="paramcall" action="{!totalcount}" rerender="my">

<apex:param name="f"  value=""/>

<apex:param name="q"  value=""/>

</apex:actionfunction>

</apex:form>

 

  <apex:form id="my">

 

<apex:pageBlock > Enter Search Value :

<apex:inputText value="{!searchkey}"/> 

<apex:commandButton value="Search" action="{!priceproduct}"/>

 

<apex:pageblockTable value="{!prwrp}" var="a">

<apex:column headervalue="Selected"><apex:inputcheckbox value="{!a.issel}"/>

</apex:column>

<apex:column headervalue="Name" >{!a.prodname}

</apex:column>

<apex:column headerValue="unitprice">

          <apex:outputText id="unitPrice" value="{!a.prodprice}"/>

        </apex:column>

 

<apex:column headerValue="Quantity">

<apex:inputtext id="quantity" value="{!a.quantity}" onkeypress="callActionMethod()"  />

 

</apex:column>

 

<apex:column headerValue="total">

          <apex:outputText id="total"/>{!total}

        </apex:column>

</apex:pageblockTable>

 

</apex:pageblock>

</apex:form>

</apex:page>

 

anup ramanup ram

I was able to calculate totalamount , JS is called and actionfunction is calling the controller

 

but i have a problem

 

how to assign the totalamount of that perticular row to the wrapperclass.

 

The return value is applying for all the rows of pageblocktable...

 

public class pricefromproduct

{

// where name like '%searchkey%'    select Id from product2 where name like '%searchkey%'

public pricefromproduct()

{

 

}

public string searchkey {get;set;}

public list<pricewrapper> prwrp {get;set;} {prwrp = new list<pricewrapper>();}

// public list<productlist> prod{get;set;} {prod = new list<productlist>();}

public pagereference priceproduct()

{

 list<product2> prod = [select id from product2 where name like :'%'+searchkey+'%'];

 system.debug('prod size' + prod.size());

// prolist = [select id,name from product__c where name like : '%'+searchkey+'%'];

 

list<pricebookentry> pricebk = [Select Id, Name, ProductCode, Pricebook2Id, UnitPrice From PricebookEntry where Product2Id in :prod and usestandardprice = false and isactive = true];

  /*  best way to remove duplicates from list

  list<string> pr = new list<string>{'james','smith','james'};

  set<string> myset = new Set<string>();

List<string> result = new List<string>();

myset.addAll(pr);

result.addAll(myset);

system.debug(' pr size before filter ' + pr.size() + '   after ' + result.size());

*/

system.debug('pricebook size' + pricebk.size());

for (pricebookentry pb : pricebk)

{

pricewrapper p = new pricewrapper();

p.prc = pb;

p.prodprice = integer.valueof(pb.unitprice);

p.prodname = pb.name;

 

prwrp.add(p);

}

return null;

}

public integer total{get;set;}

public integer f{get;set;}

public integer q{get;set;}

public pagereference totalcount()

{

f = integer.valueof(Apexpages.currentPage().getParameters().get('f'));

q = integer.valueof(Apexpages.currentPage().getParameters().get('q'));

total = f * q;

system.debug(' total ' + total);

 

return null;

}

public class pricewrapper

{

public pricebookentry prc{get;set;}

public integer prodprice{get;set;}

public string prodname{get;set;}

public boolean issel {get;set;}

public integer quantity{get;set;}

public integer totalamount{get;set;}

 

public pricewrapper()

{

 

}

}

 

}