• profile_name
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 3
    Replies

I have a controller extension for a custom object where I am trying to insert a record according to input from selectCheckbox. I am getting 'URL No Longer Exists'  and am unable to debug this or find out what is going wrong. 
Markup:

<apex:page standardcontroller="Equipment_Type__c" extensions="addMakesController1">
  <apex:pageBlock id="pageBlock1">    
        <apex:pageBlockTable value="{!usedMakes}" var="ma" style="width:20px">           
            <apex:column headerValue="Action">
                <apex:form >
                <apex:commandlink action="{!delMake}">Del</apex:commandlink>
                </apex:form>
            </apex:column>
            <apex:column value="{!ma.name}" />
        </apex:pageBlockTable>
        </apex:pageBlock>
        <apex:pageBlock id="pageBlock2">
        <apex:form >
            <apex:selectCheckboxes value="{!selectedMakes}" style="float:left"  layout="PageDirection" >
                <apex:selectOptions value="{!validMakes}" />
            </apex:selectCheckboxes><br/>
            
        </apex:form>
  </apex:pageBlock>
      <apex:form >
      <apex:commandButton action="{!addMakes}"  value="Add selected Makes" rerender="pageBlock1,pageBlock2" status="updateStatus"/>
                <apex:actionStatus startText="Please wait..." stopText="Records updated successfully" id="updateStatus"  />
      </apex:form>
</apex:page>

 Controller:

public with sharing class addMakesController1 {
    private Equipment_Type__c type;
    public addMakesController1(ApexPages.StandardController controller) {
        this.type = (Equipment_Type__c)controller.getRecord();
        
        list<Equipment_Type__c> type1=[select id,Functional_Group__r.Id from Equipment_Type__c where id=:this.type.id limit 1];
        if(type1.size()!=0)
        this.type = type1[0];
    }
    public list<Make__c> allMakes=new list<Make__c>();
    public list<SelectOption> temp=new list<SelectOption>();
    public list<Make__c> displayMakes=new list<Make__c>();       
    public list<Make__c> getUsedMakes(){
        allMakes=[select name from Make__c where Functional_Group__c=:type.Functional_Group__r.Id];
        list<Make__c> usedMakes=new list<Make__c>();
        for(Make__c m:allMakes){
            list<Type_Make__c> tmtemp=new list<Type_Make__c>();
            tmtemp=[select id from Type_Make__c where Type__c=:type.id AND Make__c=:m.id];
            if(tmtemp.size()!=0){
                usedMakes.add(m);
            }
        }
        return usedMakes;
    }         
    public list<string> selectedMakes{get;set;}
    public list<SelectOption> getValidMakes(){
        allMakes=[select name from Make__c where Functional_Group__c=:type.Functional_Group__r.Id];
        list<SelectOption> validMakes=new list<SelectOption>();
        for(Make__c m:allMakes){
            list<Type_Make__c> tmtemp=new list<Type_Make__c>();
            tmtemp=[select id from Type_Make__c where Type__c=:type.id AND Make__c=:m.id];
            if(tmtemp.size()==0){
                validMakes.add(new SelectOption(m.name,m.name));
            }
           
        }    
        if(validMakes.size()!=0){
            return validMakes;
        }
        else{
            return null;
        }
    }
    public void delMake(){}
    public void addMakes(){
            list<Type_Make__c> tmList=new list<Type_Make__c>();
            for(String m:selectedMakes){
                tmList.add(new Type_Make__c(Type__c=type.id,Make__c=[select id,name from Make__c where name=:m].id));
                 
           if(tmList.size()!=0)insert tmList;
        }
    
}

 

I have a dynamic component with a number of selectList components inside it. The behaviour required is: making a selection in one selectList should display another list, which would be hidden until then. Is there a way to do this other than creating dynamic actionSupport elements(I suspect it will be difficult to make it reRender sibling components(ie. with respect to the dynamic component as a parent))

I found that using action support in dynamic components is very troublesome and wonder if I am using the right approach to create my required output.:
Equipment_Type__c has a field called Parent_Type__c which is a lookup to itself, creating a parent-child relationship. The requirement is a set of SelectLists: at first, only one list is displayed, containing types which have no parent. When one of the types is selected,say type1, another list is displayed next to it, containing the types whose parent is type1. If one of the types on this list is selected, one more list is displayed, containing its children and so on.
The general approach I used, with dynamic component is from here:(ie. the idea was to create one dynamic component with each list as a child component of its parent)
        http://wiki.developerforce.com/page/Dynamic_Visualforce_Components
The main problem I encountered was with displaying/hiding each list: from what I've seen, it is not possible to change the 'Rendered' attribute of a component using a controller method. The only other option seems to be using ActionSupport. However, even this must be dynamic, and leaves me with having to do this(only a rough attempt):

            Component.Apex.ActionRegion ar = new Component.Apex.ActionRegion();
            Component.Apex.SelectList selList = new Component.Apex.SelectList ( size = 10,  id = 'sl1');   
            ar.childComponents.add(selList);              
            Component.Apex.ActionSupport asu = new Component.Apex.ActionSupport (event='onchange');         
            asu.expressions.action='{!processSelect}';
            asu.expressions.rerender=selectedItem;         
            selList.childComponents.add(asu);

Is there a better strategy to use? In general, what is the most efficient way to achieve the output that I described?

Hello

The requirement here is to make 2 picklists, one with records from object Functional_Group_del__c and another with records from object. Equipment_Type__c (which has a lookup field to Functional_Group_del__c)  When a record of Functional_Group_del__c is chosen in the first picklist, the values in the second picklist are restricted to records in Equipment_Type__c whose lookup field value is equal to the Functional Group chosen in the first picklist.

The variable 'fgOptions'  populates the first picklist with Functional Group values. The variable 'fgVal' must store the value currently chosen in the first picklist. 

The following code gives the error "variable is not visible" regarding 'fgVal'. Should the setter method be in some other form? In general, what must be done to give getter methods access to variables that take their values from a user input?

The markup:

<apex:page controller="buildTypeController1"> 
  <apex:pageBlock title="Select Functional Group">    
      <apex:form >
          <apex:selectList size="1" value="{!fgVal}"> 
              <apex:selectoptions value="{!fgOptions}"/>
                  <apex:actionsupport action="{!setFgVal}" event="onchange" rerender="type"/>
          </apex:selectList>
      </apex:form>
  </apex:pageBlock> 
  <apex:outputpanel id="type">
  <apex:pageBlock title="Select Equipment Type">    
      <apex:form >
          <apex:selectList size="1">
              <apex:selectoptions value="{!typeOptions}" />
          </apex:selectList>
      </apex:form>
   </apex:pageBlock>
   </apex:outputpanel>
</apex:page>

 The controller:

public with sharing class buildTypeController1 {
    public SelectOption fgVal{get;}
    public void setFgVal(SelectOption fgVal){
       system.debug('#############'+fgVal);
       this.fgVal=fgVal;
    }
    public list<SelectOption> getFgOptions(){
        list<Functional_Group_del__c> fgList = new list<Functional_Group_del__c>();
        list<SelectOption> fgOptions = new list<SelectOption>();
        fgList = [select id,name from Functional_Group_del__c];
        if(fgList.size()>0){
            for(Functional_Group_del__c fg : fgList){
                fgOptions.add(new SelectOption(fg.Name,fg.Name));
            }
            return fgOptions;
        }
        else
        return null;
    }
    public list<SelectOption> getTypeOptions(){
        list<Equipment_Type__c> typeList = new list<Equipment_Type__c>();
        list<SelectOption> typeOptions = new list<SelectOption>();
        //system.debug('*************'+string.valueof(fgVal));
        typeList = [select id,name,Functional_Group__c from Equipment_Type__c];
        if(typeList.size()>0){
            for(Equipment_Type__c et : typeList){
                typeOptions.add(new SelectOption(et.Name,et.Name));
            }
            return typeOptions;
        }
        else
        return null;
    }
        
}

 

 

Hello

The requirement here is to make 2 picklists, one with records from object Functional_Group_del__c and another with records from object. Equipment_Type__c (which has a lookup field to Functional_Group_del__c)  When a record of Functional_Group_del__c is chosen in the first picklist, the values in the second picklist are restricted to records in Equipment_Type__c whose lookup field value is equal to the Functional Group chosen in the first picklist.

The variable 'fgOptions'  populates the first picklist with Functional Group values. The variable 'fgVal' must store the value currently chosen in the first picklist. 

The following code gives the error "variable is not visible" regarding 'fgVal'. Should the setter method be in some other form? In general, what must be done to give getter methods access to variables that take their values from a user input?

The markup:

<apex:page controller="buildTypeController1"> 
  <apex:pageBlock title="Select Functional Group">    
      <apex:form >
          <apex:selectList size="1" value="{!fgVal}"> 
              <apex:selectoptions value="{!fgOptions}"/>
                  <apex:actionsupport action="{!setFgVal}" event="onchange" rerender="type"/>
          </apex:selectList>
      </apex:form>
  </apex:pageBlock> 
  <apex:outputpanel id="type">
  <apex:pageBlock title="Select Equipment Type">    
      <apex:form >
          <apex:selectList size="1">
              <apex:selectoptions value="{!typeOptions}" />
          </apex:selectList>
      </apex:form>
   </apex:pageBlock>
   </apex:outputpanel>
</apex:page>

 The controller:

public with sharing class buildTypeController1 {
    public SelectOption fgVal{get;}
    public void setFgVal(SelectOption fgVal){
       system.debug('#############'+fgVal);
       this.fgVal=fgVal;
    }
    public list<SelectOption> getFgOptions(){
        list<Functional_Group_del__c> fgList = new list<Functional_Group_del__c>();
        list<SelectOption> fgOptions = new list<SelectOption>();
        fgList = [select id,name from Functional_Group_del__c];
        if(fgList.size()>0){
            for(Functional_Group_del__c fg : fgList){
                fgOptions.add(new SelectOption(fg.Name,fg.Name));
            }
            return fgOptions;
        }
        else
        return null;
    }
    public list<SelectOption> getTypeOptions(){
        list<Equipment_Type__c> typeList = new list<Equipment_Type__c>();
        list<SelectOption> typeOptions = new list<SelectOption>();
        //system.debug('*************'+string.valueof(fgVal));
        typeList = [select id,name,Functional_Group__c from Equipment_Type__c];
        if(typeList.size()>0){
            for(Equipment_Type__c et : typeList){
                typeOptions.add(new SelectOption(et.Name,et.Name));
            }
            return typeOptions;
        }
        else
        return null;
    }
        
}