Olá, pessoal :!:
Bom, estou iniciando o estudo do framework struts, e estou precisando da ajuda dos + experientes.
O problema ocorre quando tento usar <html:optionsCollection>. A página simplismente não "carrega", possívelmente por causa de algum erro de sintaxe, sei lá.
Já fiz várias tentativas, mas nada…
Vou listar partes do código pra vcs:
1) Classe JavaBean que possui o "label" e o "value" a ser mostrado na tag option
[code]package strutsdemo.model;
import java.io.Serializable;
public class FaixasIdade implements Serializable {
final int value;
final String label;
public FaixasIdade( int value, String label ){
this.value = value;
this.label = label;
}
public int getValue( ){
return value;
}
public String getLabel( ){
return label;
}
}[/code]
2) Método "editar", da classe que estende DispatchAction
public ActionForward editar(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
ActionMessages errors = new ActionMessages( );
try{
...
request.setAttribute( "usuario", user);
faixas = new LinkedList( );
String[] titulos = {"até 20", "de 20 a 30", "de 30 a 40", "de 40 a 50", "acima de 50"};
for( int i =0; i < titulos.length; i++ )
faixas.add( new FaixasIdade( ( i + 1 ), titulos[ i ] ));
request.setAttribute( "faixas", faixas );
...
}[/code]
[b]3)[/b] Pedaços da página form.jsp
[code]Faixas:
[u]Pedaço 1[/u]
<%
java.util.Iterator it = ( ( java.util.List ) request.getAttribute("faixas") ).iterator( );
while( it.hasNext( )){
strutsdemo.model.FaixasIdade faixas = ( strutsdemo.model.FaixasIdade ) it.next( );
out.println( "<br> Label: " + faixas.getLabel( ) + " e Value: " + faixas.getValue( ));
}
%>
...
[u]Pedaço 2[/u]
<c:forEach var="fx" items="${faixas}">
Label: ${fx.label} e Value: ${fx.value}
</c:forEach>
...
[u]Pedaço 3[/u]
<td>
<html:select name="usuario" property="faixaIdade">
<html:optionsCollection property="faixas" label="label" value="value"/>
</html:select>
</td>
Sendo que as partes abaixo funcionam normalmente …
<%
java.util.Iterator it = ( ( java.util.List ) request.getAttribute("faixas") ).iterator( );
while( it.hasNext( )){
strutsdemo.model.FaixasIdade faixas = ( strutsdemo.model.FaixasIdade ) it.next( );
out.println( "<br> Label: " + faixas.getLabel( ) + " e Value: " + faixas.getValue( ));
}
%>
<c:forEach var="fx" items="${faixas}">
Label: ${fx.label} e Value: ${fx.value}
</c:forEach>
… porém, ao acrescentar optionsCollection …
<td>
<html:select name="usuario" property="faixaIdade">
<html:optionsCollection property="faixas" label="label" value="value"/>
</html:select>
</td>
… tudo desanda :roll:
O que está errado com a declaração desta tag?
Aguardo a ajuda, galera!
[]'s