无法获取< apex:selectRadio>的值.在< apex:repeat>内时 [英] Cannot get values of <apex:selectRadio> when inside <apex:repeat>

查看:106
本文介绍了无法获取< apex:selectRadio>的值.在< apex:repeat>内时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在重复中设置带有<apex:selectRadio>的visualforce页面时,似乎无法将所选值返回到控制器中.如果我将其移出重复项,则效果很好.有什么想法吗?

When I setup a visualforce page with a <apex:selectRadio> that is inside a repeat, I cant seem to get the selected value back into the controller. If I move it out of the repeat, it works fine. Any ideas?

控制器:

public with sharing class COPE_TestsExt {
public id tid {get;set;}
public boolean showTestSelect {get;set;}
public list<COPE_Tests__c> tests {get;set;}
public list<COPE_questions__c> questions {get;set;}
public list<List<SelectOption>> options {get;set;}
public COPE_results__c results {get;set;}
public list<string> rid {get;set;}   

public COPE_TestsExt(ApexPages.StandardController controller) {   

    results = new COPE_results__c();
    showTestSelect = true;
    tests = [select id, name from COPE_Tests__c];
    tid = null; 

}

public PageReference setTid(){

    integer ridCount = 0;       
    showTestSelect = false;
    tid = ApexPages.CurrentPage().getParameters().get('tid');
    results.cope_test__c = tid;
    questions = [select id, name, question_body__c, (select id, name, option_body__c from COPE_options__r order by name ASC) from COPE_questions__c ];
    options = new List<List<SelectOption>>();
    for(COPE_Questions__C q : questions){
        ridCount++;
        List<SelectOption> l = new List<SelectOption>();
        for(COPE_options__c op : q.COPE_options__r){
            l.add(new SelectOption(string.valueof(op.id), op.option_body__c));
        }
        options.add(l);
    }
    rid = new string[ridCount];
    integer tempCount = 0;
    while(tempCount < ridCount){
    rid[tempCount] = '';
    tempCount++;
    }

    return null;
}      
public pagereference submit(){
  return null;
}       
}

页面:

    <apex:page showHeader="false" standardController="COPE_Tests__c" extensions="COPE_TestsExt" >
<apex:form id="theForm" >
<apex:pageblock >
    <apex:outputPanel id="testSelect">

    <apex:pageBlockTable value="{!tests}" var="t" rendered="{!showTestSelect}"  >
    <apex:column headerValue="Please select a test:" ><apex:commandLink reRender="testSelect,testPage" action="{!setTID}"  >{!t.name}<apex:param name="tid" value="{!t.id}"/></apex:commandLink></apex:column>
    </apex:pageBlockTable>
    </apex:outputPanel>
    <apex:outputPanel id="testPage">
    <apex:outputText rendered="{!not(showTestSelect)}">
    <apex:pageBlockSection collapsible="false" title="User Information" columns="1">
        <apex:inputField label="What is your full name?" value="{!results.name}" required="false"/>
        <apex:inputField label="What is your email address?" value="{!results.Email__c}" required="false"/>
        <apex:inputField label="What is your OE Tracker #?" value="{!results.OE_Tracker__c}" required="false"/>
    </apex:pageBlockSection>
    <apex:pageBlockSection collapsible="false" title="Test Questions" columns="1">
    <apex:variable var="count" value="{!0}" />
    <apex:repeat value="{!questions}" var="q">
    {!count+1}. {!q.Question_Body__c}
    <apex:repeat first="{!count}" rows="1" value="{!options}" var="op">
    <apex:selectRadio value="{!rid[count]}" >
    <apex:selectOptions value="{!op}" />
    </apex:selectRadio>
    </apex:repeat>
<apex:variable var="count" value="{!count+1}"/>
</apex:repeat>
<apex:commandButton reRender="check" action="{!submit}" value="Submit"/>
</apex:pageBlockSection>
</apex:outputtext>
</apex:outputPanel>
<apex:outputPanel id="check">
{!rid[0]}
</apex:outputPanel>
</apex:pageblock>
</apex:form>
</apex:page>

推荐答案

如果我做对了,您想存储在

If i got it right you want to store in

public list<List<SelectOption>> options {get;set;}

可能的答案.因此,更好的方法可能是将其存储在从Question.Id到List这样的地图中

possible answers. So a better approach might be to store it in a map from Question.Id to List like this

public Map<Id,List<SelectOption>> options {get;set;}
...    
for(COPE_Questions__C q : questions){
    ridCount++;
    List<SelectOption> l = new List<SelectOption>();
    for(COPE_options__c op : q.COPE_options__r){
        l.add(new SelectOption(string.valueof(op.id), op.option_body__c));
    }
    options.put(q.Id,l);
}

然后在VF Page中,您可以做类似的事情

And then in VF Page you could do something like

<apex:repeat value="{!questions}" var="q">
  {!count+1}. {!q.Question_Body__c}
<apex:selectRadio value="{!rid[count]}" >
<apex:selectOptions value="{!options[q.Id]}" />
</apex:selectRadio>
<apex:variable var="count" value="{!count+1}"/>
</apex:repeat>

希望它会有所帮助.

P.S.如果不生气的话,我可能会误解了您的代码(它们的可读性很差):

P.S. I might misunderstood your code (hes not very readable) if so don't get angry :)

这篇关于无法获取&lt; apex:selectRadio&gt;的值.在&lt; apex:repeat&gt;内时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆