设置数据表中选项列表的默认值
我正在尝试在数据表中创建动态选择列表。我可以使用单个选项列表设置默认值,但当有多个选项列表时则不能。我还需要能够在任何行上存储更改后的值,希望将其绑定到列表中的某个变量。
为了实现这一点,我在我正在使用的对象(称为 Vendor)上创建了一个新字段,称为“selected_vendor__c”:
<apex:column headerValue="Vendor">
<apex:selectList value="{!i.selected_vendor__c}" size="1" required="true" >
<apex:selectOptions value="{!VendorList}"/>
</apex:selectList>
然后是控制器:
public List<selectOption> VendorList {get {
List<selectOption> myVendorList = new List<selectOption>();
for (Vendor__c vend : [select Name,id from Vendor__c])
myVendorList.add(new selectOption(vend.id, vend.name));
return myVendorList;
}
private set;
}
我遇到的问题是选项列表中的值始终是列表中的第一个选项,而不是我尝试动态设置它的值。我希望保存时将其绑定到“{!i.selected_vendor__c}”,但我无法将其设置为默认值。
I am trying to create a dynamic picklist in a datatable. I can set the default value with a single picklist, but not when there are multiple ones. I also need to be able to store the value of whatever it is changed to on any row, which will hopefully be bound to some variable in a list.
To accomplish this I created a new field on the object I'm using (called Vendor), called "selected_vendor__c":
<apex:column headerValue="Vendor">
<apex:selectList value="{!i.selected_vendor__c}" size="1" required="true" >
<apex:selectOptions value="{!VendorList}"/>
</apex:selectList>
And then here is the controller:
public List<selectOption> VendorList {get {
List<selectOption> myVendorList = new List<selectOption>();
for (Vendor__c vend : [select Name,id from Vendor__c])
myVendorList.add(new selectOption(vend.id, vend.name));
return myVendorList;
}
private set;
}
The problem I'm having is that the value in the picklist is always the first option from the list, not what I try to set it to dynamically. I'm hoping that it will be bound to "{!i.selected_vendor__c}" when saving, but I can't get it to be set to a default.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我自己想出了这个办法。问题是 i.selected_vendor__c 的值需要是与供应商列表对应的 id,而不是名称。
I figured this out myself. The issue is that the value of i.selected_vendor__c needed to be the id corresponding to the vendor list, not the name.