Eliminate Add and Delete functions for one class in Grails application

Tag: grails Author: xiaoyuetajie Date: 2009-10-06

I have an application with numerous Controllers. Of those, I have one that I want Update only capability, no Add and Delete functions. I've added the redirects to the class Controller for the Create and Delete, but I want to prevent the Delete and Add buttons from appearing on the different views; list, show, edit. I need full CRUD capabilities for the other classes in my application so I want the Add and Delete buttons to appear for all of the other classes in my application.

I tried editing the list.gsp with:

<g:if test="${className != 'MyUpdateOnlyClass'}">
  <span class="menuButton"><g:link class="create" action="create">New ${className}</g:link></span>
</g:if>

But the "New MyUpdateOnlyClass" button still shows in the navigation bar at the top of the list page.

Any suggestions for removing the Add and delete buttons from the various views?

Other Answer1

Are you passing in className via the model?

I assume you're re-using the same list.gsp,show,edit.gsp across multiple domain classes?

Why don't you use a template for the form and fields but create individual list,edit etc that contain the right buttons for each class.

comments:

Yes, I was attempting to use the gsp's from the src\templates\scaffolding location. I ended up doing a grails generate-all for MyUpdateOnly class and used the gsp's that were created for class. I removed the Create and Delete links. But now if I modify my MyUpdateOnly class to include a new field or remove a field, I will have to edit the custom gsp's as well to reflect the field update/removal from the class. If I were able to use the gsp's from templates (runtime), I would not have to worry about updating the gsp's for the addition/removal of a field from