简体   繁体   中英

SCALA Lift - Missing parameter type for expanded function

I have the following form:

<form class="lift:form.ajax">

    <div class="lift:StreamInput">
        <input type="hidden" name="user" value="USER" />
        <input type="hidden" name="room" value="ROOM" />
        <input type="hidden" name="path" value="PATH" />
        <input type="hidden" name="level" value="LEVEL" />
    </div>

    <input type="submit" value="" />

</form>

Which goes into:

object StreamInput {

    case class StreamItem(

        user: String, 
        path: String, 
        level: String, 
        room: String

    )

    def render = {

        var user = ""
        var path = ""
        var level = ""
        var room = ""

        def process(): JsCmd = {

            var message = StreamItem(user, path, level, room)
            StreamServer ! message

        }

        "name=user" #> SHtml.onSubmit(user => user = _)
        "name=path" #> SHtml.onSubmit(path => path = _)
        "name=level" #> SHtml.onSubmit(level => level = _)
        "name=room" #> (SHtml.onSubmit(room => room = _) ++ SHtml.hidden(process))

    }

}

When compiling I'm getting the following errors:

"Missing parameter type for expanded function ((x$1) => user = x$1)"
"name=user" #> SHtml.onSubmit(user => user = _)
                                             ^
"Missing parameter type for expanded function ((x$2) => user = x$2)"
"name=path" #> SHtml.onSubmit(path => path = _)
                                             ^
"Missing parameter type for expanded function ((x$3) => user = x$3)"
"name=level" #> SHtml.onSubmit(level => level = _)
                                                ^
"Missing parameter type for expanded function ((x$4) => user = x$4)"
"name=room" #> SHtml.onSubmit(room => room = _)
                                             ^

I've been googling for a while now and can't seem to find an explanation that fits my particular scenario.

Not sure what I'm missing, any help is much appreciated, thanks in advance :)

SHtml.onSubmit takes a callback (String) ⇒ Any . The String being the newly submitted value of the field. In your case you want to supply a setter method which changes your var s to that new value. Change the argument to

SHtml.onSubmit(user = _)

or expanded

SHtml.onSubmit(text => user = text)

( Documentation )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM