+ Start a Discussion
ezdhanezdhan 

Visualforce radiobuttons display error

I have 3 columns of radio buttons naming Present Absent and Leave. I want to take the Attendance of students. The problem is when i put the attendance like Present,Absent,Leave,Present. it is displaying as Present to all. i am submitting my 3 linked pages code for reference. Most Thankful if solved..

Thank you.

//Page 1
<apex:page showHeader="false" sidebar="false" controller="attsheet" ><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
 <center>
 <apex:form >
  <apex:panelGrid >  
   <Apex:pageblock title="Attendance">
    <apex:pageMessages ></apex:pageMessages> 
    <apex:outputText >Date</apex:outputText>
    <apex:inputField value="{!obj.Date__c}"/>
    <apex:outputText >Class</apex:outputText>
    <apex:inputText value="{!clss}" />
    <apex:outputText >Section</apex:outputText>
    <apex:inputText value="{!sec}"/>
    <apex:commandButton value="Go" action="{!go}" />
    <apex:commandButton value="Reset" action="{!reset}"/>
    <apex:commandButton value="Cancel" action="{!cancel}"/>
   </Apex:pageblock>
  </apex:panelGrid>
 </apex:form>
 </center>
</apex:page>
//Page2
<apex:page sidebar="false" showHeader="false" controller="attsheet" >
<apex:panelGrid >
  <apex:form >
   <apex:pageBlock >
     <apex:outputLabel >Date: </apex:outputLabel>
     <apex:outputField value="{!obj.Date__c}"/>
      <apex:commandButton value="Done" action="{!done}"/>
      <apex:pageBlockTable value="{!search}" var="b">
          <apex:column value="{!b.name}"/>
          <apex:column value="{!b.Name__c}"/>
          <apex:column value="{!b.Class__c}"/>
          <apex:column value="{!b.section__c}"/>
          <apex:column >
          <apex:selectRadio value="{!status}" >
          <apex:selectOptions value="{!items}" />
          </apex:selectRadio>
          </apex:column>
      </apex:pageBlockTable>
   </apex:pageBlock>
  </apex:form>
  </apex:panelGrid>
</apex:page>
//Page 3
<apex:page sidebar="false" showHeader="false" controller="attsheet">
  <apex:form >
  <apex:pageBlock >
   <apex:pageBlockTable value="{!search}" var="a">
    <apex:column value="{!a.Name}"/>
    <apex:column value="{!a.Name__c}"/>
    <apex:column value="{!a.Class__c}"/>
    <apex:column value="{!a.section__c}"/>
    <apex:column value="{!status}"/ >
    </apex:pageBlockTable>
 <apex:commandButton value="Go to page1" action="{!page1}"/>
  </apex:pageBlock> 
 </apex:form>
</apex:page>
//controller
public class attsheet {

    public PageReference done() {
        return page.attsheet2;
    }
public string status;
public Student_Attendance__c obj{set;get;}
public string clss{set;get;}
public string sec{set;get;}
public string search{set;}
 public attsheet(){
 obj = new Student_Attendance__c();
 }
 public list<student_Attendance__c> bk{set;get;}
 public list<student_Attendance__c> bk1{set;get;}
public pagereference go(){
try{
bk = [select id,name,name__c,class__c,date__c,section__c,status__c from Student_Attendance__c where class__c =:clss And section__c =: sec ];
for(Student_Attendance__c a:bk){
    if(a.Class__c ==clss  && a.section__c ==sec ){
return page.attsheet1;
}
}
}
catch (Exception E){
    return null;
}
apexPages.addMessage(new ApexPages.message(ApexPages.severity.Error,'Please Enter Missing Values'));
     return null;
}
public list<Student_Attendance__c> getsearch(){
return bk;
}
public pageReference reset(){
return new pageReference('https://c.ap1.visual.force.com/apex/attsheet');
}
public pageReference cancel(){
return null;
}
public List<SelectOption> getItems() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('Present','Present'));
options.add(new SelectOption('Absent','Absent'));
options.add(new SelectOption('Leave','Leave'));
 return options;
}
public string getStatus(){
return status;
}
public void setstatus(String status) {
        this.status = status;
    }
  
  public pageReference page1(){
  return page.attsheet;
  }
}

 

DaveHDaveH

The problem is that you only specified the selectRadio element but did not supply an array of select options. You need something like the following:

 

<apex:selectRadio value="{!selectedItem}">
    <apex:selectOptions value="{!items}"/>
</apex:selectRadio>

 Where selectedItem is the item the user has selected and items is a list of SelectOption's for the possible buttons. See this link for more info:

 

http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_selectRadio.htm

ezdhanezdhan

Thank you for your valuable suggestion, But i have given a value in <apex:radiobutton> tag, that is status. I am able to get Present/Absent/Leave for single student, But it is having problem for multiple students, Can you please elaborate your Answer ?