Results 1 to 5 of 5

Thread: Edit Data

  1. #1
    eclectica is offline Member
    Join Date
    May 2012
    Posts
    12
    Rep Power
    0

    Default Edit Data

    Hey,

    As some already know I creating Crud app
    I already have Read,Delete and create but I get an error while updating data

    When I click on a reservation(for a hotel) I get the values from my reservation, in my form i can edit the value and I like to update it to the DB

    My controller for my edit
    Java Code:
    @RequestMapping(value={"/reservationEdit"},method=RequestMethod.GET)
        public String reservationEdit(@RequestParam("reservationId") Integer id, ModelMap model){
    		//reservationdao.getById(id);
            model.addAttribute("dereservatieUpdate",reservationdao.getById(id));
            return "/reservationEdit";
        }
    	
    	@RequestMapping(value={"/reservationEdit"},method=RequestMethod.POST)
        public String reservationEditUpdate(@ModelAttribute("dereservatieUpdate") @RequestParam("reservationId") Integer id, @Valid Reservation reservation,
                                                            BindingResult result, ModelMap model){
    		
    	  //if (result.hasErrors()) return "/reservationEdit";
          reservationdao.updateReservation(id);
           
          return "/reservations";
        }
    In my Dao I only have one parameter the reservation ID (Is this right?)

    Java Code:
    public Reservation updateReservation(int reservationID);
    In my DaoImpl I update my data
    , I dont know which function to use to update data , I used refresh... / Also tried Merge
    Java Code:
    public Reservation updateReservation(int reservationID) {
    		Reservation reservation = getById(reservationID);
    		
    		em.refresh(reservation);
    		return reservation;
    	}
    If i click on update i get this error:
    SEVERE: Servlet.service() for servlet appServlet threw exception
    java.lang.IllegalStateException: Handler parameter annotations are exclusive choices - do not specify more than one such annotation on the same parameter: public java.lang.String eu.test.test4.controller.ReservationController.res ervationEditUpdate(java.lang.Integer,eu.test.test4 .model.Reservation,org.springframework.validation. BindingResult,org.springframework.ui.ModelMap)

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,947
    Rep Power
    19

    Default Re: Edit Data

    Normally in an update you would retrieve the object and then change the data in it based on the data supplied from the client.
    At the moment all you are doing is retrieving the object. Your updateReservation should either take some model or other, or take a Reservation that has already been retrieved and changed, in which case all the DAO would do is refresh().
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    eclectica is offline Member
    Join Date
    May 2012
    Posts
    12
    Rep Power
    0

    Default Re: Edit Data

    Quote Originally Posted by Tolls View Post
    Normally in an update you would retrieve the object and then change the data in it based on the data supplied from the client.
    At the moment all you are doing is retrieving the object. Your updateReservation should either take some model or other, or take a Reservation that has already been retrieved and changed, in which case all the DAO would do is refresh().
    Hi toll,
    I retreive my object I can see my current values...

  4. #4
    eclectica is offline Member
    Join Date
    May 2012
    Posts
    12
    Rep Power
    0

    Default Re: Edit Data

    I dont know why but I have "0" as reservationId in my Post Method controller
    Is there something wrong with my modelattribute ?

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,947
    Rep Power
    19

    Default Re: Edit Data

    Your update method is doing nothing except reading the object out of the database based on the id.
    There's no update there at all.

    As for why you are receiving '0', I would check what you are sending.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 2
    Last Post: 02-22-2012, 10:09 AM
  2. Edit jar, see the code, edit code and back it as a jar
    By RichersooN in forum New To Java
    Replies: 1
    Last Post: 10-10-2011, 05:33 AM
  3. Replies: 4
    Last Post: 10-01-2011, 04:13 AM
  4. Delete and edit data in xml file using JSP
    By gurpreet.singh in forum JavaServer Pages (JSP) and JSTL
    Replies: 6
    Last Post: 03-10-2011, 08:07 AM
  5. edit data??
    By Daniela_v in forum New To Java
    Replies: 4
    Last Post: 03-06-2009, 03:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •