--------------------------------------menu2 vfpage---------------------------------------------
<apex:page controller="menuTypeController" sidebar="false" showChat="false"> <apex:form > <apex:pageBlock > <apex:pageBlockTable value="{!menu}" var="m"> <apex:column value="{!m.Item__c}"/> <apex:column value="{!m.Menu_Description__c}"/> <apex:column value="{!m.Vendor__r.Vendor_Name__c}"/> <apex:column value="{!m.Cost__c}"/> </apex:pageBlockTable> </apex:pageBlock> </apex:form></apex:page>
-----------------------------------menutype vf page---------------------------------------
<apex:page sidebar="false" showChat="false" controller="MenuTypeController">
<apex:pageBlock >
<apex:form >
<apex:commandButton value="INDIAN" action="{!menu2}" reRender="one" onclick="" >
<apex:param name="Indian" value="Indian" assignTo="{!clickedButtonType}"/>
</apex:commandButton>
<apex:commandButton value="CHINESE" alt="CHINESE" action="{!menu2}" reRender="two">
<apex:param name="Chinese" value="Chinese" assignTo="{!clickedButtonType}"/>
</apex:commandButton>
<apex:commandButton value="ITALIAN" alt="ITALIAN" reRender="three" >
<apex:param name="Italian" value="Italian" assignTo="{!clickedButtonType}"/>
</apex:commandButton>
<apex:commandButton value="BRITAIN" alt="BRITAIN" reRender="four">
<apex:param name="Britain" value="Britain" assignTo="{!clickedButtonType}"/>
</apex:commandButton>
<apex:commandButton value="RANDOM" alt="RANDOM" reRender="five">
<apex:param value="Random" name="Random" assignTo="{!clickedButtonType}" />
</apex:commandButton>
</apex:form>
</apex:pageBlock>
-----------------------------------controller for both the classes------------------------------------
public class MenutypeController extends genericControllerClass{
public string clickedButtonType{get;set;}
public list<Menu__c> menuList{get;set;}
public MenutypeController(){
super();
string pageName=getPageName(apexpages.currentPage().getUrl());
if(pageName=='menu2')
{ initmenu2(); }
else if(pageName=='menuType')
{ initmenuType(); }
}
public list<Menu__C> initmenu2()
{ menu2(); return menuList; }
public list<Menu__c> initmenuType(){
return menuList; }
public pageReference menu2(){
menuList=[select cost__c from menu__c where menu_type__c=:clickedButtonType];
pageReference p=new pageReference('/apex/menu2'); p.setRedirect(true);
return p; }
}
Hello,I am assuming requirment here is to redirect to another page on button click. We have done it using the redirect URL, 'ClikedButtonType' data can be passed as a parmeter in url which should be opened on button click. New page controller should retrieve this url parameter and query the data to display it on opened page. You can use same controller or different one, just make sure to call correct method on new page load.I would recommand using output link instead of a CommandButton, it will make it easier if you do not wanna write too much javascript.1. Sample output link : <apex:outputlink target="_blank" value="/apex/menu2?btntype=indian" >INDIAN</apex:outputlink>2. Retrive Parameter - btntype in controller of menu2 page and display the data. Make sure data loading method is called on action attribute of page. example - loadData() method should do the data query and make it ready for display. <apex:page controller="menuTypeController" sidebar="false" showChat="false" action="{!loadData}"> Thanks