Sorry it took so long to get to this... my inbox keeps growing... sigh.

Anyway, Order.scala: 64 should be:


    def currentCost = Order.this.lots *
(Order.this.marketPlace.obj.map(_.lotValue.is) openOr 0 )

The marketplace field is a foreign key reference... so you have to get the
row that's represented by the foreign key (.obj) which is a Box[MarketPlace]
and then get the lotValue field from the marketplace.

I'm enclosing the revised (compiling) files.

Thanks,

David

On Sun, Jul 5, 2009 at 6:31 AM, Tobias Daub <[email protected]> wrote:

> here are the two files, thanks!
> > Send me the file and I'll debug it.
> >
> > On Fri, Jul 3, 2009 at 3:06 AM, Tobias Daub <[email protected]
> > <mailto:[email protected]>> wrote:
> >
> >
> >     Thanks Dave, but still getting this error:
> >
> >
> /home/wacky/NetBeansProjects/virtualMarket/src/main/scala/org/tobster/model/Order.scala:51:
> >     error: value lotValue is not a member of Long
> >            override def _toForm = Full(<p>{Order.this.lots *
> >     Order.this.marketPlace.lotValue}</p>)
> >
> >
> >     What is the explanation for this behavior?
> >
> >     thanks
> >     >
> >     >
> >     > On Sun, Jun 21, 2009 at 6:38 AM, Tobias Daub
> >     <[email protected] <mailto:[email protected]>
> >     > <mailto:[email protected] <mailto:[email protected]>>>
> wrote:
> >     >
> >     >
> >     >     I'm stucked again with the simple things....
> >     >
> >     >     I've a trait that extends BaseLongKeyedMapper and I wanna
> >     add a field
> >     >     (currentCost) that does some calculation. Nothing special.
> >     Here's
> >     >     the code:
> >     >
> >     >     /*
> >     >      * Order.scala
> >     >      *
> >     >      * To change this template, choose Tools | Template Manager
> >     >      * and open the template in the editor.
> >     >      */
> >     >
> >     >     package org.tobster.model
> >     >
> >     >     import net.liftweb._
> >     >     import mapper._
> >     >     import http._
> >     >     import SHtml._
> >     >     import util._
> >     >     import model._
> >     >
> >     >     /* Describes a general order.  */
> >     >     trait Order extends BaseLongKeyedMapper{
> >     >
> >     >        /* The number of lots this order has */
> >     >        object lots extends MappedInt(this.asInstanceOf[MapperType])
> >     >
> >     >        /* The person who owns the order */
> >     >        object owner extends
> >     >     MappedLongForeignKey(this.asInstanceOf[MapperType], User){
> >     >
> >     >            // hides this field in the CRUDify list/create forms
> >     >            override def dbDisplay_? = false
> >     >
> >     >            //set the default value to the current logged in user
> (at
> >     >     creation time)
> >     >            override def defaultValue =
> >     User.currentUser.map(_.id.is <http://id.is>
> >     >     <http://id.is>) openOr 0L
> >     >        }
> >     >
> >     >        /* The market place where the order belongs to  */
> >     >        object marketPlace extends
> >     >     MappedLongForeignKey(this.asInstanceOf[MapperType],
> >     >     MarketPlaceMetaObj){
> >     >            override def _toForm =
> Full(SHtml.selectObj[MarketPlace](
> >     >
> >      MarketPlaceMetaObj.findAll.map(mp
> >     >     => (mp, mp.name.is <http://mp.name.is> <http://mp.name.is>)),
> >     >                                          obj,
> >     >                                          (mp: MarketPlace) =>
> >     apply(mp)))
> >     >        }
> >     >
> >     >        /* The basic trade types are: BUY and SELL */
> >     >        object tradeType extends
> >     >     MappedLongForeignKey(this.asInstanceOf[MapperType],
> >     TradeTypeMetaObj){
> >     >            override def _toForm = Full(SHtml.selectObj[TradeType](
> >     >                    TradeTypeMetaObj.findAll.map(t => (t,
> >     t.name.is <http://t.name.is>
> >     >     <http://t.name.is>)),
> >     >                    obj,
> >     >                    (t: TradeType) => apply(t)))
> >     >        }
> >     >
> >     >
> >     >        object currentCost extends
> >     >     MappedInt(this.asInstanceOf[MapperType]){
> >     >            override def _toForm = Full(<p>{this.lots *
> >     >     this.marketPlace.lotValue}</p>)
> >     >
> >     >
> >     >
> >     > Try:
> >     > override def _toForm = Full(<p>{Order.this.lots *
> >     > Order.this.marketPlace.lotValue}</p>)
> >     >
> >     >
> >     >
> >     >
> >     >        }
> >     >
> >     >     }
> >     >
> >     >     I get the following compiler error:
> >     >
> >     >     [WARNING]
> >     >
> >
> /home/wacky/workspace_VirtuelleBoerse/virtualMarket/src/main/scala/org/tobster/model/Order.scala:51:
> >     >     error: value lots is not a member of Int
> >     >     [WARNING]         override def _toForm = Full(<p>{this.lots *
> >     >     this.marketPlace.lotValue}</p>)
> >     >     [WARNING]                                              ^
> >     >     [WARNING] one error found
> >     >
> >     >     The field marketPlace.lotValue is of type MappedInt as well
> >     as the
> >     >     field
> >     >     lots.
> >     >
> >     >     I tried things like "this.lots.is <http://this.lots.is>
> >     <http://this.lots.is>" or
> >     >     "this.lots.i_is_!" but without
> >     >     success. I ran out of ideas...
> >     >
> >     >
> >     >     thanks.
> >     >
> >     >
> >     >
> >     >
> >     >
> >     > --
> >     > Lift, the simply functional web framework http://liftweb.net
> >     > Beginning Scala http://www.apress.com/book/view/1430219890
> >     > Follow me: http://twitter.com/dpp
> >     > Git some: http://github.com/dpp
> >     >
> >     > >
> >
> >
> >
> >
> >
> >
> > --
> > Lift, the simply functional web framework http://liftweb.net
> > Beginning Scala http://www.apress.com/book/view/1430219890
> > Follow me: http://twitter.com/dpp
> > Git some: http://github.com/dpp
> >
> > >
>
>
> >
>


-- 
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

/*
 * MarketPlace.scala
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.liftcode.model

import net.liftweb._
import mapper._
import http._
import SHtml._
import util._

object MarketPlaceMetaObj extends MarketPlace with LongKeyedMetaMapper[MarketPlace]{
  override def dbAddTable = Full(populate _)

  private def populate {
    MarketPlaceMetaObj.create.lotValue(1).currentMarketValue(10000).name("Beginner").save
    MarketPlaceMetaObj.create.lotValue(10).currentMarketValue(10000).name("Advanced").save
    MarketPlaceMetaObj.create.lotValue(100).currentMarketValue(10000).name("Expert").save
  }
}


/* */
class MarketPlace extends LongKeyedMapper[MarketPlace] with IdPK {

  def getSingleton = MarketPlaceMetaObj

  /* The main purpose of the name is to have something to display. */
  object name extends MappedString(this, 50)

  /* Every market place has its own lot value that applies to all orders that belong to the market place */
  object lotValue extends MappedInt(this)
  
  /* Every market place has an independent "index" that changes every time when two orders meet */
  object currentMarketValue extends MappedInt(this)

}

object TradeTypeMetaObj extends TradeType with LongKeyedMetaMapper[TradeType]{
  override def dbAddTable = Full(populate _)

  private def populate {
    MarketPlaceMetaObj.create.lotValue(1).currentMarketValue(10000).name("Beginner").save
    MarketPlaceMetaObj.create.lotValue(10).currentMarketValue(10000).name("Advanced").save
    MarketPlaceMetaObj.create.lotValue(100).currentMarketValue(10000).name("Expert").save
  }
}


/* */
class TradeType extends LongKeyedMapper[TradeType] with IdPK {

  def getSingleton = TradeTypeMetaObj

  /* The main purpose of the name is to have something to display. */
  object name extends MappedString(this, 50)

  /* Every market place has its own lot value that applies to all orders that belong to the market place */
  object lotValue extends MappedInt(this)

  /* Every market place has an independent "index" that changes every time when two orders meet */
  object currentMarketValue extends MappedInt(this)

}
/*
 * Order.scala
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.liftcode.model

import net.liftweb._
import mapper._
import http._
import SHtml._
import util._
import model._

/* Describes a general order.  */
trait Order extends BaseLongKeyedMapper{

    /* The number of lots this order has */
    object lots extends MappedInt(this.asInstanceOf[MapperType])

    /* The person who owns the order */
    object owner extends MappedLongForeignKey(this.asInstanceOf[MapperType], User){
      
        // hides this field in the CRUDify list/create forms
        override def dbDisplay_? = false
        
        //set the default value to the current logged in user (at creation time)
        override def defaultValue = User.currentUser.map(_.id.is) openOr 0L
    }

    /* The market place where the order belongs to.
     * Display this field as a drop-down menu, that contains all available market places.  */
    object marketPlace extends MappedLongForeignKey(this.asInstanceOf[MapperType], MarketPlaceMetaObj){
    	override def _toForm = Full(SHtml.selectObj[MarketPlace](
            MarketPlaceMetaObj.findAll.map(mp => (mp, mp.name.is)),
              obj,
              (mp: MarketPlace) => apply(mp)))
    }

    /* The basic trade types are: BUY and SELL.
     * Display this field as a drop-down menu, that contains all available trade type. */
    object tradeType extends MappedLongForeignKey(this.asInstanceOf[MapperType], TradeTypeMetaObj){
    	override def _toForm = Full(SHtml.selectObj[TradeType](
            TradeTypeMetaObj.findAll.map(t => (t, t.name.is)),
              obj,
              (t: TradeType) => apply(t)))
    }

    /*
    private def displayAsDropDownMenu[T] =
        val tmp = T.toString + "MetaObj"
        Full(SHtml.selectObj[T](
            tmp.findAll.map(elem => (elem, elem.name.is)),
            obj,
            (elem: T) => apply(elem)))
    */
    
    /*object currentCost extends MappedInt(this.asInstanceOf[MapperType]){
    	override def _toForm = Full(<p>{Order.this.lots * Order.this.marketPlace.lotValue}</p>)
    }*/

    def currentCost = Order.this.lots * (Order.this.marketPlace.obj.map(_.lotValue.is) openOr 0 )
    
}

Reply via email to