错误:下标值 9 无效。必须介于 0 到 8 之间
这是我的 vf 页面,我在 conList
的 BadgeController
中获取 9 条记录,即 conList[0]
到 conList[8]
。
我使用变量 first
和 second
作为 List 的下标。
我在每个 apex:repeat 中将变量的值增加 2,它从 0 到 2 工作正常。
但是当变量变为 9 时,它会显示如下错误:
下标值 9 无效。必须介于 0 和 8 之间。
如何防止变量自增?
如何在 if .. else 条件下中断代码的执行?
<apex:page standardController="Event__c" extensions="BadgeController" showHeader="false" sidebar="false" renderAs="pdf">
<html>
<head>
</head>
<center>
<apex:variable var="first" value="{!0}" id="id3"/>
<apex:variable var="second" value="{!1}" id="id4"/>
<apex:repeat value="{!conList}" >
<apex:variable var="first" value="{!first+ 2}" id="id1"/>
<apex:variable var="second" value="{!second+ 2}" id="id2"/>
<table><tr><td>
<table BORDER="2" RULES="NONE" FRAME="BOX">
<tr>
<td>
<table height="100px" width="300px" border="1" align="center" cellspacing="30">
<tr>
<td><center><apex:outputField value="{!conList[first].AccountContact__r.FirstName}"/></center></td>
</tr>
</table>
</td>
</tr>
</table></td>
<td></td>
<td>
<table BORDER="2" RULES="NONE" FRAME="BOX">
<tr>
<td>
<table height="100px" width="300px" border="1" align="center" cellspacing="30">
<tr>
<td><center><apex:outputField value="{!conList[second].AccountContact__r.FirstName}"/></center></td>
</tr>
</table>
</td>
</tr>
</table>
</td></tr></table> <br></br><br></br>
</apex:repeat>
</center>
</html>
</apex:page>
This is my vf page, I am getting 9 records in BadgeController
in conList
, i.e. conList[0]
to conList[8]
.
I am using variables first
and second
as a subscript to List.
I am incrementing value of variable by 2 in each apex:repeat, it works fine from 0 to 2.
But when variable become 9 it is showing error like:
Subscript value 9 not valid. Must be between 0 and 8 .
How to prevent variable from incrementing?
how to break the execution of code in if .. else condition?
<apex:page standardController="Event__c" extensions="BadgeController" showHeader="false" sidebar="false" renderAs="pdf">
<html>
<head>
</head>
<center>
<apex:variable var="first" value="{!0}" id="id3"/>
<apex:variable var="second" value="{!1}" id="id4"/>
<apex:repeat value="{!conList}" >
<apex:variable var="first" value="{!first+ 2}" id="id1"/>
<apex:variable var="second" value="{!second+ 2}" id="id2"/>
<table><tr><td>
<table BORDER="2" RULES="NONE" FRAME="BOX">
<tr>
<td>
<table height="100px" width="300px" border="1" align="center" cellspacing="30">
<tr>
<td><center><apex:outputField value="{!conList[first].AccountContact__r.FirstName}"/></center></td>
</tr>
</table>
</td>
</tr>
</table></td>
<td></td>
<td>
<table BORDER="2" RULES="NONE" FRAME="BOX">
<tr>
<td>
<table height="100px" width="300px" border="1" align="center" cellspacing="30">
<tr>
<td><center><apex:outputField value="{!conList[second].AccountContact__r.FirstName}"/></center></td>
</tr>
</table>
</td>
</tr>
</table>
</td></tr></table> <br></br><br></br>
</apex:repeat>
</center>
</html>
</apex:page>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不太确定你在这里问什么,但听起来你只是想在列表中显示交替值。这是 Apex 的工作(如果您真的不想编写任何 Apex 代码,则可能是 JavaScript,但如果您打算在 Force.com 上停留一段时间,您应该了解 Apex)。在 Apex 中,您可以对列表执行任何您喜欢的操作,并显示您需要显示的任何内容,而无需将演示文稿与业务逻辑紧密耦合。来自 Visualforce 开发人员指南:
因此,这里有一个 Apex 示例,它创建两个可供 Visualforce 显示的交替元素列表:
现在,您可以在 Visualforce 中显示两个不同的列表,这些列表具有原始 SOQL 中的偶数/奇数行号:
或者只需修改 Apex 以生成包含任何内容的单个列表您希望的行顺序并显示它。
希望有帮助。
I'm not exactly sure what you're asking here, but it sounds like you simply want to display alternating values in a list. This is a job for Apex (or perhaps JavaScript if you really don't want to code any Apex, though you should get to know Apex if you plan to remain on Force.com for a while). In Apex you can do whatever you like with lists and display whatever you need to display without tightly coupling your presentation with your business logic. From the Visualforce Developer's Guide:
So here's an Apex sample that creates two lists of alternating elements for Visualforce to display:
Now you can display two different lists in Visualforce that have even/odd row numbers from your original SOQL:
Or just modify the Apex to produce a single list with whatever row order you wish and display that.
Hope that helps.