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

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

问题描述

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

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

最重要的是,我正在连接到外部 Web 服务,该服务将向我的顶点控制器返回一些 XML.这个想法是我想在 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天全站免登陆