Hello, I am trying to undertand how encapsulate data works. I have: TestEncapsulate userdata = new TestEncapsulate ( rs.getString("name")==null?"":rs.getString("name"), rs.getString("last")==null?"":rs.getString("last"), rs.getString("midd")==null?"":rs.getString("mid") ) ; was working, good. But another programmer told me that was missing: userdata.setname(request.getParameter("name")); userdata.setlast(request.getParameter("last") ); userdata.setmidd(request.getParameter("midd")); So I added (and is working too!). He told me to keep it because is necessary. I do not undertand why do I need to do the second section if in the first section I put the values, isn't it?. Some body can explain me this, please? THANK YOU!
I'm not really sure how this is a Struts question.
I suspect the issue the other programmer was talking about is that the JavaBean specification requires getters and setters for bean properties.
Having a constructor that fills all the values is okay, but it's also good practice (and required in many circumstances) to have a default constructor that takes no values, and getters/setters that allow setting and retrieving the bean properties.