(Somehow this mail got lost.. Resending) 

Hi.

I'm looking for some suggestions/ideas on how to implement a 
'confirm-delete' function in our application.

We have a number of JSP's where we list a number of entities. For each
entity there's a link to a 'removeXX.action'. We would like to present
the user with a "confirm delete" page where the user can choose to
delete the entity och abort.

We use WW 1.3 at the moment, but suggestions for WW2 are welcome too :)

Our current idea is to have our actions implement a "ConfirmOnRemove"
interface:

public interface ConfirmOnRemove {
   public static final String VERIFY_REMOVE = "verify-remove";
   public String getEntityName();
   public String getEntityDisplayName();
   public String getEntityDisplayId();
   public void setConfirmRemove(boolean bConfirmed);
}

And in actions.xml have something like:

<action name="AddEditEntity" alias="viewEntity">
   <view name="success">viewEntity.jsp</view>
   <view name="error">redirect.action=listEntities.action</view>
   <command name="remove" alias="removeEntity">
      <view name="success">redirect.action=listEntities.action</view>
      <view name="error">viewEntity.jsp</view>
      <view name="verify-remove">confirmRemove.jsp</view>
   </command>
</action>

And the code in the AddEditEntity action would be something like:

public class AddEditEntity extends ActionSupport implements
   ConfirmOnRemove 
{
   //...

   //-- ConfirmOnRemove -----
   private boolean bConfirmed = false;
   
   public String getEntityName(){
      return "Entity";
   }
   
   public String getEntityDisplayName() {
      return "EntityTypeName";
   }
   
   public String getEntityDisplayId(){
      return String.valueOf(getId());
   }
   public void setConfirmRemove(boolean bConfirmed){
      this.bConfirmed = bConfirmed;
   }

   //-- Commands -------
   public String doRemove() throws Exception {
      if(!bConfirmed){
         return ConfirmOnRemove.VERIFY_REMOVE;
      }
      else {
         // Remove the entity, return SUCCESS if ok, else ERROR
      }
   }
}

The confirmRemove.jsp would look something like:

<p>
   Are you sure you want to remove the <ww:property
   value="entityDisplayName"/> (<ww:property value="entityDisplayId"/>)?
</p>

<!-- Link to remove -->
<a href="<ww:url><ww:param name="'confirmRemove'"
value="'true'"/></ww:url>">OK</a>

<!-- Link to abort -->
<a href="view<ww:property value="entityName"/>.action">Abort</a>

Now - the scenario where the user verifies the 'remove' is pretty
straight forward, but when the user aborts the removal, you have to know
which action to send the user to... this is a bit akward since it puts
logic about the name of an action into the action itself
(getEntityName()).

How are you guys handling these kind of things?

//Anders

-- 
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. Anders Engström         [EMAIL PROTECTED]
. http://www.gnejs.net    PGP-Key: ED010E7F
. [Your mind is like an umbrella. It doesn't work unless you open it.]  

Attachment: pgp00000.pgp
Description: PGP signature

Reply via email to