Hi all,
i have a tricky situation which i am finding difficult to implement. Here is my requirement:
I have to implement this using
struts framework. I have a
JSP page called Ref.jsp which has a Text Box named Reference Id(uneditable) and many other text boxes to capture the reference details. When user opens this JSP page, Ref.jsp must auto populate the Reference Id text Box. And this value must be 1 higher than the Maximun Reference Id from the Reference Table. Remember that this Ref.jsp page can be opened from many machines. I have one approach of implementing this but that comes again with a drawback. Here is the approach:
1. When user opens the Ref.jsp page, call a synchronised function called maxRefId(). This function will connect to the database gets the maximum ReferenceId from the Reference table, and a dummy record is created with ReferenceId one higher than the maximum ReferenceId. This dummy record's referenceId will be returned to the JSP page, which will be populated in the ReferenceId text Box.
With this approach if different machines request for the Ref.jsp page at the same time, all machines will get different RefId's because of the Sunchronized maxRefId function. Thus the user will enter other reference details and will submit. This details can be updated onto the Reference Table.
Drawback: The draw back with this approach is that every time a user opens the Ref.jsp page a new record is getting created. And if user doesnt enter the other reference details, the record will be left incomplete. If this situation happens many times, the table will be left with many incomplete records.
I request u to suggest any other better approach to implement this. I will be waiting for your replies.
Thanks to all in advance.