我想列出调查结果来自表格,但我收到错误
未知属性' String.Name'
我需要在VisualForce页面上显示结果。
VF页面
<apex:page showHeader="false" sidebar="false" controller="SurveyResultController">
<apex:form>
<apex:pageBlock title="Submited Result">
<apex:pageBlockTable value="{!SurveyResult}" var="sr">
<apex:column value="{!sr.Name}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
Apex控制器
public with sharing class SurveyResultController {
public String surveyId {
get;
set{
this.surveyId = value;
}
}
public Integer SurveySessionID {
get;
set{
this.SurveySessionID = value;
}
}
public String ssessionid {
get;
set;
}
public SurveyResultController() {
surveyId = Apexpages.currentPage().getParameters().get('id');
ssessionid = Apexpages.currentPage().getParameters().get('ssessionid');
}
public List<String> getSurveyResult() {
List<tblSurveyResult__c> qr = [SELECT Name,
QuestionID__c,
SurveyID__c,
Answer__c,
QuestionID__r.Id,
QuestionID__r.Name,
QuestionID__r.Question__c,
QuestionID__r.SelectedAnswer__c
FROM tblSurveyResult__c
WHERE SurveyID__c = :surveyId
AND SurveySessionID__c = :SurveySessionID];
List<String> resp = new List<String>();
for (tblSurveyResult__c r : qr) {
resp.add(r.Name);
}
return resp;
}
}
答案 0 :(得分:4)
在以下一行
<apex:column value="{!sr.Name}"/>
您尝试从String实体中读取Name
。
在控制器中,您准备了List<String>
并将其返回到页面。
List<String> resp = new List<String>();
for (tblSurveyResult__c r : qr) {
resp.add(r.Name);
}
return resp;
所以,你的选择:
在页面上使用以下格式
<apex:column value="{!sr}"/>
将tblSurveyResult__c的列表返回到页面
public List<tblSurveyResult__c > getSurveyResult() {
return [SELECT Name,
QuestionID__c,
SurveyID__c,
Answer__c,
QuestionID__r.Id,
QuestionID__r.Name,
QuestionID__r.Question__c,
QuestionID__r.SelectedAnswer__c
FROM tblSurveyResult__c
WHERE SurveyID__c = :surveyId
AND SurveySessionID__c :SurveySessionID];
}
由于您的评论而编辑,请使用第二个选项
将tblSurveyResult__c的列表返回到页面
public List<tblSurveyResult__c > getSurveyResult() {
return [SELECT Name,
QuestionID__c,
SurveyID__c,
Answer__c,
QuestionID__r.Id,
QuestionID__r.Name,
QuestionID__r.Question__c,
QuestionID__r.SelectedAnswer__c
FROM tblSurveyResult__c
WHERE SurveyID__c = :surveyId
AND SurveySessionID__c :SurveySessionID];
}
<apex:page showHeader="false" sidebar="false" controller="SurveyResultController">
<apex:form>
<apex:pageBlock title="Submited Result">
<apex:pageBlockTable value="{!SurveyResult}" var="sr">
<apex:column value="{!sr.SurveyID__c}"/>
<apex:column value="{!sr.Name}"/>
<apex:column value="{!sr.QuestionID__r.Question__c}"/>
<apex:column value="{!sr.QuestionID__r.SelectedAnswer__c}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>