Salesforce使用XML并在Visualforce报告中显示数据 [英] Salesforce consuming XML and display data in Visualforce report

查看:102
本文介绍了Salesforce使用XML并在Visualforce报告中显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,这个问题需要一些介绍,请耐心等待.

Firstly, this question requires a bit of introduction so please bear with me.

高级是我正在连接到外部Web服务,该服务将一些XML返回到我的apex控制器.我的想法是,我想在VisualForce页面中显示以漂亮的表格格式返回的XML.返回的XML格式如下所示:

The high level is that I am connecting to a outside web service which will return some XML to my apex controller. The idea is that I want to display the XML returned into a nice tabular format in a VisualForce page. The format of the XML coming back will look something like this:

<Wrapper><reportTable name='table_id' title='Report Title'>
  <row>
    <Element1><![CDATA[campaign_id]]></Element1>
    <Element2><![CDATA[577373]]></Element2>
    <Element3><![CDATA[4129]]></Element3>
    <Element4 dataFormat='2' dataSuffix='%'><![CDATA[0.7151]]></Element4>
    <Element5><![CDATA[2010-04-04]]></Element5>
    <Element6><![CDATA[2010-05-03]]></Element6>
  </row>
</reportTable>

...

现在,我现在正在使用XMLdom实用程序类(由SF为XML函数开发),以将该数据映射到包含行"自定义对象列表的自定义对象"reportTable".之所以以这种方式构建它,是因为我不知道每行中有多少个元素,也不知道行数.

Now currently I am using the XMLdom utility class (developed by SF for XML functions) to map this data into a custom object "reportTable" which contains a list of "row" custom objects. The reason I am building it out this way is because I don't know how many elements will be in each row, nor the number of rows.

Visualforce页面看起来像这样:

The Visualforce page looks something like this:

<table><apex:repeat value="{!reportTables}" var="table">
  <apex:repeat value="{!table.rows}" var="row">
  <tr>
   <apex:repeat value="{!row.ColumnValue}" var="column">
    <apex:repeat value="{!column}" var="value">
     <td>
     <apex:outputText value="{!value}" />
     </td>
    </apex:repeat>
   </apex:repeat>
   </tr>
  </apex:repeat>

问题是:

1)这似乎是解决问题的好方法吗?

1) Does this seem like a good approach to the problem?

2)除了编写自己的自定义对象以将VF映射到之外,还有没有更简单/更好的方式来使用XML?

2) Is there a simpler/better way to consume the XML besides writing my own custom objects to map VF to?

打开所有建议.我真的希望有比自己构建HTML表更好的方法,因为那样的话我还必须处理样式和对齐方式等问题.谢谢.

Open to any and all suggestions. I really hope there is a better way than building the HTML table myself, as then I also have to deal with styling and alignment etc. Thanks.

推荐答案

由于您将XML直接返回给控制器,因此请定义并使用一个包装类,该包装类具有每个XML的属性(即使是未定义行长的其他集合)需要节点.通常需要做的是显示来自多个对象的表格数据.包装对象的集合将允许您遍历它们,并使用点表示法访问类中的字段.

Since you're returning the XML directly to your controller, define and use a wrapper class, with properties (even additional collections for undefined row lengths) for each XML node needed. It's often what needs to be done to display tabular data from across multiple objects. A collection of your wrapper objects will allow you to iterate over them, and use dot notation to access the fields in the class.

这篇关于Salesforce使用XML并在Visualforce报告中显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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