Announcement Announcement Module
Collapse
No announcement yet.
Efficient way to copy one bean to the other? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Efficient way to copy one bean to the other?

    So I had this really long post and I solved my own problem. So let me ask this...is this the most efficient way to copy from one bean to the next. The caseDetail contains all Strings and my command has Dates. The only way I can see to make this work is to exclude all the date attributes to do the BeanUtils.copyProperties() and then use the BeanWrapperImpl to copy the dates over.

    Also, this is done on the way out to the view, not from the form to the controller. I know coming from the view I can just bind properties.

    Code:
    BeanWrapperImpl commandWrapped = new BeanWrapperImpl(command);
    commandWrapped.registerCustomEditor(Date.class, DATE_EDITOR_REQUIRED);
    
    String excludes[] = new String[]{"BMT", "modSts", "chngSts", "birthDt", "cseEffDt"};
    BeanUtils.copyProperties(caseDetail, command, excludes);
    commandWrapped.setPropertyValue("modSts", PropertyUtils.getProperty(caseDetail, "modSts"));
    commandWrapped.setPropertyValue("chngSts", PropertyUtils.getProperty(caseDetail, "chngSts"));
    commandWrapped.setPropertyValue("birthDt", PropertyUtils.getProperty(caseDetail, "birthDt"));
    commandWrapped.setPropertyValue("cseEffDt", PropertyUtils.getProperty(caseDetail, "cseEffDt"));
Working...
X