はじめてのSAStruts 4週目

はじめてのSAStruts 3週目 - 130単位

の続きです。

この週でView(JSP)が一通り完成しました。

1/26~1/30

▼application_ja.properties

errors.required2={0}は空白にすることができません。
labels.title=タイトル

▼ActionForm

@Required(arg0 = @Arg(key = "labels.title"),
    msg = @Msg(key = "errors.required2"), target = "insert")
public String title;

▼Action

@Execute(input = "create.jsp")
public insert() {
    //...
}
<property name="interceptorName">"loginConfirmInterceptor"</property>
  • Switch文の条件にString型は不可
    • 「型 String の値でスイッチすることはできません。 int 値または enum 定数のみが許可されています」
    • 上記エラーがでたので、「if~else」でやることにした
  • String型の比較
    • 「==」による比較でうまく動かなかった
    • equals()メソッドを使って比較しないといけない

strA == strB は、strA と strB が同じオブジェクトかどうかを調べたりする際に用いる演算子です。

とほほのJava入門
  • 成功メッセージの表示
    • エラー時と同じ要領でやることができた

▼Action

ActionMessages messages = new ActionMessages();
messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("messages.success"));
ActionMessagesUtil.addMessages(RequestUtil.getRequest(), messages);

JSP

<html:messages id="msg" message="true">
  <fontcolor="blue"><bean:write name="msg" ignore="true"/></font>
</html:messages>
原文地址:https://www.cnblogs.com/aggavara/p/2708702.html