質問

im tring to display records in question__c object along with fields in object as radio button. but im not able to get radio button value. getting only radio button without name.
im new to salesforce.if this is very basic question pls excuse me.

<apex:page standardController="question__c" extensions="GetQuestionList" >

<apex:form >
  <apex:repeat value="{!que}" var="a">
  <apex:pageBlock >
  <apex:pageBlockSection columns="1">
  {!a.Quiz_question__c} {!a.id} <br/>

     <apex:selectRadio value="{!selectedAns}" >                    
                <apex:selectOption itemValue="{!opt3}" itemLabel="{!a.option_3__c}"/>
                <apex:selectOption itemValue="{!opt4}" itemLabel="{!a.option_4__c}"/>

        </apex:selectRadio> 

</apex:pageBlockSection>  
</apex:pageBlock>  
</apex:repeat>
</apex:form>
</apex:page>

____mycontroller is

public class GetQuestionList {
question__c q1;
public List<question__c> que{set;}
public List<question__c> getque(){
List<question__C> que= new List<question__c>();
for(question__C q:[select Quiz_question__c,id from question__c]){
    que.add(q);
  system.debug(que);
}
system.debug(que);
return que;
}

public String selectedAns{get;set;} 
public String opt2{get;set;}
public String opt4{get;set;}
public String opt3{get;set;}

public GetQuestionList(ApexPages.StandardController controller) {

}


}
役に立ちましたか?

解決

The reason you have no label is because the value field on the <apex:selectRadio> is a String variable, rather than a field. If you want to add a label, there is a label attribute on that visualforce component you can use.

If you want the label to be dynamically shown based on an actual field's label in the data model, you need to set the value field to that field. An example of that would be if you had an Answer__c field on the Question__c object.

<apex:selectRadio value="{!a.Question__r.Answer__c}">
  <apex:selectOption itemValue="{!opt3}" itemLabel="{!a.option_3__c}"/>
  <apex:selectOption itemValue="{!opt4}" itemLabel="{!a.option_4__c}"/>
</apex:selectRadio> 

That value field would use the label assigned to that field in the object model by default.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top