[web-devel] on the necessity of extractBody

Max Cantor mxcantor at gmail.com
Tue May 3 15:33:28 CEST 2011

I've heard that its unnecessary, but I can't seem to get out it of my code.  for instance, here is a simple route which should return a small HTML snippet for AJAX requests:

  getAdmPurchDetailRh   :: EncPurchId -> Handler RepHtml
  getAdmPurchDetailRh epid = withEncPersistKey epid $ \(purchId, purch) -> do
    -- purchImgData <- runDB $ selectList [] [] 50 offset
    -- _TODO this will be done FOR EACH Purchase.  need to cache the OcrRefs
    ocrRefs <- map snd <$> runDB ( selectList [] [] 50 0)
    mPsiPkv <- runDB (getBy $ PurchImgUnq purchId True)
    (_, formW, et, nonce) <- runFormPost (purchFormlet purch ocrRefs)
    let act = AdminRb
    pc <- widgetToPageContent $ do
      form <- extractBody formW
      addHamlet $(Settings.hamletFile "admin/purch-dtl")
    hamletToRepHtml [$hamlet|\^{pageBody pc}|]

and the hamlet file:

  $maybe psiPkv <- mPsiPkv
    <img src=@{getPurchImgRoute psiPkv}>
    <span .missingRecptImage>
      missing image
  <form action=@{act} enctype=#{et}>
    <input type=submit>

if I drop the extractBody formW call and replace ^{form} with ^{formW} it fails to compile.  

also, is there a way to get rid of the widgetToPageContent call and then extracting it with pageBody pc?  hamletToRepHtml fails when the hamlet references any widgets it seems.

sidenote, i understand that there is alot of polymorphism going on here but I'm still not exactly clear on what i "should" be doing in terms of hamlet, widgets, snippets etc.  any style hints are appreciated.


More information about the web-devel mailing list