ともくんコードのお話
今日はまずともくんの作ったwicket+twitterのコードを指摘するお勉強
public HomePage(final PageParameters parameters) { PostingData data = new PostingData(); TextField<String> inputId = new TextField<String>("inputId", new PropertyModel<String>(data, "userId")); PasswordTextField inputPw = new PasswordTextField("inputPw", new PropertyModel<String>(data, "password")); TextArea<String> inputSb = new TextArea<String>("inputSb", new PropertyModel<String>(data, "subject")); SubmitButton confirmButton = new SubmitButton("confirmButton", data); Form<Object> inputForm = new Form<Object>("inputForm"); inputForm.add(inputId, inputPw, inputSb, confirmButton); this.add(inputForm); }
コンポーネントIDとプロパティ式は一緒にするのが一般的らしいです。
一緒にするとなると同じ名前を2回書くことになるので、CompoundPropertyModelを使うとすっきりします
ちょうど昨日ブログにまとめました!
あとでともくんのも同じようにCompoundPropertyModelを使ってリファクタリングしてみようかな
あと、this.add(inputForm);のthis.はなくてもいいんじゃないかなって思いました。
つけなくてもちゃんとページにaddされます。
ついき
ふむふむ、this.については書く人によってまちまちみたいですね
なるほどーいろんな意見が聞けてうれしいです