Jump to content

Número dinâmico de dropdowns Java Wicket


RicardoCostaTW

Recommended Posts

Olá,

Estou a tentar criar várias dropdown na framework Wicket, mas não sei como implementar um numeor dinâmico de dropdowns porque na view só defino uma...

add(new DropDownChoice("authors",
				 new PropertyModel(author, "name"),
				 similiarAuthors, new IChoiceRenderer() {
					 @Override
					 public Object getDisplayValue(Object t) {
						 return t.toString();
					 }
					 @Override
					 public String getIdValue(Object t, int i) {
						 if (i < 0) {
							 i = 0;
						 }
						 return String.valueOf(similiarAuthors.get(i).getId());
					 }
				 }));

este pequeno snippet é suposto ser utilizado dentro de um loop para criar dinâmicamente dropdown com informação da lista similiarAuthors.

Eu não estou a conseguir porque apenas consigo definir na View uma dropdown de cada vez:

<wicket:extend>
		 <div wicket:id="label_selectBox"/>
			 <select wicket:id="authors"/>	
</wicket:extend>
Edited by RicardoCostaTW
Link to comment
Share on other sites

Descobri uma forma usando fragments.

código da view:

<wicket:fragment wicket:id="fragment1">
			    <select wicket:id="authors"/>
		    </wicket:fragment>

Código do model:

Loop loop = new Loop("list", dropDowns.size()) {
	    @Override
	    protected void populateItem(LoopItem li) {

		    int index = li.getIndex()+1;

		    String fragmentId = "fragment1";
		    li.add(new Fragment1("panel", fragmentId, dropDowns, index));


	    }
    };
    add(loop);

public class Fragment1 extends Fragment {
    public Fragment1(String id, String markupId, List<DropDownChoice> dropDowns, int index) {
	    super(id, markupId, MixBook.this);
	    add(dropDowns.get(index-1));
    }
   }
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.