You need to sign in to do that
Don't have an account?
Yash
Want to change the combo box value on selection of another combo box in VF
Hi,
Parent - Category Master
Child - Sub Category Master
Relationship between above custom object is 1:M
I want to display the resepective sub category on selection of the category. I am not able to get the id of selected category and passed it to query to retreive the sub category list.
Code is as follow
Thank you
Parent - Category Master
Child - Sub Category Master
Relationship between above custom object is 1:M
I want to display the resepective sub category on selection of the category. I am not able to get the id of selected category and passed it to query to retreive the sub category list.
Code is as follow
Code:
<apex:page controller="Item_Master_Controller" sidebar="false" showHeader="true"> <apex:sectionHeader title="Item Master" subtitle="" description="" ></apex:sectionHeader> <apex:form > <apex:pageBlock title=""> <apex:outputPanel id="out1"> <apex:actionstatus id="status1" startText="starting..."> <apex:facet name="stop"> <apex:outputPanel > <h1> <apex:outputText style="font-style:bold" value="{!message}"></apex:outputText> <p/> </h1> </apex:outputPanel> </apex:facet> </apex:actionstatus> </apex:outputPanel> <p/> <h1><apex:outputText style="font-style:bold" value="Select the Category"></apex:outputText></h1> <apex:selectList value="{!selectedCategory}" multiselect="false" size="1"> <apex:selectOptions value="{!category}"/> <apex:actionSupport event="onchange" rerender="changeSubCategory"/> </apex:selectList><p/> <apex:outputPanel id="changeSubCategory"> <h1><apex:outputText style="font-style:bold" value="Select the Sub Category"></apex:outputText></h1> <apex:selectList value="{!selectedSubCategory}" multiselect="false" size="1"> <apex:selectOptions value="{!subCategory}"/> </apex:selectList><p/> </apex:outputPanel> <apex:pageblockButtons > <apex:commandButton value="Submit" action="{!save}" rerender="out1" status="status1"></apex:commandButton> </apex:pageblockButtons> </apex:pageBlock> </apex:form> </apex:page>
Code:
public class Item_Master_Controller{ String[] selectedCategory= new String[]{}; String[] selectedSubCategory= new String[]{}; String message=null; String itemName=null; String itemDesc=null; String upc=null; Integer itemNumber; List<Category_Master__c> category; List<Sub_Category_Master__c> subCategory; public PageReference save() { Boolean flag=true; //this.setMessage(String.valueOf(selectedCategory.size())); this.setMessage('in save method...'); return null; } public void setMessage(String message){ this.message=message; } public String getMessage(){ return this.message; } public List<SelectOption> getCategory() { List<SelectOption> options = new List<SelectOption>(); Integer i=0; for(Category_Master__c category : [select Category_Id__c,Category_Name__c from Category_Master__c]) { options.add(new SelectOption(String.valueOf(category.Category_Id__c),category.Category_Name__c)); } return options; } public List<SelectOption> getSubCategory() { List<SelectOption> options = new List<SelectOption>(); Integer catId=-1; if(selectedCategory.size()>=1){ catId=Integer.valueOf(selectedCategory[0]); } Integer i=0; for(Sub_Category_Master__c subCategory : [select Sub_Category_Id__c,Sub_Category_Name__c from Sub_Category_Master__c where Category_Id__c =: catId]) { i++; options.add(new SelectOption(String.valueOf(subCategory.Sub_Category_Id__c),subCategory.Sub_Category_Name__c)); } if(i==0){ options.add(new SelectOption('Zero',String.valueOf(catId))); }else{ options.add(new SelectOption('Not Zero',String.valueOf(catId))); } return options; } public String[] getSelectedCategory() { return selectedCategory; } public void setSelectedCategory(String[] selectedCategory) { this.selectedCategory= selectedCategory; } public String[] getSelectedSubCategory() { return selectedSubCategory; } public void setSelectedSubCategory(String[] selectedSubCategory) { this.selectedSubCategory= selectedSubCategory; } /* public Boolean isPresent(String agentId,String ruleId) { Boolean flag=false; for(AgentRule__c agRule : [select id from AgentRule__c where LP_Agent_Id__c = : agentId and LP_Rule_Id__c =: ruleId]) { flag=true; } return flag; } */ }
Thank you