Stateless Apache Wicket stateless pages/requests

后端 未结 5 1524
感情败类
感情败类 2021-02-06 13:53

So I was reading another question under the Wicket tag comparing Apache Wicket and Apache Click. A concise explanation, in my opinion. I am more familiar with the Wicket world t

5条回答
  •  花落未央
    2021-02-06 14:30

    I prefer to check that in test.

    so each test for stateless page overrides

    getStatelessWebPage()
    

    which by default returns null.

    then in basic test I have generic test that visits all components on page and check whether component is stateless or not

    @Test
    public void checkForStateless()
    {
        StatelessWebPage statelessPage = getStatelessWebPage();
        if (statelessPage != null)
        {
            Page page = (Page)statelessPage;
            if (!page.isPageStateless())
            {
                //find the reason
                Component statefulComponent = page.visitChildren(Component.class, new StatelessChecker());
                if (statefulComponent != null)
                {
                    fail("Stateless page contains stateful component ["
                         +statefulComponent.getClass().getName()+" : "
                         + statefulComponent.getMarkupId() +"]");
                }
            }
        }
    }
    

    and

    class StatelessChecker implements IVisitor
    {
        @Override
        public void component(Component component, IVisit iVisit)
        {
            if (!component.isStateless())
            {
                iVisit.stop(component);
            }
        }
    }
    

提交回复
热议问题