salesforce 从 sObject 转换为自定义对象
我编写了一个基本控制器,我想用它来管理服务器控制器上的数据分页。
我有一个像这样的抽象方法
public abstract List<sObject> getPagedData();
然后我的每个扩展基本控制器的控制器都实现了自己的 getPagedData 版本。但返回特定的客户对象,例如 Foo__c
我可以在 Visualforce 页面中从 List
转换为 List
我的页面看起来像但是
<apex:dataTable value="{!PagedData}" var="c" >
<apex:column >
<apex:facet name="header">Foo</apex:facet>
<apex:outputText value="{!c.Bar__r.SomeValue__c]}" />
</apex:column>
我收到一个错误,表明 sObject 不知道 Bar__r
我已尝试使用 dataTable 值和 outputText 内部进行强制转换,但它似乎不起作用
我可以使用动态绑定http://www.salesforce.com/us/developer/docs /pages/Content/pages_dynamic_vf.htm 但我该如何做类似的事情,
<apex:outputText value="{0, number, $###,###}">
<apex:param value="{!c.Amount__c}" />
</apex:outputText>
<apex:outputText value="{0,date,dd/MM/yyyy}">
<apex:param value="{!c.Date_Of_Birth__c}" />
</apex:outputText>
因为我收到错误,说它需要一个 DateTime 对象等
I have written a Base controller that I want to use to manage data pagination on sever controllers.
I have an abstract method like so
public abstract List<sObject> getPagedData();
Then each of my controllers that extend the base controller implement their own version of getPagedData. But return a specific customer object e.g Foo__c
Can I Cast from List<sObject>
to List<Foo__c>
in a visualforce page
My page looks like this
<apex:dataTable value="{!PagedData}" var="c" >
<apex:column >
<apex:facet name="header">Foo</apex:facet>
<apex:outputText value="{!c.Bar__r.SomeValue__c]}" />
</apex:column>
But I get an error that sObject does not have know about Bar__r
I have tried doing a Cast with the dataTable value and inside the outputText but it does not seem to work
I can use dyamic bindings http://www.salesforce.com/us/developer/docs/pages/Content/pages_dynamic_vf.htm but then how do i do things like
<apex:outputText value="{0, number, $###,###}">
<apex:param value="{!c.Amount__c}" />
</apex:outputText>
<apex:outputText value="{0,date,dd/MM/yyyy}">
<apex:param value="{!c.Date_Of_Birth__c}" />
</apex:outputText>
As i get errors as saying it expects a DateTime object etc
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
去过那里。不幸的是,没有办法直接在 Visualforce 页面中投射对象。
我解决这个问题的方法是将所有分页逻辑以通用形式移至基本控制器中,然后让子控制器负责将数据转换为 Visualforce 页面期望的形式。
您还可以考虑使用 StandardSetController 来控制分页。它非常适合自定义对象和大多数标准对象,但不适用于自定义 ApexClass 和某些标准对象。也就是说,您仍然需要转换结果集,因为它从 getRecords() 方法返回一个列表。
Been there. Unfortunately, there isn't a way to cast objects directly in the visualforce page.
The way I've addressed this is to move all the pagination logic into your base controller in generic form and then have the child controllers take on the responsibility for casting the data into the form your visualforce page expects.
You might also consider using the StandardSetController to control your pagination. It works great for custom objects and most standard objects, but not for custom ApexClasses and some standard objects. That said you'll still need to cast your result set as it to returns a List from its getRecords() method.