You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Mathilde Pellerin <ma...@statlife.fr> on 2011/08/04 17:05:18 UTC

session closed when adding CSSPackageResource

Hi all,

I want to override some style of modal window, so I created a css file and I
added it on the modal window constructor :

public class ModalWindowE4N extends ModalWindow {

    public ModalWindowE4N(String id, String titre) {
        super(id);
        add(CSSPackageResource.getHeaderContribution("modalE4N.css"));
        this.setTitle(titre);
        this.setUseInitialHeight(false);
        this.setHeightUnit("px");
        this.setWidthUnit("px");
        this.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
        this.setMaskType(ModalWindow.MaskType.SEMI_TRANSPARENT);
    }

    private static final long serialVersionUID = 5439940276271822354L;

}

But then, when I click on the AjaxLink which must show the modal window, I
have this error :

ERROR - azyInitializationException - failed to lazily initialize a
collection of role:
fr.statlife.protoE4N.data.entites.Questionnaire.listeQuestions, *no session
or session was closed*
org.hibernate.LazyInitializationException: failed to lazily initialize a
collection of role:
fr.statlife.protoE4N.data.entites.Questionnaire.listeQuestions, no session
or session was closed
    at
org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:383)
    at
org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:375)
    at
org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:368)
    at
org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:111)
    at
org.hibernate.collection.PersistentBag.iterator(PersistentBag.java:272)
    at
fr.statlife.protoE4N.pages.membre.QuestionnaireContentPanel.initialiserQuestionnaire(QuestionnaireContentPanel.java:181)
    at
fr.statlife.protoE4N.pages.membre.QuestionnairesPage$BoutonRemplirQuestionnaire$1.onClick(QuestionnairesPage.java:116)
    [...]

obviously, my session is closed by adding the CSSPackageResource (because
when I comment this line, everything works well), and I don't understand
why.
What am I doing wrong?

Thanks
M.

-- 
*Mathilde Pellerin*
Ingénieur en développement de logiciel

STATLIFE
tel : 01.42.11.64.88
mail : mathilde.pellerin@statlife.fr

Re: session closed when adding CSSPackageResource

Posted by Dan Retzlaff <dr...@gmail.com>.
Hi Mathilde,

The story must be more complicated than your addition of a
HeaderContributor. Somehow you're serializing a Questionnaire into your
Wicket session, and when it's used in a subsequent request, the Hibernate
session associated with its lazy collection of questions has been closed.
One way to troubleshoot this is to change Questionnaire so it is not
Serializable; then you will see the problem closer to its source. The best
solution is to create an IModel for Questionnaire so that the entity itself
is not serialized.

Hope that helps,
Dan

On Thu, Aug 4, 2011 at 8:05 AM, Mathilde Pellerin <
mathilde.pellerin@statlife.fr> wrote:

> Hi all,
>
> I want to override some style of modal window, so I created a css file and
> I
> added it on the modal window constructor :
>
> public class ModalWindowE4N extends ModalWindow {
>
>    public ModalWindowE4N(String id, String titre) {
>        super(id);
>        add(CSSPackageResource.getHeaderContribution("modalE4N.css"));
>        this.setTitle(titre);
>        this.setUseInitialHeight(false);
>        this.setHeightUnit("px");
>        this.setWidthUnit("px");
>        this.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
>        this.setMaskType(ModalWindow.MaskType.SEMI_TRANSPARENT);
>    }
>
>    private static final long serialVersionUID = 5439940276271822354L;
>
> }
>
> But then, when I click on the AjaxLink which must show the modal window, I
> have this error :
>
> ERROR - azyInitializationException - failed to lazily initialize a
> collection of role:
> fr.statlife.protoE4N.data.entites.Questionnaire.listeQuestions, *no session
> or session was closed*
> org.hibernate.LazyInitializationException: failed to lazily initialize a
> collection of role:
> fr.statlife.protoE4N.data.entites.Questionnaire.listeQuestions, no session
> or session was closed
>    at
>
> org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:383)
>    at
>
> org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:375)
>    at
>
> org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:368)
>    at
>
> org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:111)
>    at
> org.hibernate.collection.PersistentBag.iterator(PersistentBag.java:272)
>    at
>
> fr.statlife.protoE4N.pages.membre.QuestionnaireContentPanel.initialiserQuestionnaire(QuestionnaireContentPanel.java:181)
>    at
>
> fr.statlife.protoE4N.pages.membre.QuestionnairesPage$BoutonRemplirQuestionnaire$1.onClick(QuestionnairesPage.java:116)
>    [...]
>
> obviously, my session is closed by adding the CSSPackageResource (because
> when I comment this line, everything works well), and I don't understand
> why.
> What am I doing wrong?
>
> Thanks
> M.
>
> --
> *Mathilde Pellerin*
> Ingénieur en développement de logiciel
>
> STATLIFE
> tel : 01.42.11.64.88
> mail : mathilde.pellerin@statlife.fr
>

Re: session closed when adding CSSPackageResource

Posted by Dan Retzlaff <dr...@gmail.com>.
No, sorry, that doesn't make sense to me. But I'm glad to hear you worked
out the problem, and more importantly, understand the usage of detachable
models. :)

On Fri, Aug 5, 2011 at 1:52 AM, Mathilde Pellerin <
mathilde.pellerin@statlife.fr> wrote:

> Wonderful ! it works with "*InjectorHolder.getInjector().inject(this);*".
>
> Thank to you all.
>
> Can someone could explain to me why I need a specific
> LoadableDetachableModel only when I add CSSPackageResource to my modal
> window ?
>

Re: session closed when adding CSSPackageResource

Posted by Mathilde Pellerin <ma...@statlife.fr>.
Wonderful ! it works with "*InjectorHolder.getInjector().inject(this);*".

Thank to you all.

Can someone could explain to me why I need a specific
LoadableDetachableModel only when I add CSSPackageResource to my modal
window ?

Re: session closed when adding CSSPackageResource

Posted by Martin Grigorov <mg...@apache.org>.
 public QuestionnaireModel(Long primaryKey) {
       InjectorHolder.getInstance().inject(this);     <<<<<<<<<<<<
       id = primaryKey;
   }


On Fri, Aug 5, 2011 at 11:27 AM, Mathilde Pellerin
<ma...@statlife.fr> wrote:
> Ok, so I try with your method. This is my model :
>
> public class QuestionnaireModel extends
> LoadableDetachableModel<Questionnaire> {
>    @SpringBean
>    private ServiceQuestionnaire serviceQuestionnaire;
>    private Long id;
>
>    public QuestionnaireModel(Long primaryKey) {
>        id = primaryKey;
>    }
>
>    @Override
>    protected Questionnaire load() {
>
>        return serviceQuestionnaire.getOne(id);
>    }
> }
>
> But I have a null pointer exception :
> java.lang.NullPointerException
>    at
> fr.statlife.protoE4N.pages.membre.QuestionnaireModel.load(QuestionnaireModel.java:22)
>    at
> fr.statlife.protoE4N.pages.membre.QuestionnaireModel.load(QuestionnaireModel.java:1)
>    at
> org.apache.wicket.model.LoadableDetachableModel.getObject(LoadableDetachableModel.java:120)
>    at
> org.apache.wicket.Component.getDefaultModelObject(Component.java:1724)
>    at
> fr.statlife.protoE4N.pages.membre.QuestionnairesPage$BoutonRemplirQuestionnaire$1.onClick(QuestionnairesPage.java:112)
>    [...]
>
> Questionnaire is also an attribute of my Page and maybe there is a conflict.
> This code calls my new model :
>     item.add(new BoutonRemplirQuestionnaire("boutonQuestionnaire",  new
> QuestionnaireModel(q.getIdQuestionnaire())));
>
> and this is inner class BoutonRemplirQuestionnaire :
>    class BoutonRemplirQuestionnaire extends Panel
>    {
>        public BoutonRemplirQuestionnaire(String id, IModel<?> model) {
>            super(id, model);
>
>            //Ajout du lien qui affichera le questionnaire
>            AjaxLink<Void> showQuestionnaire = new AjaxLink<Void>("remplir")
> {
>                @Override
>                public void onClick(AjaxRequestTarget target) {
>                    qCourant =
> (Questionnaire)getParent().getDefaultModelObject();
>
>
> target.appendJavascript("Wicket.Window.unloadConfirmation = false;");
>
> questionnaireContentPanel.initialiserQuestionnaire(qCourant);
>                    modalWindow.setContent(questionnaireContentPanel);
>                    modalWindow.setTitle(qCourant.getTitre());
>                    modalWindow.show(target);
>                }
>            };
>            add(showQuestionnaire);
>        }
>    }
>
> the NullPointerException is sent by this line :
>       qCourant = (Questionnaire)getParent().getDefaultModelObject();
>
> Maybe modal window make this problem more complex...
>



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

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


Re: session closed when adding CSSPackageResource

Posted by Mathilde Pellerin <ma...@statlife.fr>.
Ok, so I try with your method. This is my model :

public class QuestionnaireModel extends
LoadableDetachableModel<Questionnaire> {
    @SpringBean
    private ServiceQuestionnaire serviceQuestionnaire;
    private Long id;

    public QuestionnaireModel(Long primaryKey) {
        id = primaryKey;
    }

    @Override
    protected Questionnaire load() {

        return serviceQuestionnaire.getOne(id);
    }
}

But I have a null pointer exception :
java.lang.NullPointerException
    at
fr.statlife.protoE4N.pages.membre.QuestionnaireModel.load(QuestionnaireModel.java:22)
    at
fr.statlife.protoE4N.pages.membre.QuestionnaireModel.load(QuestionnaireModel.java:1)
    at
org.apache.wicket.model.LoadableDetachableModel.getObject(LoadableDetachableModel.java:120)
    at
org.apache.wicket.Component.getDefaultModelObject(Component.java:1724)
    at
fr.statlife.protoE4N.pages.membre.QuestionnairesPage$BoutonRemplirQuestionnaire$1.onClick(QuestionnairesPage.java:112)
    [...]

Questionnaire is also an attribute of my Page and maybe there is a conflict.
This code calls my new model :
     item.add(new BoutonRemplirQuestionnaire("boutonQuestionnaire",  new
QuestionnaireModel(q.getIdQuestionnaire())));

and this is inner class BoutonRemplirQuestionnaire :
    class BoutonRemplirQuestionnaire extends Panel
    {
        public BoutonRemplirQuestionnaire(String id, IModel<?> model) {
            super(id, model);

            //Ajout du lien qui affichera le questionnaire
            AjaxLink<Void> showQuestionnaire = new AjaxLink<Void>("remplir")
{
                @Override
                public void onClick(AjaxRequestTarget target) {
                    qCourant =
(Questionnaire)getParent().getDefaultModelObject();


target.appendJavascript("Wicket.Window.unloadConfirmation = false;");

questionnaireContentPanel.initialiserQuestionnaire(qCourant);
                    modalWindow.setContent(questionnaireContentPanel);
                    modalWindow.setTitle(qCourant.getTitre());
                    modalWindow.show(target);
                }
            };
            add(showQuestionnaire);
        }
    }

the NullPointerException is sent by this line :
       qCourant = (Questionnaire)getParent().getDefaultModelObject();

Maybe modal window make this problem more complex...

RE: session closed when adding CSSPackageResource

Posted by Wilhelmsen Tor Iver <To...@arrive.no>.
> When I do this :
>      new Model<Questionnaire>(q)
> it creates an IModel for Questionnaire, doesn't it?

I think he means to make a more dynamic model, e.g.

public class QuestionnaireModel extends LoadableDetachabeModel<Questionnaire> {

	private String theKey;

	public QuestionnaireModel(String key) { theKey = key; }

	public Questionnaire load() { /* Get Hibernate session and load based on key */ }
}

This serializes the minimum amount of state to "recreate" the complex object.

- Tor Iver

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


Re: session closed when adding CSSPackageResource

Posted by Mathilde Pellerin <ma...@statlife.fr>.
Hi Dan,

I followed your advise : I change Questionnaire so it is not serializable
and errors appeared in my page for this line :
item.add(new BoutonRemplirQuestionnaire("boutonQuestionnaire",  new
Model<Questionnaire>(q)));

and it's coherent because it's when I click on this AjaxLink that I have the
first error (method *BoutonRemplirQuestionnaire* creates a Panel with an
AjaxLink inside).

But I don't really understand your solution :

> The best solution is to create an IModel for Questionnaire so that the
> entity itself is not serialized.


When I do this :
     new Model<Questionnaire>(q)
it creates an IModel for Questionnaire, doesn't it?

and there is something else that I don't understand : why this problem
appears only when I add a HeaderContributor?

thanks for your help
M.


> Hi Mathilde,
>
> The story must be more complicated than your addition of a
> HeaderContributor. Somehow you're serializing a Questionnaire into your
> Wicket session, and when it's used in a subsequent request, the Hibernate
> session associated with its lazy collection of questions has been closed.
> One way to troubleshoot this is to change Questionnaire so it is not
> Serializable; then you will see the problem closer to its source. The best
> solution is to create an IModel for Questionnaire so that the entity itself
> is not serialized.
>
> Hope that helps, Dan
>
>
>