Pregunta

De acuerdo, me he golpeado la cabeza tratando de descubrir cómo solucionar este problema sin escribir código innecesario.

Tengo el siguiente código de Visualforce que está causando un error al guardar:

<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>

El error es:Error: el tipo de elemento "Opción" debe ser seguido por cualquiera de las especificaciones de atributos, ">" o "/>".

Aparentemente, el analizador de fuerza visual está molesto por una etiqueta de opción que no tiene un atributo para el {!IF(selpg.value = selectedpgtxt, 'selected','')}.

He probado el equivalente de:

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

Sin embargo, el navegador considera todas las opciones seleccionadas haciendo esto.

¿Fue útil?

Solución

A menos que esto se considera un código innecesario, lo siguiente me parece bastante sencillo.

Visualforce:

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

Apéndice:

// 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';
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top