Search Results

Search found 2 results on 1 pages for 'yusaku'.

Page 1/1 | 1 

  • I am confused about how to use @SessionAttributes

    - by yusaku
    I am trying to understand architecture of Spring MVC. However, I am completely confused by behavior of @SessionAttributes. Please look at SampleController below , it is handling post method by SuperForm class. In fact, just field of SuperForm class is only binding as I expected. However, After I put @SessionAttributes in Controller, handling method is binding as SubAForm. Can anybody explain me what happened in this binding. ------------------------------------------------------- @Controller @SessionAttributes("form") @RequestMapping(value = "/sample") public class SampleController { @RequestMapping(method = RequestMethod.GET) public String getCreateForm(Model model) { model.addAttribute("form", new SubAForm()); return "sample/input"; } @RequestMapping(method = RequestMethod.POST) public String register(@ModelAttribute("form") SuperForm form, Model model) { return "sample/input"; } } ------------------------------------------------------- public class SuperForm { private Long superId; public Long getSuperId() { return superId; } public void setSuperId(Long superId) { this.superId = superId; } } ------------------------------------------------------- public class SubAForm extends SuperForm { private Long subAId; public Long getSubAId() { return subAId; } public void setSubAId(Long subAId) { this.subAId = subAId; } } ------------------------------------------------------- <form:form modelAttribute="form" method="post"> <fieldset> <legend>SUPER FIELD</legend> <p> SUPER ID:<form:input path="superId" /> </p> </fieldset> <fieldset> <legend>SUB A FIELD</legend> <p> SUB A ID:<form:input path="subAId" /> </p> </fieldset> <p> <input type="submit" value="register" /> </p> </form:form>

    Read the article

  • Correct usage of "<T extends SuperClass>"

    - by yusaku
    I am not familiar with "Generics". Is it a correct use of "<T extends SuperClass>" ? And do you agree that the codes after using generics are better? Before using Generics ================================================= public abstract class SuperSample { public void getSomething(boolean isProcessA) { doProcessX(); if(isProcessA){ doProcessY(new SubASample()); }else{ doProcessY(new SubBSample()); } } protected abstract void doProcessX(); protected void doProcessY(SubASample subASample) { // Nothing to do } protected void doProcessY(SubBSample subBSample) { // Nothing to do } } public class SubASample extends SuperSample { @Override protected void doProcessX() { System.out.println("doProcessX in SubASample"); } @Override protected void doProcessY(SubASample subASample) { System.out.println("doProcessY in SubASample"); } } public class Sample { public static void main(String[] args) { SubASample subASample = new SubASample(); subASample.getSomething(true); } } After using Generics ================================================= public abstract class SuperSample { public void getSomething(boolean isProcessA) { doProcessX(); if(isProcessA){ doProcessY(new SubASample()); }else{ doProcessY(new SubBSample()); } } protected abstract void doProcessX(); protected abstract <T extends SuperSample> void doProcessY(T subSample); } public class SubASample extends SuperSample { @Override protected void doProcessX() { System.out.println("doProcessX in SubASample"); } @Override protected <T extends SuperSample> void doProcessY(T subSample) { System.out.println("doProcessY in SubASample"); } } public class Sample { public static void main(String[] args) { SubASample subASample = new SubASample(); subASample.getSomething(true); } }

    Read the article

1