2011-12-03 41 views
0

好吧,我一直在努力研究如何在不寫入不必要的代碼的情況下解決此問題。創建頂點時出現Visualforce錯誤:重複選擇選項

我有保存時,就導致一個錯誤以下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> 

錯誤是: 錯誤:元素類型「選項」必須跟任一屬性規格,「>」或「/>」。

顯然,視覺力解析器對於不具有{!IF(selpg.value = selectedpgtxt, 'selected','')}屬性的選項標籤感到不安。

我已經試過相當於:

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

但是瀏覽器將考慮所有的選擇這樣的選項。

回答

3

除非這被認爲是不必要的代碼,以下對我來說似乎很簡單。

Visualforce:

<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'; 
+0

謝謝,不知道爲什麼我沒有用頂點:選擇列表的擺在首位。猜猜我剛剛修好了關於

+0

沒問題。我通常會嘗試找到「Force.com認可的路徑」來完成任務(如果有的話),因爲一次又一次,我發現自己在雜草中試圖獲得JavaScript/CSS/HTML來執行Force.com提供的功能本身。 Visualforce預處理器中的ID /名稱也會引起人們的注意(請參閱$ Component:http://www.salesforce.com/us/developer/docs/pages/Content/pages_variables_global.htm)。 – Adam