我是 APEX 和 visualforce 的新手,所以我对这个有点粗略......我创建了以下类,但我不确定如何截断输出......有人可以向我解释我是如何将截断 CommentBody 字段,因此我将其显示为使用此类的 visualforce 页面上的输出字段
班级:
public class displaycase {
public string getcasetype{get;set;}
public void displaycase() {}
public list<case> caselst{get;set;}
public list<selectoption>getcasestatus() {
list<selectoption>selectopt=new list<selectoption>();
selectopt.add(new selectoption('All' ,'All'));
selectopt.add(new selectoption('All Open' ,'All Open'));
selectopt.add(new selectoption('All Closed' ,'All Closed'));
selectopt.add(new selectoption('New' ,'New'));
selectopt.add(new selectoption('Re-open' ,'Re-open'));
selectopt.add(new selectoption('Pending' ,'Pending'));
selectopt.add(new selectoption('In Progress' ,'In Progress'));
selectopt.add(new selectoption('Approved' ,'Approved'));
selectopt.add(new selectoption('Created Story in PT' ,'Created Story in PT'));
selectopt.add(new selectoption('On Hold' ,'On Hold'));
selectopt.add(new selectoption('Resolved' ,'Resolved'));
selectopt.add(new selectoption('Closed' ,'Closed'));
return selectopt;
}
public void displaycaselist(){
caselst=new list<case>();
if(getcasetype == 'All'){
caselst=[SELECT Id, (SELECT CommentBody, LastModifiedDate, CreatedBy.Name FROM Case.CaseComments ORDER BY LastModifiedDate DESC), CreatedBy.Name, CaseNumber, ClosedDate, IsClosed, IsEscalated, Priority, Reason, Status, Subject, Type FROM Case WHERE (CreatedBy.ManagerId=:UserInfo.getUserId() OR CreatedBy.Id=:UserInfo.getUserId()) AND RecordTypeId = '012C00000007l5V'];
}
else if(getcasetype == 'All Open') {
caselst=[SELECT Id, (SELECT CommentBody, LastModifiedDate, CreatedBy.Name FROM Case.CaseComments ORDER BY LastModifiedDate DESC), CreatedBy.Name, CaseNumber, ClosedDate, IsClosed, IsEscalated, Priority, Reason, Status, Subject, Type FROM Case WHERE (status = 'New' OR status = 'Re-Open' OR status = 'Pending' OR status = 'In Progress' OR status = 'On Hold' OR status = 'Created Story in PT' OR status = 'Approved') AND (CreatedBy.ManagerId=:UserInfo.getUserId() OR CreatedBy.Id=:UserInfo.getUserId()) AND RecordTypeId = '012C00000007l5V'];
}
else if(getcasetype == 'All Closed') {
caselst=[SELECT Id, (SELECT CommentBody, LastModifiedDate, CreatedBy.Name FROM Case.CaseComments ORDER BY LastModifiedDate DESC), CreatedBy.Name, CaseNumber, ClosedDate, IsClosed, IsEscalated, Priority, Reason, Status, Subject, Type FROM Case WHERE (status = 'Closed' OR status = 'Created Story in PT' OR status = 'Resolved') AND (CreatedBy.ManagerId=:UserInfo.getUserId() OR CreatedBy.Id=:UserInfo.getUserId()) AND RecordTypeId = '012C00000007l5V'];
}
else {
caselst=[SELECT Id, (SELECT CommentBody, LastModifiedDate, CreatedBy.Name FROM Case.CaseComments ORDER BY LastModifiedDate DESC), CreatedBy.Name, CaseNumber, ClosedDate, IsClosed, IsEscalated, Priority, Reason, Status, Subject, Type FROM Case WHERE status=:getcasetype AND (CreatedBy.ManagerId=:UserInfo.getUserId() OR CreatedBy.Id=:UserInfo.getUserId()) AND RecordTypeId = '012C00000007l5V'];
}
}
}
提前致谢!!!
视觉力量代码:
<apex:page controller="displaycase">
<apex:includeScript value="{!$Resource.HistoryJS}"/>
<apex:stylesheet value="{!$Resource.HistoryCSS}" />
<apex:form id="frm"><div>Please select a Case Status</div>
<apex:selectList size="1" value="{!getcasetype}" title="Please Select a Case Status" multiselect="false">
<apex:selectOptions value="{!casestatus}"></apex:selectOptions>
<apex:actionSupport event="onselect" action="{!displaycaselist}"/>
</apex:selectList>
<apex:commandButton action="{!displaycaselist}" value="Go" id="theButton"/>
<apex:outputLabel id="pnl1" >
<apex:pageBlock >
<apex:pageblocktable value="{!caselst}" var="cse" styleClass="table" rowClasses="odd,even" cellpadding="5" border="1">
<apex:column >
<apex:facet name="header">Case Number</apex:facet>
<apex:outputPanel onclick="toggle_visibility('{!cse.CaseNumber}');" layout="block" styleClass="column1">{!cse.CaseNumber}</apex:outputPanel>
<div id="{!cse.CaseNumber}" class="list" style="display: none; cursor: pointer;" onclick="showHistory('{!cse.Id}');"><p><b>Most recent Case Comment:</b><br />{!cse.CaseComments[0].CommentBody}</p></div>
</apex:column>
<apex:column >
<apex:facet name="header">Created By</apex:facet>
<apex:outputfield value="{!cse.CreatedBy.Name}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Case Subject</apex:facet>
<apex:outputfield value="{!cse.Subject}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Case Type</apex:facet>
<apex:outputfield value="{!cse.Type}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Case Priority</apex:facet>
<apex:outputfield value="{!cse.Priority}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Case Reason</apex:facet>
<apex:outputfield value="{!cse.Reason}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Escalated</apex:facet>
<apex:outputfield value="{!cse.IsEscalated}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Closed</apex:facet>
<apex:outputfield value="{!cse.IsClosed}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Case Close Date</apex:facet>
<apex:outputfield value="{!cse.ClosedDate}"/>
</apex:column>
</apex:pageblocktable>
</apex:pageBlock>
</apex:outputLabel>
</apex:form>
</apex:page>
使用的Javascript:
function showHistory(cid) {
var content = '';
content += '<div id="frameParent">';
content += '<div id="blackoutDiv" onclick="hideHistory()"></div>';
content += '<div id="frameHolder"><a class="boxclose" id="boxclose" onclick="hideHistory()"></a>';
content += '<iframe src="https://c.cs7.visual.force.com/apex/casecomments?cid=' + cid + '" width="60%" height="60%" id="historyFrame"></iframe>';
content += '</div>';
content += '</div>';
console.log(content);
document.getElementById('contentWrapper').innerHTML += content;
}
function toggle_visibility(id) {
var e = document.getElementById(id);
if (e.style.display === 'block') {
e.style.display = 'none';
} else {
e.style.display = 'block';
hideAllBut(id);
}
}
function hideAllBut(id) {
var lists = document.querySelectorAll('div.list');
for (var i = lists.length; i--;) {
if (lists[i].id != id) {
lists[i].style.display = 'none';
}
}
}
function hideHistory() {
var el = document.getElementById('frameParent');
el.parentNode.removeChild(el);
}
document.onkeydown = function(evt) {
evt = evt || window.event;
if (evt.keyCode === 27) {
hideHistory();
}
}
document.onkeyup = function(evt) {
evt = evt || window.event;
if (evt.keyCode === 27) {
hideHistory();
}
};
以上是我正在使用的代码,我知道如何创建基本的 Visualforce 页面,这只是我有点卡住的 APEX 类,我不确定如何截断 CommentBody,所以如果有人发表评论是几千个字符长,它只会显示前 100 个左右。