| Author |
Struts2 values passed to and fron JSPs to Actions and avoiding NULL errors
|
Kevin P Smith
Ranch Hand
Joined: Feb 18, 2005
Posts: 362
|
|
If I have an object called 'TestObject' with parameters
TestObject.name
TestObject.email
TestObject.telNo
TestObject.dateCreated
If I'm editing the values of TestObject taken from a database and I have parameters
name, email & telNo displayed on the screen, but dateCreated is not displayed
When I click 'save' values name, email & telNo of object testObject will be passed back to my Action from my JSP, dateCreated will now be
NULL as the value was never sent to the JSP in the first place.
Is there a way in which you should handle this properly in Struts2 to retain the original value from the database, or do you have to have a hidden
field on your JSP carrying the value of dateCreated?
I ask, because potentially you could have dozens of fields which you do not want on the screen, especially if only certain values are
editable on certain screens and it seems overkill to have to have them all as hidden fields.
Hope this makes sense!
:-D
|
 |
jatan bhavsar
Ranch Hand
Joined: Jul 23, 2008
Posts: 296
|
|
Hi Kevin,
if you are getting three fields from the database then there shouldn't be any prob in getting the date from db. So check whether you are getting the date from db or not.
Second you can put the server side validation to check the date for null but it will be work once you edit the data and submit the form.
Paste some code so we can help you better way.
Regards
Jatan
|
 |
Harsha Ka
Ranch Hand
Joined: Mar 14, 2010
Posts: 42
|
|
|
I believe dateCreated will need to be inserted into DB only when the object was first created and not when the other values are updated. Probably you may change the business logic to just update the other fields if they have changed and not update dateCreated.
|
SCJP 1.6,Preparing (Tryin to prepare) for scwcd
|
 |
Yogesh Lonkar
Ranch Hand
Joined: Jul 17, 2012
Posts: 82
|
|
I understand Kevin what you are trying to do. what you want is just update fields that have been modified for that what you can do is in your action class you get name, email, telephone no. all that you have stored in suppose object1. for update procedure retrieve all current values of that particular entry in object2 by using some query. then modify object2 with updated values like object2.setName(object1.getName); and object2.setEmail(object1.getEmail) etc by this you will only modify necessary field and rest will not be changed
after this you can persist or merge or use your own save procedure on object2 for successful update in database
|
Learning some thing New Every Day
|
 |
 |
|
|
subject: Struts2 values passed to and fron JSPs to Actions and avoiding NULL errors
|
|
|