Sarang
Sarang

Reputation: 117

Displaying custom controller data in visualforce page after onchange event

I have a picklist containing names of records of an object, "Test_Script".When I select any option from a picklist("selectlist" & selectoption are used for implementing picklist),at onchange event the other fields related to that record name should be displayed on visualforce page.

VF Page:

<h1>Choose Script:</h1>
<apex:selectlist value="{!selectedValue}" size="1"onchange="{!setValues}">
                            <apex:selectOptions value="{!scriptoptions}" />
                        </apex:selectlist>
                        <br/>
                        Executioner Name: 
                        <outputfield value="{!valueResult.executioner_name}"/>
                        <br/>Planner Name: 
                        <outputfield value="{!valueResult.planner_name}"/>
                        <br/>Reviewer Name: 
                        <outputfield  value="{!valueResult.reviewer_name}"/>

Controller:

public class ScriptAttributesController 
{

    public String setValues { get; set; }
    public List<Test_script__c> scriptListWithValues = [select name, id, Executioner__c, Planner__c, Reviewer__c from Test_Script__c];
    public static Test_Script__c valueResult=new Test_Script__c();
    public String selectedValue {get;set;}
    
    public void ScriptAttributesController()
    {
    }

    public List<SelectOption> getScriptoptions()
    {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('select a value','select a value'));
        for(Test_Script__c s: scriptListWithValues )
        {
            options.add(new SelectOption(s.id,s.name));
        }
        return options;
    }
    
        public void setValues()
    {
        valueResult=[select name, id, Executioner__c, Planner__c, Reviewer__c, Iteration__c from Test_Script__c where name='selectedValue' limit 1];
    }
}

I am not able to see value on screen on change og picklist value

Upvotes: 0

Views: 1555

Answers (1)

utm
utm

Reputation: 290

I would say that a getter is missing for your valueResult.

public Test_Script__c valueResult {get; set;}

and in the controller you can init the object.

Upvotes: 0

Related Questions