Re: Drop Down Box - Ajax Behaviour
On Thu, 19 Feb 2009, Daniel Ferreira Castro wrote: My problem is that After I submit the form, inserting on the bank a new Category (Caategoria in Portuguese), the DropDown does not update its values list with the inserted one. That's probably best done with a pull model IModelListCategoria allCategoriesModel = new AbstracReadOnlyModelListCategoria { @Override public ListCategoria getObject() { return categoriaDao.getAllCategorias(); } } categoriaPai = new DropDownChoice(categoriaPai, categoriaPaiModel, allCategoriesModel, choiceRenderer); If the dropdown values should change when needed, you shouldn't just fetch the data on component creation and populate the dropdown with it, but have the model get fresh data on every render. Best wishes, Timo -- Timo Rantalaiho Reaktor Innovations OyURL: http://www.ri.fi/ - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Drop Down Box - Ajax Behaviour
The method getHibernateTransaction is a need :) Hibernate complains if I try to do a select without an active transaction. But this is not the case, it is working fine - no runtime errors - so it is ok at the moment :) My problem is that After I submit the form, inserting on the bank a new Category (Caategoria in Portuguese), the DropDown does not update its values list with the inserted one. Wierd also is the fact that I tryed to use the AjaxSelfUpdatingTimerBehavior to update the DropDown from time to time, but the values does not change - even with the new version inserted on the database. So, my best guess is that I am doing something wrong...the problem is find out what. I tryed to look, always do, the wicket debug console, but didn't show me the reason of the actual behaviour. On Thu, Feb 19, 2009 at 1:23 AM, Timo Rantalaiho timo.rantala...@ri.fiwrote: On Thu, 19 Feb 2009, Timo Rantalaiho wrote: AjaxFormComponentUpdatingBehavior does not submit the whole form -- for that you need to use some *submitting*behavior. Ah, now I saw that you had probably tried that? It's pretty hard to investigate what's going on -- you could try debugging Form.process() which usually gives a pretty good idea of what's happening, or prepare a quickstart with a problem and post a link here if you need more help. Best wishes, Timo -- Timo Rantalaiho Reaktor Innovations OyURL: http://www.ri.fi/ - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org -- Two rules to succeed in life: 1 - don´t tell people everything you know. We shall go on to the end. We shall fight in France We shall fightover the seas and oceans. We shall fight with growing confidence and growing strength in the air. We shall defend our island whatever the cost may be We shall fight on beaches, we shall fight on the landing grounds, We shall fight in the fields and in the streets, We shall fight on the hills. We shall never surrender. Winston Churchill
Re: Drop Down Box - Ajax Behaviour
I tryied to add the AjaxBehaviour AjaxFormComponentUpdatingBehavior(onchange) and AjaxFormComponentUpdatingBehavior(onsubmit) to the DropDown Box that I want to be updated after the form post. But didn't work yet. I am doing this way. This is the constructor of the Panel that I am using to show the Form. It is a AJAX tabbed panel that works fine. public CadastroCategoriaPanel(String id) { super(id); addHeaders(); getHibernateTransaction(); *//Gets the list from database to populate the DropDown Box that I want to be updated by AJAX *ListCategoria categorias = (ListCategoria) CategoriaDAO.getAllCategorias(hibernateSession); *//The model used by the DropDown and passed to the Form class constructor *optionModel = new CompoundPropertyModel(categorias); *//This is the form that has the DropDown Box that I want to be updated by AJAX *final CategoriaForm categoriaForm = new CategoriaForm(categoriaForm,optionModel); *//My failed attemp to use the Ajax event to update the form* categoriaForm.getCategoriaPai().add(new AjaxFormComponentUpdatingBehavior(onchange) { private static final long serialVersionUID = 1998330379948659165L; protected void onUpdate(AjaxRequestTarget target) { target.addComponent(categoriaForm.getCategoriaPai()); } }); *// Add components to the page *add(categoriaForm); closeTransaction(); closeSession(); } Please, can anyone help me? On Mon, Feb 16, 2009 at 7:34 PM, Daniel Ferreira Castro dfcas...@gmail.comwrote: *This is my form source code* package com.jasp.ecommfwk.pages.forms; import java.io.Serializable; import java.util.List; import org.apache.log4j.Logger; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior; import org.apache.wicket.ajax.form.AjaxFormSubmitBehavior; import org.apache.wicket.ajax.markup.html.form.AjaxButton; import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.form.DropDownChoice; import org.apache.wicket.markup.html.form.Form; import org.apache.wicket.markup.html.form.TextField; import org.apache.wicket.markup.html.panel.FeedbackPanel; import org.apache.wicket.model.CompoundPropertyModel; import org.apache.wicket.model.Model; import org.apache.wicket.model.StringResourceModel; import org.hibernate.Transaction; import org.hibernate.classic.Session; import com.jasp.ecommfwk.util.markup.html.form.CategoriaChoiceRenderer; import com.jasp.persistence.hierarchy.Categoria; import com.jasp.persistence.hierarchy.dao.CategoriaDAO; import com.jasp.persistence.util.HibernateUtil; @SuppressWarnings(unchecked) public class CategoriaForm extends FormCategoria implements Serializable { private static final long serialVersionUID = -1940617589157076677L; private static Logger logger = Logger.getLogger(CategoriaForm.class); private Session hibernateSession; private transient Transaction hibernateTransaction; // Textos i18n carregados aqui private final StringResourceModel labelCategoriaValue = new StringResourceModel( categoria.label, this, null, new Object[] { getLocale() }); private final StringResourceModel labelPaiValue = new StringResourceModel( categoria.labelPai, this, null, new Object[] { getLocale() }); // End of i18n load // Declare component's form private DropDownChoice categoriaPai; private TextField nomeCategoria; private Label labelCategoria; private Label labelCategoriaPai; private CategoriaChoiceRenderer choiceRenderer; private AjaxButton cadastrar; private FeedbackPanel feedbackPanel; private void inicializaComponentesForm() { categoriaPai = criaCategoriaPaiDropdown(); nomeCategoria = criaNomeCategoriaTextField(); nomeCategoria.setRequired(true); labelCategoria = new Label(labelCategoria, labelCategoriaValue); labelCategoriaPai = new Label(labelCategoriaPai, labelPaiValue); cadastrar = new AjaxButton(cadastrar, this) { private static final long serialVersionUID = 6045168066074475539L; @Override protected void onSubmit(AjaxRequestTarget target, Form? form) { getHibernateTransaction(); int idBanco = Integer.parseInt(categoriaPai.getValue()); Categoria escolhida = null; Categoria nova = new Categoria(); nova.setNome(nomeCategoria.getValue()); hibernateSession.persist(nova); if (0 idBanco) { escolhida = new Categoria(idBanco); hibernateSession.clear(); //Seto o pai nova.setCategoriaPai(escolhida);
Re: Drop Down Box - Ajax Behaviour
On Wed, 18 Feb 2009, Daniel Ferreira Castro wrote: AjaxFormComponentUpdatingBehavior(onchange) and AjaxFormComponentUpdatingBehavior(onsubmit) to the DropDown Box that I want to be updated after the form post. But didn't work yet. onsubmit probably doesn't exist for select. Have you looked at the ajax debug console (available when running Wicket in development mode, e.g. -Dwicket.configuration=DEVELOPMENT )? getHibernateTransaction(); That sounds strange, by the way. *//My failed attemp to use the Ajax event to update the form* categoriaForm.getCategoriaPai().add(new AjaxFormComponentUpdatingBehavior(onchange) { private static final long serialVersionUID = 1998330379948659165L; protected void onUpdate(AjaxRequestTarget target) { target.addComponent(categoriaForm.getCategoriaPai()); } }); You're just updating categoriaPai with the values from the server, whenever its selection is changed, without ever submitting them to the server. AjaxFormComponentUpdatingBehavior does not submit the whole form -- for that you need to use some *submitting*behavior. Look at the source code of the different Ajax*Form*Behavior to see better what they do. Best wishes, Timo -- Timo Rantalaiho Reaktor Innovations OyURL: http://www.ri.fi/ - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Drop Down Box - Ajax Behaviour
Where do yo u have the values in the DropDown in the first place? If you use a model, why not updating it? Eyal Golan egola...@gmail.com Visit: http://jvdrums.sourceforge.net/ LinkedIn: http://www.linkedin.com/in/egolan74 P Save a tree. Please don't print this e-mail unless it's really necessary On Mon, Feb 16, 2009 at 2:13 PM, Daniel Ferreira Castro dfcas...@gmail.comwrote: I read the examples of Ajax Forms and I am trying to adapt it to my needs. I have a form with a input text, a drop down box, a feedback panel and a submit button. My submit is an ajaxButton. My form setsOutputMarkupId(true); My dropdown sets OutputMarkupId(true); When I submit my form it inserts an item on a table. My intention is after the form submit the dropdown uptades itself, adding the previously inserted item to its options. how to do it? -- Two rules to succeed in life: 1 - don´t tell people everything you know. We shall go on to the end. We shall fight in France We shall fightover the seas and oceans. We shall fight with growing confidence and growing strength in the air. We shall defend our island whatever the cost may be We shall fight on beaches, we shall fight on the landing grounds, We shall fight in the fields and in the streets, We shall fight on the hills. We shall never surrender. Winston Churchill
Re: Drop Down Box - Ajax Behaviour
I have this method that is run on the momento of the form construction The ListCategoria keyValuePairsTemp stores the values of the DropDown private DropDownChoice criaCategoriaPaiDropdown() { setOutputMarkupId(true); choiceRenderer = new CategoriaChoiceRenderer(); getHibernateTransaction(); ListCategoria keyValuePairsTemp = (ListCategoria) CategoriaDAO .getAllCategorias(hibernateSession); Categoria categoria = null; // Trata o caso de não existir categoria cadastrada if (keyValuePairsTemp.size() 1) { categoria = new Categoria(); } else { categoria = keyValuePairsTemp.get(0); } PropertyModel categoriaPaiModel = new PropertyModel(categoria, categoriaPai); categoriaPai = new DropDownChoice(categoriaPai, categoriaPaiModel, keyValuePairsTemp, choiceRenderer); return categoriaPai; } On Mon, Feb 16, 2009 at 11:06 AM, Eyal Golan egola...@gmail.com wrote: Where do yo u have the values in the DropDown in the first place? If you use a model, why not updating it? Eyal Golan egola...@gmail.com Visit: http://jvdrums.sourceforge.net/ LinkedIn: http://www.linkedin.com/in/egolan74 P Save a tree. Please don't print this e-mail unless it's really necessary On Mon, Feb 16, 2009 at 2:13 PM, Daniel Ferreira Castro dfcas...@gmail.comwrote: I read the examples of Ajax Forms and I am trying to adapt it to my needs. I have a form with a input text, a drop down box, a feedback panel and a submit button. My submit is an ajaxButton. My form setsOutputMarkupId(true); My dropdown sets OutputMarkupId(true); When I submit my form it inserts an item on a table. My intention is after the form submit the dropdown uptades itself, adding the previously inserted item to its options. how to do it? -- Two rules to succeed in life: 1 - don´t tell people everything you know. We shall go on to the end. We shall fight in France We shall fightover the seas and oceans. We shall fight with growing confidence and growing strength in the air. We shall defend our island whatever the cost may be We shall fight on beaches, we shall fight on the landing grounds, We shall fight in the fields and in the streets, We shall fight on the hills. We shall never surrender. Winston Churchill -- Two rules to succeed in life: 1 - don´t tell people everything you know. We shall go on to the end. We shall fight in France We shall fightover the seas and oceans. We shall fight with growing confidence and growing strength in the air. We shall defend our island whatever the cost may be We shall fight on beaches, we shall fight on the landing grounds, We shall fight in the fields and in the streets, We shall fight on the hills. We shall never surrender. Winston Churchill
Re: Drop Down Box - Ajax Behaviour
*This is my form source code* package com.jasp.ecommfwk.pages.forms; import java.io.Serializable; import java.util.List; import org.apache.log4j.Logger; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior; import org.apache.wicket.ajax.form.AjaxFormSubmitBehavior; import org.apache.wicket.ajax.markup.html.form.AjaxButton; import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.form.DropDownChoice; import org.apache.wicket.markup.html.form.Form; import org.apache.wicket.markup.html.form.TextField; import org.apache.wicket.markup.html.panel.FeedbackPanel; import org.apache.wicket.model.CompoundPropertyModel; import org.apache.wicket.model.Model; import org.apache.wicket.model.StringResourceModel; import org.hibernate.Transaction; import org.hibernate.classic.Session; import com.jasp.ecommfwk.util.markup.html.form.CategoriaChoiceRenderer; import com.jasp.persistence.hierarchy.Categoria; import com.jasp.persistence.hierarchy.dao.CategoriaDAO; import com.jasp.persistence.util.HibernateUtil; @SuppressWarnings(unchecked) public class CategoriaForm extends FormCategoria implements Serializable { private static final long serialVersionUID = -1940617589157076677L; private static Logger logger = Logger.getLogger(CategoriaForm.class); private Session hibernateSession; private transient Transaction hibernateTransaction; // Textos i18n carregados aqui private final StringResourceModel labelCategoriaValue = new StringResourceModel( categoria.label, this, null, new Object[] { getLocale() }); private final StringResourceModel labelPaiValue = new StringResourceModel( categoria.labelPai, this, null, new Object[] { getLocale() }); // End of i18n load // Declare component's form private DropDownChoice categoriaPai; private TextField nomeCategoria; private Label labelCategoria; private Label labelCategoriaPai; private CategoriaChoiceRenderer choiceRenderer; private AjaxButton cadastrar; private FeedbackPanel feedbackPanel; private void inicializaComponentesForm() { categoriaPai = criaCategoriaPaiDropdown(); nomeCategoria = criaNomeCategoriaTextField(); nomeCategoria.setRequired(true); labelCategoria = new Label(labelCategoria, labelCategoriaValue); labelCategoriaPai = new Label(labelCategoriaPai, labelPaiValue); cadastrar = new AjaxButton(cadastrar, this) { private static final long serialVersionUID = 6045168066074475539L; @Override protected void onSubmit(AjaxRequestTarget target, Form? form) { getHibernateTransaction(); int idBanco = Integer.parseInt(categoriaPai.getValue()); Categoria escolhida = null; Categoria nova = new Categoria(); nova.setNome(nomeCategoria.getValue()); hibernateSession.persist(nova); if (0 idBanco) { escolhida = new Categoria(idBanco); hibernateSession.clear(); //Seto o pai nova.setCategoriaPai(escolhida); hibernateSession.merge(nova); } hibernateTransaction.commit(); closeTransaction(); String mensageSucesso = Categoria + nova.getNome() + cadastrada com sucesso!; info(mensageSucesso); target.addComponent(feedbackPanel); /* This is the part that I am having trouble with. The idea is after the form submission the Dropdown categoriaPai should be updated with the recent created item */ this.add(new AjaxFormSubmitBehavior(onchange){ @Override protected void onError(AjaxRequestTarget target) { // TODO Auto-generated method stub } @Override protected void onSubmit(AjaxRequestTarget target) { // TODO Auto-generated method stub target.addComponent(categoriaPai); } }); } @Override protected void onError(AjaxRequestTarget target, Form? form) { // repaint the feedback panel so errors are shown target.addComponent(feedbackPanel); } }; } public CategoriaForm(String id) { super(id); setOutputMarkupId(true); inicializaComponentesForm(); feedbackPanel = criaFeedbackPanel(); // Adicionando todos os componentes ao form this.add(categoriaPai); this.add(nomeCategoria); this.add(labelCategoria); this.add(labelCategoriaPai); this.add(cadastrar); this.add(feedbackPanel); } /* This is the method used