私は国際化対応のWebプロジェクトを持っています。それはhttp://www.springbyexample.org/examples/basic-webapp-internationalization-jsp-example.htmlとかなり似ています。 デコレータにロケールを切り替えるためのリンクがあります。現在のURLにlang paramを追加します:Spring国際化:ロケール変更の問題
<a href="?lang=en">En</a> | <a href="?lang=ru">Ru</a> </span></td>
初めて国際化がうまくいきました。しかし、我々はいくつかのフォームで問題を発見した。 フォーム:
<form:form action="${pageContext.request.contextPath}/branch/${branchId}/topic.html" modelAttribute="topicDto" method="POST"
onsubmit="this.getAttribute('submitted')"> <!--Block multiple form submissions-->
<table border="2" width="100%">
<tr>
<td width="30%">
<form:label path="topicName"><spring:message code="label.topic"/></form:label>
<form:input path="topicName"/>
<form:errors path="topicName"/>
</td>
</tr>
<tr>
<td height="200">
<form:label path="bodyText"><spring:message code="label.text"/></form:label>
<form:textarea path="bodyText"/>
<form:errors path="bodyText"/>
</td>
</tr>
</table>
<input type="submit" value="<spring:message code="label.addtopic"/>"/>
コントローラ:
/**
* @see Topic
*/
@Controller
public final class TopicController {
/**
* Method handles newTopic.html GET request and display page for creation new topic
*
* @param branchId {@link org.jtalks.jcommune.model.entity.Branch} id
* @return {@code ModelAndView} object with "newTopic" view, new {@link TopicDto} and branch id
*/
@RequestMapping(value = "/branch/{branchId}/topic/create", method = RequestMethod.GET)
public ModelAndView createPage(@PathVariable("branchId") Long branchId) {
return new ModelAndView("newTopic")
.addObject("topicDto", new TopicDto())
.addObject("branchId", branchId);
}
/**
* This method handles POST requests, it will be always activated when the user pressing "Submit topic"
*
* @param topicDto the object that provides communication between spring form and controller
* @param result {@link BindingResult} object for spring validation
* @param branchId hold the current branchId
* @return {@code ModelAndView} object which will be redirect to forum.html
* @throws org.jtalks.jcommune.service.exceptions.NotFoundException
* when branch not found
*/
@RequestMapping(value = "/branch/{branchId}/topic", method = RequestMethod.POST)
public ModelAndView create(@Valid @ModelAttribute TopicDto topicDto,
BindingResult result,
@PathVariable("branchId") Long branchId) throws NotFoundException {
if (result.hasErrors()) {
return new ModelAndView("newTopic").addObject("branchId", branchId);
} else {
Topic createdTopic = topicService.createTopic(topicDto.getTopicName(), topicDto.getBodyText(),
branchId);
return new ModelAndView("redirect:/branch/" + branchId + "/topic/"
+ createdTopic.getId() + ".html");
}
}
}
ユーザーはそれがフィールドの前に検証メッセージが表示されます、無効なフィールドを持つフォームを投稿した場合。あなたが登録ページ http://deploy.jtalks.org/jcommune/registration.html で当社の開発サーバー例えば http://deploy.jtalks.org/jcommune/index.html で問題を自分でチェックすることができ
HTTP Status 405 - Request method 'GET' not supported
type Status report
message Request method 'GET' not supported
description The specified HTTP method is not allowed for the requested resource (Request method 'GET' not supported).
Apache Tomcat/7.0.11
空白のフォームのままにし、それを提出する:彼はその瞬間にページの言語を切り替えると、彼はエラーが表示されます。検証メッセージが表示されます。言語を変更し、フォームをもう一度送信して、指定されたエラーを表示するよりも。
あなたがページにもたらしたものは何でもURLにLANGパラメータを追加しているここに私たちのすべてのソースhttp://fisheye.jtalks.org/
ありがとうございます。しかし、私はこのエラーを避けるために何ができますか?ユーザーをメインページにリダイレクトすることができます。しかし、ユーザーフレンドリーではありません。コントローラの前のどこかでGETパラメータを確認できますか? – NullPointer
GET-paramを渡すのではなく、JavaScript固有のクッキーフォームをjavascriptに設定することもできます。それはうまくいくが、私はそれが最善の解決策ではないと思う。 – NullPointer