エンド ユーザーが Web サイトでフォームを正常に送信した後、情報メッセージ (Spring RediractAttribute/Flash メッセージ) に html クリック可能なリンクを追加したいと考えています。
そのため、最後に次の (フラッシュ) メッセージが表示されます。
成功
オブジェクトが更新されました。
情報
属性を編集することを忘れないでください。
Edit Attributeは、エンド ユーザーのブラウザでクリック可能なリンクになります。
調整に苦労しているのは、リンクの HTML テキストを作成するコードがどこにあるのかということです。
私たちは、messages.properties ファイルに html があるべきだとは思いませんし、コントローラーに html 生成があるべきだとも思いません。
コントローラーのコードは次のとおりです。
public ModelAndView processSubmit(@Valid ObjectCommand command, BindingResult bindingResult, RedirectAttributes redirectAttributes, HttpServletRequest request) {
if (bindingResult.hasErrors()) {
return new ModelAndView("/form.html");
} else {
// Command Object successfully send to service to update database as needed.
// First Flash Message (the success message from above).
redirectAttributes.addFlashAttribute("successMessage", "Object updated.");
// Second Flash Message (The informational message from above urging the user to go update something else too.
String informationMessage = this.getInformationMessage(request, object);
redirectAttributes.addFlashAttribute("infoMessage", informationMessage);
return new ModelAndView("redirect:/object.html");
}
}
private String getInformationMessage(Request request, Object object) {
// THIS CODE HERE, FEELS SLIMY.
String editUrl = "Remember to <a href=\"" + request.getContextPath() + "/object/" + object.getIdentifier() + "/attribute.html\" />Edit Attribute</a>";
}
次に、両方の情報メッセージを表示する jsp タグ コードを次に示します。
<%@tag body-content="empty"%>
<%@ include file="/WEB-INF/views/html/common/include.jsp" %>
<%@ attribute name="message" required="true" type="java.lang.String" %>
<c:if test="${not empty message}">
<div class="info_message">
<div class="title">Information:</div>
<div class="body">
${message}
</div>
</div>
</c:if>
情報メッセージでクリック可能なリンクを取得する方法について、親切なアドバイスをいただければ幸いです。