servlets - Edit form input details in jsp -
i have made input form takes input , stores in database using jsp , servlets. form has edit details button. want when user clicks button form should autofill old values , allow user change values. , new values should updated in database. here screenshot of form. please help...
it depends want do. can either client side or server side. client site refer post below. what best way track changes in form via javascript?
for server side
if orm can use saveorupdate() call. read does.
or
make 2 datatransfer objects lets call them loadtimeobject , submitobject.
assuming flow , domain model here.
- edit details button click -> row id or primary key/unique row/or id.
- load data fields make ajax call or if data available in javascript object, using row/object id - refer loadtimeobject
- user makes/does not make changes , click on submit. load form fields submitobject. in java validate if loadtimeobject , submitobject differ? track fields changes , persist them in db.
hint:you may use apache commons beanutils compareobjects(object loadtimeobject , object submitobject) methods.
or
use java reflection compare objects.
public static <t> void compare(t source, t target) throws illegalargumentexception, illegalaccessexception { if(source == null) { throw new illegalargumentexception("null argument not excepted @ point"); } field[] fields = source.getclass().getfields(); object sourceobject; object targetobject; for(field field : fields){ sourceobject = field.get(source); targetobject = field.get(target); //compare object } }
Comments
Post a Comment