Scala compile error: value is not member of

Sorry for my bad english!

I'm newbie in scala language, I'm compiling a project with some modifications and getting the error

"scala value is not member of"... some body can help me? follow my code:

Command.scala

package com.bla.cms.domain

import scala.collection.Map
import redis.clients.jedis.Jedis

sealed trait CommandResult
object Success extends CommandResult
object Failure extends CommandResult
object Unauthorized extends CommandResult

trait Command {
  def captchaValidator:Validator
  def logger:Logging

  val properties = PropertiesHandler.readProperties(System.getProperty(PropertiesHandler.configFileNameKey))
}

RedisIcrementCommand.scala

package com.bla.cms
package domain

import scala.collection.Map
import redis.clients.jedis.JedisPool
import dispatch._
import org.apache.log4j.Logger
import redis.clients.jedis.Jedis

class RedisIncrementCommand(database: Jedis, val captchaValidator:Validator, val logger:Logging) extends Command {

  def execute(parameters: Map[String,String]):CommandResult = {
      captchaValidator.validate(parameters) match {
        case Right(params) =>
          executeInDatabase(params)
        case Left(status) =>
          logger.info("Falha ao tentar executar comando. Captcha inválido. Status: " + status)
          Failure
      }
  }

  def executeInDatabase(parameters: Map[String,String]):CommandResult = {
    parameters.get("selectedAnswer") match {
      case Some(selectedAnswer) =>
            database.incr(selectedAnswer)
            database.sadd(Answers.key, selectedAnswer)
            logger.info("Incremento recebido com sucesso. Opção: " + selectedAnswer)
            Success
      case None =>
        logger.info("Falha ao tentar computar incremento. Alternativa não informada.")
        Failure
    }
  }
}

PollServle.scala

package com.bla.cms             

import javax.servlet.http._    
import redis.clients.jedis.JedisPool
import scala.collection.JavaConverters._
import scala.collection.JavaConversions._
import com.bla.cms.domain.Logging
import org.apache.log4j.Logger 
import scala.util.matching.Regex

class PollServlet extends HttpServlet with RequiresConnection {
  import com.bla.cms.domain._   
  import URLHandler._          

  override def doPost(request:HttpServletRequest, response:HttpServletResponse):Unit = {

    val parametersMap = new ServletApiAdapter(request,response).parameters

    val outcome = newIncrementCommand(request).execute(parametersMap)
    redirect(request, response, outcome)
  }
}

And when I compile, I've got:

[error]PollServlet.scala:19: value execute is nota member of com.bla.cms.domain.Command

val outcome = newIncrementCommand(request).execute(parametersMap)

Somebody can help me please?

Upvotes: 0

Views: 3786

Answers (1)

Marek Adamek
Marek Adamek

Reputation: 520

You can:

  1. Add def execute(parameters: Map[String,String]):CommandResult to Command trait.

  2. Change newIncrementCommand(request) to return RedisIncrementCommand instead of Command.

  3. Cast result of newIncrementCommand(request) to RedisIncrementCommand using asInstanceOf.

I prefer 1 which would be:

trait Command {
  val captchaValidator: Validator
  val logger: Logging
  val properties = PropertiesHandler.readProperties(System.getProperty(PropertiesHandler.configFileNameKey))

  def execute(parameters: Map[String,String]): CommandResult  
  def executeInDatabase(parameters: Map[String,String]): CommandResult
} 

Upvotes: 1

Related Questions