[英]Managing page flow in Play! framework tags
In a web app built using Play framework, I have a checkout page which lists the user's shopping cart as well as an address form. 在使用Play框架构建的网络应用中,我有一个结帐页面,其中列出了用户的购物车以及地址表。 I created the address form as a tag (addressform.html) so that it can be reused. 我将地址表单创建为标签(addressform.html),以便可以重复使用它。
checkout.html: checkout.html:
#{if shopcart.cartItems}
#{shopcartview customer:customer,shopcart:shopcart/}
#{addressform customer:customer /}
#{/if}
The address form has a form element #{form @setAddressInfo()}
地址表单具有表单元素#{form @setAddressInfo()}
which calls a controller method as below 如下调用控制器方法
public static void setAddressInfo(Long customerId,...) {
...
showPaymentPage();
}
which if everything went well, goes to a payments page. 如果一切顺利,请转到付款页面。
The problem occurs when I want to reuse the addressform
on my confirmOrder
page. 当我想重用我的confirmOrder
页面上的addressform
confirmOrder
时,会发生问题。
confirmOrder.html: ConfirmOrder.html:
#{if shopcart.cartItems}
#{shopcartview customer:customer,shopcart:shopcart/}
#{addressform customer:customer /}
#{/if}
<a href="link_to_payment_page">editPaymentInfo</a>
here, if the user changes the address and submits the form, the setAddressInfo()
method will, on successful completion open up the payments page. 在这里,如果用户更改地址并提交表格,则setAddressInfo()
方法将在成功完成后打开付款页面。 That is not good--the user may not want to change the payment info at all. 那不是很好-用户可能根本不想更改付款信息。 Also, I am providing a link to payments page for those users who want to change payment info. 另外,我为那些想要更改付款信息的用户提供了指向付款页面的链接。 I want the same OrderConfirm page to show up, so that the user can click on the Submit Order
button. 我希望显示相同的OrderConfirm页面,以便用户可以单击Submit Order
按钮。
So how do I do it? 那我该怎么办呢? I can surely reuse the address form in this case right? 我肯定可以在这种情况下重复使用地址表格,对吗? Can you help me figure out how to manage page flow in this case? 您能帮我弄清楚在这种情况下如何管理页面流吗?
You can provide a parameter, indicating where to redirect the user, to the setAddressInfo() via hidden input or via java paramater like. 您可以提供一个参数,指示通过隐藏输入或通过Java参数等将用户重定向到setAddressInfo()的位置。 Both options: 两种选择:
<input type="hidden" name="urlToRedirectUserTo" value="urlToRedirecTo(maybe using @{}..)"/>
Or: 要么:
#{form @setAddressInfo("urlToRedirectUserTo")}
And in the action you do: 在操作中,您将执行以下操作:
public static void setAddressInfo(String urlToRedirectUserTo) {
...
...
...
redirect(urlToRedirectUserTo);
}
There are better options to make it more typed and less error prone, but this one is probably good enough. 有更好的选择来使它更加类型化并且不易出错,但是这一选择可能已经足够了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.