创建顶点时出现 Visualforce 错误:在选择选项上重复

发布于 2024-12-19 11:54:30 字数 746 浏览 3 评论 0原文

好吧,我一直在绞尽脑汁试图弄清楚如何在不编写不必要的代码的情况下解决这个问题。

我有以下 Visualforce 代码,在保存时导致错误:

<select id="rec_count">
    <apex:repeat value="{!pg}" var="selpg">
        <option {!IF(selpg.value = selectedpgtxt, 'selected','')} value="{!selpg.value}" >
              {!selpg.value}
        </option>
    </apex:repeat>
</select>

错误是: 错误:元素类型“option”后必须跟有属性规范“>”或“/>”。

显然,视觉强制解析器对选项标签没有 {!IF(selpg.value = selectedpgtxt, 'selected','')}< /代码>。

我已经尝试过等效的操作:

<option selected="" value="1">1</option>
<option selected="selected" value="2">2</option>

但是浏览器会考虑执行此操作所选择的所有选项。

Okay, I've been banging my head trying to figure out how to get around this issue without writing unnecessary code.

I have the following Visualforce code that is causing a error when saving:

<select id="rec_count">
    <apex:repeat value="{!pg}" var="selpg">
        <option {!IF(selpg.value = selectedpgtxt, 'selected','')} value="{!selpg.value}" >
              {!selpg.value}
        </option>
    </apex:repeat>
</select>

The error is:
Error: Element type "option" must be followed by either attribute specifications, ">" or "/>".

Apparently the visual force parser is upset about a option tag not having a attribute for the {!IF(selpg.value = selectedpgtxt, 'selected','')}.

I have tried the equivalent of:

<option selected="" value="1">1</option>
<option selected="selected" value="2">2</option>

However browser considers all of the options selected doing this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

提笔落墨 2024-12-26 11:54:30

除非这被认为是不必要的代码,否则以下对我来说似乎非常简单。

视觉力:

<apex:selectList value="{!theSelection}">
   <apex:selectOptions value="{!theList}"/>
</apex:selectList>

顶点:

// Top of class
public List<SelectOption> theList {get; private set;}
public String theSelection {get; set;}


// In constructor
this.theList = new List<SelectOption>();
this.theList.add(new SelectOption('1', 'First Option'));
this.theList.add(new SelectOption('2', 'Second Option'));

// Now for the default
this.theSelection = '1';

Unless this is considered unnecessary code, the following seems pretty straightforward to me.

Visualforce:

<apex:selectList value="{!theSelection}">
   <apex:selectOptions value="{!theList}"/>
</apex:selectList>

Apex:

// Top of class
public List<SelectOption> theList {get; private set;}
public String theSelection {get; set;}


// In constructor
this.theList = new List<SelectOption>();
this.theList.add(new SelectOption('1', 'First Option'));
this.theList.add(new SelectOption('2', 'Second Option'));

// Now for the default
this.theSelection = '1';
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文