Move your code from IAjaxCallDecorator to onSubmit() and use
target.appendJavascript()

IAjaxCallDecorator is used to modify the javascript which is used to
in <button onclick="HERE"> which is not what you want

On Wed, Sep 28, 2011 at 11:41 AM, Mathilde Pellerin
<mathilde.pelle...@statlife.fr> wrote:
> Hi all,
>
> I want to generate a Line chart (from Google Visualization API) when I
> submit a form.
> To do that, I used getAjaxCallDecorator like this :
>
>        AjaxButton submit = new AjaxButton("submit") {
>            private int agePersonne;
>            private double risque;
>
>            @Override
>            protected void onSubmit(AjaxRequestTarget target, Form<?> form)
> {
>                agePersonne = age.getModelObject();
>
>                //Récupération du risque via le DAO auquel on passe les
> valeurs du formulaire
>                //les valeurs doivent donc avoir été validées avant
>                risque = risqueDao.getOneByProfil(agePersonne,
> agePremieresRegles.getModelObject(),
>                        nbParentsAtteints.getModelObject(),
> nbBiopsies.getModelObject(),
>                        menopauseGroupe.getModelObject(),
> ageMenopause.getModelObject(), statutTHS.getModelObject());
>
>            }
>
>            @Override
>            protected void onError(AjaxRequestTarget target, Form<?> form) {
>                target.add(feedback);
>            }
>
>            @Override
>            protected IAjaxCallDecorator getAjaxCallDecorator() {
>                return new AjaxCallDecorator() {
>                    public CharSequence decorateScript(Component c,
> CharSequence script){
>                        return JavascriptUtils.genererScriptLine("risque",
> agePersonne, risque) + script;
>                    }
>                };
>            }
>        };
>        form.add(submit);
>
> With this code, the static method genererScriptLine() is called on page
> loading, so agePersonne and risque are not initialized because they will be
> calculated only on form submitting. So when I submit the form, chart is
> displayed but not with good values for agePersonne and risque.
>
> I don't understand how to use getAjaxCallDecorator with AjaxButton to be
> sure that decorateScript will be called after submitting, and not on page
> loading?
> What am I doing wrong?
>
> Mathilde
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to