facebook

How best to add a POJO Form?

  1. MyEclipse IDE
  2.  > 
  3. Spring Development
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #317621 Reply

    Mork
    Participant

    I’m trying to add a form that will let the user upload a file. When I read this file, I would write the contents to a database.

    (Note: we have already scaffolded a basic application from our database).

    So, my approach was initially the following — uploading and processing file contents only:

    1. Create a POJO that has the fields needed for the form.

    2. Scaffold the web layer, and service layers. This is so I can get the input form to submit to the Controller and then handle reading the business logic from the service layer.

    However, when using this scaffolding approach by using the JavaBean option and selecting the POJO I created (and selecting the web and service layers), MYE for Spring overwrites what we customized in the SiteMesh section deleting our menus and other customizations!

    So, my basic question is how best to add a form (via POJO) and scaffold it without losing all the code we’ve written.

    Do I need to manually add all this logic (form, POJO, web, and service layers)?

    ———–

    Also, the way to do a file upload is built into Spring so I’m assuming the customizations to other configuration files (and having the controller extend SimpleFormController, if it doesn’t already) would have to be done manually, correct?

    Thanks in advance for suggestions.

    — m

    #317626 Reply

    jkennedy
    Member

    Did you uncheck the checkboxes for “Update CSS” and “Update Sitemesh” on the scaffolding wizard when you reran it?

    That should stop the generator for retouching those files.

    Regarding file upload / download support, we have included code generation for managing file uploads and downloads in other products but we do not gen that code for ME4S.

    Here is what looks to be a decent example on the subject http://www.ioncannon.net/programming/975/spring-3-file-upload-example/ but let me know if you need assistance getting something working.

    One thing we did leave in that may be of assistance to you on the “download” or streaming side is the support for a View class that takes care of streaming binary content. If you look at your generated controller, you will see at the bottom that there is a RequestMapping that is designed to set the view name to streamedBinaryContentView which we wire up in the web-context.xml file. If you open the ModelAttributeStreamer class that this bean reference points to, you can see the code we have to try to make this a bit easier. You can look at the method getBinaryContentUrl for a hint on how to get a URL that you could embed in a page that would resolve to this view, and that would let you stream binary content back to the browser with support for either hard coding the content types or deriving the content type from a variable, etc.

    The top of this class contains the statics that we use for variable names in the request to pass things like the content type and file name etc that you want to stream. Many browsers use the last segment of the url (file name) as a hint as to how to prompt the end user to save the binary content (like a file etc).

    If you show this Class file in the Package explorer, you will also see another class file next to it (ModelBindingMultiPartResolver).
    This is a Java file that we left in as a utility to developers who may want to deal with File Upload/ Download in a similar way using a set of keys and values in a form to deal with Multipart binding in the generic. As I mentioned, we do not automatically generate an exemplar for using these classes, but you may find them useful.

    Hope this all helps,
    jack

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: How best to add a POJO Form?

You must be logged in to post in the forum log in