Announcement Announcement Module
No announcement yet.
Binding form:update with non-rendered fields Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Binding form:update with non-rendered fields


    I've this update screen with some non-rendered fields and when I click save, all the existing values of those fields are lost.

    If I change the rendering to true everything is ok.

    So the binding of non rendered fields in not done and the update uses the empty fields.

    Is that the expected behaviour?

    To reproduce:

    project --topLevelPackage rootest --projectName rootest --java 6
    persistence setup --provider HIBERNATE --database HYPERSONIC_IN_MEMORY 
    entity --class ~.server.domain.Comment --testAutomatically
    field string --fieldName title --notNull
    field string --fieldName extID --sizeMax 500 
    controller all --package ~.web
    change update.jspx with

        <field:textarea field="extID" id="c_rootest_server_domain_Comment_description" render="false" z=""/>
    Create a comment with a title and a extID
    Modify the only field available (title)
    Show the comment-> the extID is emty.


  • #2
    Hi fraveau,

    I'm facing with the same problem

    Did you find any solutions?



    • #3
      Hi tob
      No, I didn't find any solution while keeping the project under Roo control.
      I'm planning to put my project out of Roo soon and then I'll do it in a more traditional way.
      But I'm still interested in any solution!


      • #4
        I think this is just how the JPA implementations work. You can edit the merge method of the entity to have it leave certain properties out of its update, or create your own "partialUpdate" method for these cases. That of course means pushing in some of your code.

        You might consider making the fields hidden instead (depending on whether or not the data is sensitive).


        • #5
          Ok, I fixed it by removing the @Valid Annotation for the update method.
          Now my target object is not automatically validated.
          So I need to add a Validator and check for errors.
          After that I merged the fields from the persistent object to the updated object.

          This way is descripted here:

          Thanks for your help.


          • #6
            my advise:
            1) create a @NotUpdatable annotation for fields you don't want to be updated and rendered
            2) create a utility method that scans classes through beanutils to get a list of "notUpdatable" properties
            3) store the list into the UiModel and use it to get the "render" attribute value in forms
            4) override the merge method of your entity using the same list to merge with beanutils.copyproperties passing the ignoredProperties parameter

            Going to write down some roo mod for this, if I'll have time