Update data/item in ATG repository

Update droplet:

package com.mohit;
import java.io.IOException;
import javax.servlet.ServletException;
import atg.repository.MutableRepository;
import atg.repository.MutableRepositoryItem;
import atg.repository.RepositoryException;
import atg.servlet.DynamoHttpServletRequest;
import atg.servlet.DynamoHttpServletResponse;
import atg.servlet.DynamoServlet;
public class UpdateRepositoryDroplet extends DynamoServlet{
@Override
 public void service(final DynamoHttpServletRequest pReq,
 final DynamoHttpServletResponse pRes) throws ServletException,
 IOException {
 //receive repository
 Object repository = pReq.getLocalParameter("repository");
 //receive item descriptor
 String itemDescriptor = (String) pReq.getLocalParameter("itemDescriptor");
 //receive values of existing item
 String itemID = (String) pReq.getLocalParameter("itemID");
 //receive values to be updated
 int newNumber = Integer.parseInt((String) pReq.getLocalParameter("newNumber"));

 //create Mutable Repository object
 MutableRepository mutableRepository = (MutableRepository) repository;

 //Get exisiting item from repository
 MutableRepositoryItem mutableRepositoryItem = null;
 try {
 mutableRepositoryItem = mutableRepository.getItemForUpdate(itemID,itemDescriptor);
 } catch (RepositoryException e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 }

 mutableRepositoryItem.setPropertyValue("number", newNumber);

 //Commit update
 try {
 mutableRepository.updateItem(mutableRepositoryItem);
 } catch (RepositoryException e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 }

 //send response to JSP
 pReq.setParameter("myresult", "Value updated in DB.");
 pReq.serviceParameter("myoutput", pReq, pRes);
 }
}

 

Update JSP:

<dsp:page>
<head>
<title>UpdateRepository</title>
</head>
<body>
<dsp:droplet name="/com/mohit/UpdateRepositoryDroplet">

 <dsp:param name="repository" bean="/com/mohitrepo/myrepo"/>
 <dsp:param name="itemDescriptor" value="myproduct"/>
 <dsp:param name="itemID" value="Yo Yo"/>
 <dsp:param name="newNumber" value="117"/>

 <dsp:oparam name="myoutput">
 <dsp:valueof param="myresult">Not available.</dsp:valueof>
 </dsp:oparam>
 </dsp:droplet>
</body>
</dsp:page>

 

Other details: Here