Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loading html:select with values from a Map in request scope

Status
Not open for further replies.

SuperMoonster

Programmer
Aug 11, 2005
59
BR
Hello everyone,

I have not been able to load the contents of a Map in a html:select.

Here's what I'm doing. I have this action:
Code:
public class MontaBuscaColecaoAction extends Action {

    public ActionForward execute (
		ActionMapping mapping,
		ActionForm form,
		HttpServletRequest request,
		HttpServletResponse response) throws Exception {
            
                ColecaoGerenciador colecaoGer = new ColecaoGerenciador();
                Map mapa = colecaoGer.getAtributosColecao();
                
 		request.setAttribute("mapaColecao", mapa);
                return mapping.findForward("success");
	}           
    
}

As you can see, it gives puts a map in the request scope. And when I wanna load the html:select, I do:
Code:
    <html:form action="/ListaColecao.do" method="post" focus="descricao">  
      
<html:select property="colecao" > <html:options collection="mapaColecao" property="colecao" labelProperty="descricao" /> </html:select> 	<html:text property="parametro" />
	
<html:submit value="Buscar"/> 	<html:reset value="Limpar"/>


     </html:form>

It gives me an error saying "no getter method for colecao under bean mapaColecao".

Here goes my map:
Code:
    public Map getAtributosColecao(){
       Map mapa = new HashMap();
       
       mapa.put("colecao","Coleção");
       mapa.put("descricao","Descrição");
       
       return mapa;
    }

Ok, I'm doing something wrong. Just don't know what. How should I refer to the map? thanks.
 
Hi,

When you are using collections to populate the select options it is best to use LabelValueBean which comes with struts. How ever when you are using Map then it should be

Code:
<html:select property="colecao">
<html:options collection="mapaColecao" property="key"
		labelProperty="value" />
</html:select>

Hope this will hlep you,
Cheers
Venu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top