You need to sign in to do that
Don't have an account?
static list in apex
I created a static list in my apex class like this :
Static List<String> Storeitems = new List<String>();
Static List<Integer> Qty= new List<Integer>();
I am adding values in to it from my vf page like this :
<apex:commandLink action="{!addtolist}" value="Add to List">
<apex:param name="ProductId" value="{!prod.Id}"/>
</apex:commandLink>
And this is my function in apex class :
public pagereference addtolist(){
String ProductId = System.currentPageReference().getParameters().get('ProductId');
System.Debug('ProductId >>>>>>>>>>>>>>>>'+ProductId);
Storeitems.add(ProductId );
Qty.add(1);
System.Debug('StoreItems >>>>>>>>>>>>>>>>'+Storeitems.get(0));
System.Debug('Qty >>>>>>>>>>>>>>>>>>'+Qty.get(0));
Pagereference pg = new PageReference('/apex/SiteProducts');
pg.setredirect(true);
return pg;
}
But every time i am adding a new Productid in list , it shows the new one at list.get(0).
means its not appending it to existing one rather every time adding it as first element.
VF: SiteProducts
Class: SiteProductsCon
Static variables are transient, which means that they do not retain their value each time the page is refreshed or submitted. Remove the static keyword to make them non-transient.
After removing static also , list is not retaining the values.
Ok its working fine after removing pg.setredirect(true).
But when i am refreshing the page its again gone.
As i am making these pages for site
i cannot restrict usres to refresh the page.