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
BALA_RAMBALA_RAM 

when i'm select the "add" button that Record will display another Visualforce page

Please give me help.

 

My visualforce page view

                                               dropdown Product Family     & Search "Button"

                                                          TextBox                           & Search "Button"  

 

When i click Search button it will display List of Records[List View] Every record Has Add "Button".

When i'm clic Add button how can I display the Recod into another visualforce page

 

<apex:page controller="Stringdisplay">
<apex:form id="myForm">
<apex:actionFunction name="productSearch" action="{!AddtoCart}" >
<apex:param name="ab" value="" assignTo="{!getCartID}" />
</apex:actionFunction>
<!--<apex:actionFunction name="displayContacts" action="{!getdisplayName}" reRender="myForm" />-->
<!--<center align="Right">
<b><apex:commandLink value="+Add New Product" action="/01t/e?retURL=%2F01t%2Fo"/></b></center>-->
<apex:pageBlock >
<center>
Search by Product Category<p/>
<apex:selectList size="1" value="{!strSelAccount}" onclick="displayContacts()">
<apex:selectOptions value="{!distinctrecs}">
</apex:selectOptions>
</apex:selectList>
&nbsp;&nbsp;<apex:commandButton value="Search" action="{!getdisplayName}"/>
<p/>
<apex:selectRadio value="{!searchbutton}">
<apex:selectOptions value="{!Selectsearching}"/>
</apex:selectRadio>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<apex:inputText value="{!str}" size="30"/> &nbsp;&nbsp;
<apex:commandButton value="Search" action="{!submit}"/>
</center>
</apex:pageBlock>
<p/>
<apex:pageBlock rendered="{!renderFirst}">
<apex:outputPanel id="out1">
<apex:pageblockTable value="{!lstCon}" var="con" id="out">
<apex:column value="{!con.Productcode}" headerValue="Code"/>
<apex:column value="{!con.Family}" headerValue="Category"/>
<apex:column headerValue="Description">
<apex:commandLink value="{!con.Description}" action="{!redirect}">
<apex:param value="{!con.id}" assignTo="{!pid}" name="p1"/></apex:commandLink>
</apex:column>
<apex:column value="{!con.Servings_Container__c}" headerValue="Container"/>
<apex:column headerValue="Add to Cart">
<apex:commandButton value="Add" onclick="test('{!con.id}')"/>
</apex:column>
</apex:pageblockTable>
</apex:outputPanel>
</apex:pageBlock>
</apex:form>
<p/>
<apex:form >
<apex:pageBlock rendered="{!isdisplay}">
<apex:pageBlockTable value="{!showrecord}" var="record">
<apex:column headerValue="Code" value="{!record.ProductCode}"/>
<apex:column headerValue="Category" value="{!record.Family}"/>
<!--<apex:column headerValue="Name" Value="{!record.name}"/>-->
<apex:column headerValue="Description">
<apex:commandLink Value="{!record.Description}" action="{!redirect}">
<apex:param value="{!record.pid}" assignTo="{!pid}" name="p1"/></apex:commandLink>
</apex:column>
<apex:column headerValue="Container" value="{!record.container}"/>
<apex:column headerValue="Add to Cart">
<apex:commandButton value="Add" onclick="test('{!record.pid}')"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
<script>
function test(val)
{
alert(val);
window.open('/apex/Mycart?ide='+val);
//productSearch(val);
}
</script>
</apex:page>

 

 

Controller

 

public class Stringdisplay
{
public List<wraper> wrap {get;set;}
public string getCartID{get;set;}
public boolean isdisplay{get;set;}
public boolean renderFirst{get;set;}
//public list<wrapper> SelectedprodList{get;set;}
String str=null;
String myname,myphone,myFamily,myDescription,myProductCode,myContainer,myId;
public void setstr(String astr)
{
this.str=astr;
}
public String getstr()
{
return null;
}
public PageReference submit()
{
isdisplay=true;
renderFirst = false;
return null;
}
Public PageReference AddtoCart()
{
//Stringdisplay sd = new Stringdisplay();
//system.debug('###'+getCartID);
//Product2 p =[Select Id,Name,Productcode from Product2 where Id=:ApexPages.currentPage().getParameters().get('Id')];
pageReference ref = new pageReference('/apex/Mycart?ide='+getCartID);
//ref.getParameters().put('Id',pid);
ref.setRedirect(true);
return ref;
}
public Stringdisplay()
{
isdisplay= false;
renderFirst = false;
//rendered= false;
}
public String searchbutton{get;set;}
public List<SelectOption> getSelectsearching()
{
List<SelectOption> options=new List<SelectOption>();
options.add( new SelectOption('Search by Description','Search by Description'));
options.add( new SelectOption('Search by Burger Maker Code','Search by Burger Maker Code'));
options.add( new SelectOption('Search by Sysco Code ','Search by Sysco Code'));

return options;
}

public List<wraper> getshowrecord()
{
String str3=str+'%';
if(searchbutton=='Search by Description')
{
List<product2> product=[select Id,Name,Description,Family,ProductCode,Servings_Container__c from Product2 where Description Like:str3];
wrap = new List<wraper>();
for(product2 a1:product)
{
myname = a1.name;
myFamily = a1.Family;
myDescription=a1.Description;
myProductCode=a1.ProductCode;
myContainer=a1.Servings_Container__c;
myId=a1.Id;
wrap.add(new wraper(myname,myFamily,myDescription,myProductCode,myContainer,myId));
}
return wrap ;
}
if(searchbutton=='Search by Burger Maker Code')
{
List<product2> product=[select id,Name,Description,Family,ProductCode,Servings_Container__c from Product2 where ProductCode like:str3];
wrap = new List<wraper>();
for(product2 a1:product)
{
myname = a1.name;
myFamily = a1.Family;
myDescription=a1.Description;
myProductCode=a1.ProductCode;
myContainer=a1.Servings_Container__c;
myId=a1.Id;
wrap.add(new wraper(myname,myFamily,myDescription,myProductCode,myContainer,myId));
}
return wrap;
}
if(searchbutton=='Search by Sysco Code')
{
List<product2> product=[select Id,Name,Description,Family,ProductCode,Servings_Container__c from Product2];
wrap = new List<wraper>();
for(product2 a1:product)
{
myname = a1.name;
myFamily = a1.Family;
myDescription=a1.Description;
myProductCode=a1.ProductCode;
myContainer=a1.Servings_Container__c;
myId=a1.Id;
wrap.add(new wraper(myname,myFamily,myDescription,myProductCode,myContainer,myId));
}
}
return null;
}

public string pid {get; set;}
Public class wraper
{
public String name {get;set;}
public String Family {get;set;}
public String Description{get;set;}
public String ProductCode{get;set;}
public String Container{get;set;}
public string pid {get; set;}
Public wraper(String name,String Family,String Description,String ProductCode,String Container,String Id)
{
this.name=name;
this.Family=Family;
this.Description=Description;
this.ProductCode=ProductCode;
this.Container=Container;
this.pid = Id;
}
}

public PageReference redirect()
{
System.debug('---------->'+pid);
pagereference ref = new pagereference('/'+pid);
return ref;
}
/*Public PageReference AddtoCart()
{
//Stringdisplay sd = new Stringdisplay();
//system.debug('###'+sd.getCartID);
pageReference ref = new pageReference('/apex/Mycart?ide='+getCartID);

//ref.getParameters().put('Id',pid);
ref.setRedirect(true);
return ref;
} */

public List<Product2> lstCon{get;set;}
public string strSelAccount{get;set;}
public boolean rendered{get;set;}
public List<Product2> getDisplayContacts()
{
lstCon=[select Id,Name,Description,Family,ProductCode,Servings_Container__c from Product2 where Family=:strSelAccount];
system.debug('Size is '+lstCon.size());
renderFirst = true;
return lstCon;
}

public List<SelectOption> getdistinctrecs()
{
List<SelectOption> options=new List<SelectOption>();
Map<String,String> prodMap=new Map<String,String>();
Product2[] prod=[select Id,Name,Description,Family,ProductCode,Servings_Container__c from Product2 order by Family];
for(Product2 prods:prod)
{
prodMap.put(prods.Family,prods.Family);
}
Set<String> prodNames=prodMap.keySet();
List<String> prodids=prodMap.values();
List<String> prodNames1= new List<String>(prodNames);
options.add(new SelectOption('--None--','--None--'));
for(integer i=0;i<prodNames.size();i++)
{
options.add(new SelectOption(prodids.get(i),prodNames1.get(i)));
}
return options;
}
public Void getDisplayName()
{
isdisplay= false;
if(strSelAccount=='--None--')
rendered=false;
else
rendered=true;
getDisplayContacts();
}
}

JHayes SDJHayes SD

Change your test() function in Javascript to the following:

 

function test(val) {
    var w=window.open('/apexMycart?id=' + val,target='_blank');
    return false ;
}

 Worked for me.

 

Regards, jh

 

 

JHayes SDJHayes SD

Edited my reply, your commandButton is fine, just need to update the Javascript function.