0

I am experimenting with Grails, and in my app I want to restrict things so that data is only entered 'in bulk' from an XML file (I know how to upload/parse the XML). How can I do this? Do I simply remove or overwrite create in the controller?

ChrisM
  • 2,128
  • 1
  • 23
  • 41

1 Answers1

1

If you want to restrict even single item creation then yes start by overwriting your create action and view. You will want to allow the user to upload the file from the create then have that form either submit back to the modified create action or to a new action such as bulkCreate that deals with the XML file.

When you are parsing the XML file to create the domain objects you may find these items helpful Using Attributes for Domain Objects and Groovy's XML Slurper

Another area to think about is how you are going to handle domain objects that don't validate will you load everything but the ones that don't validate or not load anything?

Community
  • 1
  • 1
Jeff Beck
  • 3,944
  • 3
  • 28
  • 45
  • Thanks, very helpful answer and links. Appreciate it. – ChrisM Feb 12 '12 at 17:21
  • I added a g:uploadForm tag to my list.gsp. In my `create` I get a reference to the file with `request.getFile` and parse the XML with `XmlParser`, making a new domain class instance for each node. However nothing happens once I've uploaded the XML file. I suspect that my `create` is not doing the right thing. What exactly should it be returning? An instance list? And do I have the file uploader in the right place? – ChrisM Feb 13 '12 at 21:26
  • If you would like send me an email directly and we can work through whats happening. – Jeff Beck Feb 13 '12 at 22:09
  • Many thanks Jeff, but I don't see your email anywhere. If you like you can send it to the address on my profile and I can get back to you... New to Grails, so I think I'm making a fairly simple error... – ChrisM Feb 13 '12 at 22:57
  • Cheers Jeff, you should have mail now. – ChrisM Feb 14 '12 at 02:18