Lift Scala-重定向不适用于两相形式。
|
我有一个两阶段的表单,我正在尝试在Lift Scala中实施。我的表格处于第一阶段,但第二阶段没有按预期工作。
第一个表单要求用户提供一些输入,提交后,它将带用户进入第二个表单,其中包含显示的第一个表单的详细信息。用户可以在文本字段中输入一些文本,然后单击提交以查看表单结果。第二种形式应该对任何其他用户都可用,以便他们可以输入初始用户给出的标题说明。
它的工作方式如下-用户1添加标题(表单第一阶段),另一个用户可以输入描述(表单第二阶段),然后提交表单以查看结果。但是,当用户在表单第二阶段输入描述并单击提交时,将不会发生任何事情。没有重定向,没有错误。
任何帮助对此表示感谢。
我的代码在下面,这是正确的方法吗?
class TwoPhaseForm extends DispatchSnippet with Logger {
def dispatch : DispatchIt = {
case \"addformphaseone\" => addformphaseone _
case \"viewformphaseone\" => viewformphaseone _
case \"addformphasetwo\" => addformphasetwo _
case \"viewresults\" => viewresults _
}
object currentAccountVar extends RequestVar[Entry]({
Entry.create.author(User.currentUser.open_!)
})
def currentAccount = currentAccountVar.is
//The first part of the form
def addformphaseone (xhtml : NodeSeq) : NodeSeq = {
def doSave () = {
currentAccount.validate match {
case Nil =>
currentAccount.save
S.redirectTo(\"/viewformphaseone?id=\" + currentAccount.id)
case x => S.error(x)
}
}
val acct = currentAccount
bind(\"entry\", xhtml,
\"id\" -> SHtml.hidden(() => currentAccountVar(acct)),
\"title\" -> SHtml.text(currentAccount.title.is, currentAccount.title(_)),
\"submit\" -> SHtml.submit(\"Submit\", doSave))
}
//view the details from form phase one
def viewformphaseone(xhtml : NodeSeq) : NodeSeq = {
val t = Entry.find(S.param(\"id\"))
t.map(t =>
bind(\"entry\", xhtml,
\"title\" -> t.title.toString,
)) openOr <span>Not found!</span> <b>Not found!</b>
}
//Second phase of the form
def addformphasetwo (xhtml : NodeSeq) : NodeSeq = {
def doSave () = {
currentAccount.validate match {
case Nil =>
currentAccount.save
S.redirectTo(\"/results\")
case x => S.error(x)
}
}
val t = Entry.find(S.param(\"id\"))
t.map(t =>
bind(\"entry\", xhtml,
\"desc\" -> SHtml.text(currentAccount.desc.is, currentAccount.desc(_)),
\"submit\" -> SHtml.submit(\"Submit\", doSave)
)) openOr <span>Not found!</span> <b>Not found!</b>
}
//view the results from both forms
def viewresults(xhtml : NodeSeq) : NodeSeq = {
val t = Entry.find(S.param(\"id\"))
t.map(t =>
bind(\"entry\", xhtml,
\"title\" -> t.title.toString,
\"desc\" -> t.desc.toString,
)) openOr <span>Not found!</span> <b>Not found!</b>
}
}
没有找到相关结果
已邀请:
1 个回复
青董据零
标记。因此该表格未提交