logo

const class

webapp::FindViewStep

sys::Obj
  web::WebStep
    webapp::WebAppStep
      webapp::FindViewStep
//
// Copyright (c) 2008, Brian Frank and Andy Frank
// Licensed under the Academic Free License version 3.0
//
// History:
//   14 Mar 08  Brian Frank  Creation
//

using web

**
** FindViewStep is responsible for finding a suitable Weblet
** used to process the source and sticking it in the WebReq.stash
** under "webapp.view".
**
** See [docLib::WebApp]`docLib::WebApp#findViewStep`
**
const class FindViewStep : WebAppStep
{

  **
  ** Perform this step against the specified request and response.
  **
  override Void service(WebReq req, WebRes res)
  {
    // if resource is itself a Weblet, then it is its own view
    if (req.resource is Weblet)
    {
      req.stash["webapp.view"] = req.resource
      return
    }

    // use typedb to match resource type to weblet type
    t := Type.findByFacet("webView", req.resource.type, true)
    if (t.isEmpty)
    {
      log.warn("No view available for $req.resource.type")
      res.sendError(404)
      return
    }

    // init view instance
    req.stash["webapp.view"] = t.first.make
  }

}

More Info

Slots