|
|
|
Marcelo Grassi Franco Melgaço
|
Hello.
I'm using click 1.4.2 I have a form with two fields and one hidden field. I have a submit button for this form with a method binded on it. The problem is when i click in the submit button the method is called two times in the same request. What should cause this problem ? Thanks! ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Click-user mailing list Click-user@... https://lists.sourceforge.net/lists/listinfo/click-user |
|
sabob
|
Hi Marcelo,
Marcelo Grassi Franco Melgaço wrote: > I have a form with two fields and one hidden field. > I have a submit button for this form with a method binded on it. > The problem is when i click in the submit button the method is called > two times in the same request. > What should cause this problem ? Perhaps the method is bounded to another component as well? Perhaps Form? Can you post an example for us to look at? kind regards bob ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Click-user mailing list Click-user@... https://lists.sourceforge.net/lists/listinfo/click-user |
|||||||||||||||||
|
Marcelo Grassi Franco Melgaço
|
Hello Bob,
here is the .java of the page. The method is onSaveClick I fixed the problem saving a request attribute in the first time the method is called and testing this attribute in the next time, returning true if the attribute is not null in the line: if (getContext().getRequestAttribute("jaGravou")!=null){return true;} Did i do something wrong in the code that may causing this ? Thanks for any help! 2008/7/16 bob <sabob1@...>: Hi Marcelo, [ClasseCliente.java] package br.com.gtec.page.classes; import java.util.Collection; import net.sf.click.control.FieldSet; import net.sf.click.control.Form; import net.sf.click.control.HiddenField; import net.sf.click.control.Option; import net.sf.click.control.Select; import net.sf.click.control.Submit; import net.sf.click.control.TextField; import br.com.gtec.classes.modelo.interfaces.ManutencaoClasses; import br.com.gtec.classes.to.ClasseClienteTO; import br.com.gtec.control.TreeGtec; import br.com.gtec.excecoes.ExcecaoGenerica; import br.com.gtec.excecoes.ExcecaoNegocio; import br.com.gtec.excecoes.ExcecaoSistema; import br.com.gtec.modelo.ServiceLocator; import br.com.gtec.page.Modelo; import br.com.gtec.seguranca.Sessao; import br.com.gtec.util.Util; public class ClasseCliente extends Modelo{ public String titulo = "Cadastro de Classes de Cliente"; private Form form = new Form("form"); private TreeGtec tree; public String msg; private Select codClassePai = new Select("codClassePai", "Classe Pai", false); private Submit excluir = new Submit("excluir", "Excluir", this, "onDeleteClick"); public ClasseCliente(){ addControl(form); } /** * @see net.sf.click.Page#onInit() */ public void onInit() { super.onInit(); tree = new TreeGtec("tree", "Classe de cliente", "codClasse", "descricao", "classeClienteFilhos"); tree.setLinkEdicao(getContext().getRequest().getContextPath()+getPath()); addControl(tree); FieldSet fieldSet = new FieldSet("Classe de Cliente"); fieldSet.add(codClassePai); TextField descricao = new TextField("descricao", "Descrição", true); descricao.setSize(20); descricao.setMaxLength(20); fieldSet.add(descricao); form.add(fieldSet); //botoes form.add(new Submit("save", "Gravar", this, "onSaveClick")); form.add(new Submit("cancel", "Novo", this, "onCancelClick")); excluir.setStyle("display", "none"); form.add(excluir); fieldSet.add(new HiddenField("codClasse", Integer.class)); codClassePai.add(Option.EMPTY_OPTION); try{ ManutencaoClasses manut = ServiceLocator.get(ManutencaoClasses.class); Collection<ClasseClienteTO> itens = manut.listarClasseClienteTodos(((Sessao)getContext().getSessionAttribute("sessao")).getCodCliente()); codClassePai.addAll(Util.criaOptionTO(itens, "codClasse", "descricao")); preecheTree(manut); }catch(ExcecaoGenerica e){ form.setError(e.getMessage()); e.printStackTrace(); return; } } private void preecheTree(ManutencaoClasses manut) throws ExcecaoNegocio, ExcecaoSistema { Collection<ClasseClienteTO> tos = manut.listarClasseCliente(((Sessao)getContext().getSessionAttribute("sessao")).getCodCliente()); tree.setItens(tos); } @SuppressWarnings("unchecked") public boolean onSaveClick() { if (form.isValid()) { ClasseClienteTO to = new ClasseClienteTO(); form.copyTo(to); to.setCodClienteGtec(((Sessao)getContext().getSessionAttribute("sessao")).getCodCliente()); if (getContext().getRequestAttribute("jaGravou")!=null){ return true; }else{ getContext().setRequestAttribute("jaGravou","true"); } try{ ManutencaoClasses manut = ServiceLocator.get(ManutencaoClasses.class); form.getField("codClasse").setValueObject(manut.gravarClasseCliente(to)); preecheTree(manut); }catch(ExcecaoGenerica e){ form.setError(e.getMessage()); e.printStackTrace(); return true; } msg = "Classe de cliente gravada com sucesso"; //preencheTree(); // excluir.setStyle("display", "block"); //codClassePai.setReadonly(true); form.clearValues(); form.clearErrors(); } return true; } public boolean onCancelClick() { form.clearValues(); form.clearErrors(); excluir.setStyle("display", "none"); codClassePai.setReadonly(false); return true; } public boolean onDeleteClick() { try{ ManutencaoClasses manut = ServiceLocator.get(ManutencaoClasses.class); manut.excluirClasseCliente(Integer.valueOf(form.getField("codClasse").getValue())); msg = "Classe de cliente excluída com sucesso"; form.clearValues(); form.clearErrors(); excluir.setStyle("display", "none"); codClassePai.setReadonly(false); //preencheTree(); preecheTree(manut); }catch(ExcecaoGenerica e){ form.setError(e.getMessage()); e.printStackTrace(); } return true; } @Override public void onGet() { super.onGet(); if(getContext().getRequestParameter("codClasse")!=null){ ClasseClienteTO to; try { ManutencaoClasses manut = ServiceLocator.get(ManutencaoClasses.class); to = manut.recuperarClasseCliente(Integer.valueOf(getContext().getRequestParameter("codClasse"))); if (to != null) { form.copyFrom(to); excluir.setStyle("display", "block"); codClassePai.setReadonly(true); } } catch (ExcecaoGenerica e) { form.setError(e.getMessage()); e.printStackTrace(); } } } } ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Click-user mailing list Click-user@... https://lists.sourceforge.net/lists/listinfo/click-user |
|||||||||||||||||
|
sabob
|
Marcelo Grassi Franco Melgaço wrote:
> > The method is onSaveClick My current guess is that somewhere Form.onProcess is invoked manually, perhaps in the Modelo parent Page or a custom Control. You can use your IDE debugger and check the stackTrace, or try the following trick and post the two stackTraces: public boolean onSaveClick() { try { throw new Exception("Testing"); } catch (Exception e) { e.printStackTrace(); } ... } This should indicate what is triggering the onProcess calls. kind regards bob > > I fixed the problem saving a request attribute in the first time the > method is called and testing this attribute in the next time, returning > true if the attribute is not null in the line: > if (getContext().getRequestAttribute("jaGravou")!=null){return true;} > > Did i do something wrong in the code that may causing this ? > > Thanks for any help! > > > > 2008/7/16 bob <sabob1@... <mailto:sabob1@...>>: > > Hi Marcelo, > > Marcelo Grassi Franco Melgaço wrote: > > I have a form with two fields and one hidden field. > > I have a submit button for this form with a method binded on it. > > The problem is when i click in the submit button the method is called > > two times in the same request. > > What should cause this problem ? > > Perhaps the method is bounded to another component as well? Perhaps > Form? > > Can you post an example for us to look at? > > kind regards > > bob > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's > challenge > Build the coolest Linux based applications with Moblin SDK & win > great prizes > Grand prize is a trip for two to an Open Source event anywhere in > the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > <http://moblin-contest.org/redirect.php?banner_id=100&url=/> > _______________________________________________ > Click-user mailing list > Click-user@... > <mailto:Click-user@...> > https://lists.sourceforge.net/lists/listinfo/click-user > > > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's challenge > Build the coolest Linux based applications with Moblin SDK & win great prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > > > ------------------------------------------------------------------------ > > _______________________________________________ > Click-user mailing list > Click-user@... > https://lists.sourceforge.net/lists/listinfo/click-user ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Click-user mailing list Click-user@... https://lists.sourceforge.net/lists/listinfo/click-user |
|||||||||||||||||
|
Marcelo Grassi Franco Melgaço
|
Ok, i will try that.
Thanks 2008/7/16 bob <sabob1@...>:
------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Click-user mailing list Click-user@... https://lists.sourceforge.net/lists/listinfo/click-user |
|||||||||||||||||
| Free Forum Powered by Nabble | Forum Help |