• Toasty02
  • NEWBIE
  • 0 Points
  • Member since 2009

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

Can anyone help me with this?  I need to display a list of objects to a user and allow the user to select any number of these objects.  I then need to process only the selected objects.  I  found a wiki post that shows exactly how to do this:

 

http://wiki.apexdevnet.com/index.php/Checkbox_in_DataTable

 

 

I copied the code and tweaked it to use one of my custom objects (rather than Account objects), and it works perfectly.  However, I don't understand how it is working!  Can someone tell me how the a.selected property gets set to true when the user clicks on the corresponding checkbox?  I don't see where this is happening!

 

 

Thanks,

 

Carolyn

Hello,
 
I'm new to this Apex stuff, so I'm hoping someone will be able to help me out.  I have an Apex page with a selectList, and I'd like to take the value that the use selects and do something with it on the page.  The code I have doesn't appear to be working, and I can't figure out why.
 
This is my controller class:
 
public class SimplePrintLabelsController {
public String selectedLabelTemplateName {get; set;}
public List<selectOption> labelTemplateList {
    get {
        List<selectOption> labelTemplateOptions = new List<selectOption>();
        labelTemplateOptions.add(new selectOption('', '--Select a label template--'));
       
        for (Label_Template__c lt : [select name from Label_Template__c order by name]) {
            labelTemplateOptions.add(new selectOption(lt.name, lt.name));
        }
       
        return labelTemplateOptions;   
    }
    set;
}
}
 
 
And here is the Apex page code:
 
<apex:page controller="SimplePrintLabelsController">
  <script type="text/javascript">
      function showAlert() {
          alert("You selected " + "{!selectedLabelTemplateName}");
      }
  </script>  
  <apex:form >
      <apex:pageBlock >
          <apex:outputLabel value="Label template: "/>
          <apex:selectList id="labelTemplates" value="{!selectedLabelTemplateName}" size="1" onChange="showAlert()">
              <apex:selectOptions value="{!labelTemplateList}"/>
          </apex:selectList>
      </apex:pageBlock>
      <apex:pageBlock >
          <apex:outputLabel value="You selected: {!selectedLabelTemplateName}"/>
      </apex:pageBlock>
  </apex:form>
</apex:page>
 
 
 
As you can see, I'm trying to display the selected value in both an output label and in a JavaScript alert.  However, the selected value is not showing up in either place.  Can anyone tell me what I'm doing wrong here?
 
Thanks very much!
 
- Carolyn
Hello,
 
I'm new to this Apex stuff, so I'm hoping someone will be able to help me out.  I have an Apex page with a selectList, and I'd like to take the value that the use selects and do something with it on the page.  The code I have doesn't appear to be working, and I can't figure out why.
 
This is my controller class:
 
public class SimplePrintLabelsController {
public String selectedLabelTemplateName {get; set;}
public List<selectOption> labelTemplateList {
    get {
        List<selectOption> labelTemplateOptions = new List<selectOption>();
        labelTemplateOptions.add(new selectOption('', '--Select a label template--'));
       
        for (Label_Template__c lt : [select name from Label_Template__c order by name]) {
            labelTemplateOptions.add(new selectOption(lt.name, lt.name));
        }
       
        return labelTemplateOptions;   
    }
    set;
}
}
 
 
And here is the Apex page code:
 
<apex:page controller="SimplePrintLabelsController">
  <script type="text/javascript">
      function showAlert() {
          alert("You selected " + "{!selectedLabelTemplateName}");
      }
  </script>  
  <apex:form >
      <apex:pageBlock >
          <apex:outputLabel value="Label template: "/>
          <apex:selectList id="labelTemplates" value="{!selectedLabelTemplateName}" size="1" onChange="showAlert()">
              <apex:selectOptions value="{!labelTemplateList}"/>
          </apex:selectList>
      </apex:pageBlock>
      <apex:pageBlock >
          <apex:outputLabel value="You selected: {!selectedLabelTemplateName}"/>
      </apex:pageBlock>
  </apex:form>
</apex:page>
 
 
 
As you can see, I'm trying to display the selected value in both an output label and in a JavaScript alert.  However, the selected value is not showing up in either place.  Can anyone tell me what I'm doing wrong here?
 
Thanks very much!
 
- Carolyn
I'm trying to create a page where a list of all accounts are presented to the user so he/she can select accounts to be displayed on the bottom part of the page.  I'm trying to display inputcheckboxes next to each account to to capture the user's request.   For some reason, I can't get the initial list of accounts to display.

My code is below -

Code:
<apex:page Controller="AccountSelectController">
  <apex:form >  
   <apex:pageBlock title="Available Accounts">
      <apex:pageBlockTable title="Accounts" id="PickAccts" value="{!MyAcct}" var="aAcct" >
        <apex:column>
          <apex:inputCheckBox value="{!aAcct.selected}" Id="selectLine"/>
        </apex:column>
        <apex:column headerValue="Account Id" value="{!aAcct.theacct.Id}" />
        <apex:column headerValue="Account Name" value="{!aAcct.theacct.Name}" />
      </apex:PageblockTable>
    <apex:commandButton action="{!gensAcct}" value="Select" rerender="MyPanel" status="status"/> <br />
    <apex:pageMessages ></apex:pageMessages>
  </apex:pageBlock>

<apex:actionStatus startText="Updating..." id="status"/>

<apex:outputpanel title="Results" id="MyPanel">
  <apex:outputpanel title="Wrapper" id="Wrapper" rendered="{!NOT(ISNULL(SAcct))}">
    <apex:pageBlock >
      <apex:pageBlockTable title="Accounts" id="PickAccts" value="{!SAcct}" var="aAcct" >
        <apex:column headerValue="Account Id" value="{!aAcct.theacct.Id}" />
        <apex:column headerValue="Account Name" value="{!aAcct.theacct.Name}" />
      </apex:PageblockTable>
    </apex:Pageblock>
  </apex:outputpanel>
</apex:outputpanel>

  </apex:form>
</apex:page>

Controller -
Code:
public class AccountSelectController {

    public PageReference genSAcct() {
        SAcct = getSAcct();
        return null;
    }
    
    public class cAcct{
        public Account theacct {get; set;}
        public Boolean selected{get; set;}
       
        public cAcct(Account a,Boolean s){
            theacct = a;
            selected = s;
        }
    }
    
    //A collection of the class/wrapper objects cAcct
    
    //The fist list includes all Accounts
    public List<cAcct> MyAcct {get; set;}
    
    //The second list only inclues Accouts selected
    public List<cAcct> SAcct {get; set;}

   //This method uses a SOQL query to return a list of all Accounts
    public List<cAcct> getMyAcct(){
          if(MyAcct == null){
              MyAcct = new List<cAcct>();
              for(Account acct : [Select Name FROM Account Limit 10  ]){
                    /* As each opportunity is processed I create a new cOpportunity object and add it to MyList */
                    cAcct myadd = new cAcct(acct,FALSE);
                    MyAcct.add(myadd);
              }
          }
        return MyAcct;
    }
    
    //This method uses looks at the full account list and adds only those with "selected" = true
    public List<cAcct> getSAcct(){
      if (MyAcct != null) {  
          if (SAcct == null) {
              SAcct = new List<cAcct>();
              for(cAcct cacct : MyAcct){
                  /* As each Accout is processed, check if the selected value is true. */
                  if (cacct.selected == TRUE) {
                      SAcct.add(cacct);
                  }
              }
          }
          return SAcct;
      } else {
          SAcct = null;
          return SAcct;
      }
    }
}

 

 

  • January 19, 2009
  • Like
  • 0