final public function generateResponse($request = null)
    {
        while (true) {
            $this->setWebRequest($request);

            try {
                if ($request->header("Accept") == "application/leaf") {
                    $response = new XmlResponse($this);
                    $response->setContent($this->renderXhr());
                } else {
                    $response = new HtmlResponse($this);
                    $response->setContent($this->render());
                }

                return $response;
            } catch (RequiresViewReconfigurationException $er) {
                $this->initialiseView();
            }
        }

        return null;
    }