8

I have a VF page in that I am having a List which has picklist field called "Status", values named "open" and "complete". When we select the picklist value "Complete" then the record should move to the another list called "history" which empty by initial. Kindly tell how to get the picklist value.Thanks in advanced

Code:

public with sharing class sample {
    public Integer numberOfRowToRemove1 { get; set; }
    public List<Account> list1 { get; set; }
    public List<Account> list2 { get; set; }
    public string temp{get;set;}

    public sample() {
        list1 = [select id,name,accountnumber from Account limit 2];
        list2 = [select id,name,accountnumber from Account limit 3];
    }

    public List<selectOption> getitems() {
        List<selectoption> options=new List<selectoption>();
        options.add(new selectoption('Complete','Complete'));
        options.add(new selectoption('Open','Open'));
        return options;
    }

    public PageReference showdata() {
        if(temp=='Complete') {
            list2.add(0,list1.get(numberOfRowToRemove1));
            list1.remove(numberOfRowToRemove1);
        }
        return null;
    }

}

Page:

<apex:page controller="sample" >
    <apex:form >
        <apex:variable value="{!0}" var="rowNumber1" />
        <apex:outputPanel id="panelWithVar">
            <apex:variable value="{!0}" var="rowNumber1" />
        </apex:outputPanel>
        **<apex:actionFunction name="find" action="{!showdata}"/>**  

        <apex:pageBlock id="table1">
            <apex:dataTable value="{!list1}" var="a" columnswidth="100px,100px" cellpadding="3" columns="4" border="1" width="500px" bgcolor="#f5dcef" rowClasses="1" >
                <apex:column value="{!a.Name}" headerValue="Customer Name" />
                <apex:column value="{!a.AccountNumber}" headerValue="Number" width="100"/>
                <apex:column headerClass="Status">
                    **<apex:selectList id="selected_list" value="{!temp}" required="false" size="1" onchange="find();">**
                        <apex:selectOptions value="{!items}"/>
                        <!--<apex:selectOption itemvalue="None" itemLabel="--None--"/>
                        <apex:selectOption itemvalue="complete" itemLabel="complete"/>
                        <apex:selectOption itemvalue="Open" itemLabel="Open"/>-->
                        <!--<apex:actionSupport event="onchange" reRender="Details,panelWithVar,table1" action="{!find}" onsubmit="checkAll(this)"/>-->
                        <apex:param name="p1" value="{!rowNumber1}" assignTo="{!numberOfRowToRemove1}"/>
                    </apex:selectList>
                    <apex:variable var="rowNumber3" value="{!rowNumber1 + 1}" />
                </apex:column>
            </apex:dataTable>
        </apex:pageBlock>

        <apex:pageBlock id="Details">
            <apex:pageBlockSection >
                <apex:panelGroup >
                    <apex:dataTable value="{!list2}" var="a" columnswidth="50px,50px" cellpadding="4" border="1" >
                        <apex:column value="{!a.Name}" headerValue="Customer Name" width="100"/>
                        <apex:column value="{!a.AccountNumber}" headerValue="Address" width="100"/>
                        <apex:column headerClass="Status">
                            <apex:selectList id="selected_list" value="{!temp}" required="false" size="1">

                                <apex:selectOptions value="{!items}"/>
                            </apex:selectList>
                        </apex:column>
                    </apex:dataTable>
                </apex:panelGroup>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>
  • @Mohith ,Thanks I have updated my question. I have tried this but its not working – Lavanya Sanathkumar Nov 22 '13 at 7:18
  • 1
    I think you should use action function and on change of picklist call the pagereference method and in page reference method manage your list . – Mohith Shrivastava Nov 22 '13 at 7:28
  • @MohithKumar Thanks a lot for your reply, I have done this <apex:actionFunction reRender="Details,panelWithVar,table1" action="{!find}" onsubmit="checkAll(this)"/> . But its not working please give some clarification on this. – Lavanya Sanathkumar Nov 22 '13 at 7:41
  • 1
    i dont see pagereference method and also not sure whats temp varibale?The variable has to be for each record and your select option picker should itself get set before your action method and you can use that – Mohith Shrivastava Nov 22 '13 at 7:46
  • @MohithKumar thanks for the reply. I have updated my question , but its not working. Please check this and guide me. – Lavanya Sanathkumar Nov 22 '13 at 11:29
1

It might help you a bit if you understood more of what you're actually doing with your controller and the visual force page it's intended to work with. It appears that you're creating a controller to report and change the Status of something related to an Account. That could be any number of things, but in this case, I suspect it's used for Tasks (sorry, but your code doesn't tell us the actual use case, so am guessing here).

This controller could be used for a page inserted as a related list on another page that reports on Opportunities. When the status of the Task changes from Open to Closed, the record would then need to be added to the History for the Opportunity its related to. When that happens, the list for History within your controller needs to be updated or refreshed. One doesn't "move" the record from one list to the another. Instead, the Task record is updated and the controller's contents are then refreshed when the page is updated using the action method that calls for a rerender.

Mohith has given you excellent assistance on how to resolve your coding issues with the controller, but I thought it might be helpful to you to explain a bit more about what was also going on that wasn't quite as evident based on the description you were providing of what you wanted the controller to do for you.

1

Go through this code :) Similar problem statement to move records from one pageblocktable to another :)

Controller :

public class SampleSE
{

    public List<cAccount> accountList {get;set;}

    public List<Account> selectedAccounts{get;set;}

    public Integer value {get;set;}

    public List<cAccount> getAccounts()
    {
        if(accountList == null)
        {
            accountList = new List<cAccount>();
            for(Account a : [select Id, Name, Phone from Account limit 10])
            {
                accountList.add(new cAccount(a));
            }
        }
        return accountList;
    }
    public PageReference processSelected()
    {
        selectedAccounts = new List<Account>();
        for(cAccount aAcc : getAccounts())
        {
            if(aAcc.selected == true)
            {
            selectedAccounts.add(aAcc.acc);

            }

        }
        value = selectedAccounts.size();

        return null;
    }
    public List<Account> getSelectedAccounts()
    {
        if(selectedAccounts.size()>0)
            return selectedAccounts;
        else
            return null;
    }
    public class cAccount
    {
        public Account acc {get; set;}
        public Boolean selected {get; set;}
        public cAccount(Account a) {
            acc = a;
            selected = false;
        }
    }//Wrapper Class
}

Visualforce Page :

<apex:page controller="sampleSE" >
<apex:form >
    <apex:pageBlock >
        <apex:pageBlockButtons >
            <apex:commandButton value="Move Selected" action="{!processSelected}" rerender="test"/>
        </apex:pageBlockButtons>
        <apex:pageBlockTable value="{!Accounts}" var="a" >
            <apex:column >
                <apex:inputCheckbox value="{!a.selected}"/>
            </apex:column>
            <apex:column value="{!a.acc.Name}" />
            <apex:column value="{!a.acc.Phone}" />
        </apex:pageBlockTable>
    </apex:pageBlock>

    <apex:pageBlock id="test">
        Total No of Selected Records :<apex:outputText value="{!value }"/>
        <apex:pageBlockTable value="{!SelectedAccounts}" var="a" >
            <apex:column value="{!a.Name}" />
            <apex:column value="{!a.Phone}" />
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:form>
</apex:page>
0

I think that you have a problem in the reRender of the action function find, because you are only rendering the new list and you need rerender the 2 list.

Can you try this?

<apex:actionFunction name="find" action="{!showdata}" reRender="table1,Details"/>**  

Regards

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.