Menu

@ NoCreate used in @ManyToOne makes impossible to select itens

2023-07-15
2023-08-21
  • Gustavo Almeida

    Gustavo Almeida - 2023-07-15

    @NoCreate when used in a @ManyToOne reference doesn't let the user create an instance of the referenced entity. Which is correct. But, the user still can click the search icon and select one of the existent elements as a reference.

    But, when @NoCreate is used with @ManyToMany reference, besides being unable to add new instances of the referenced entity, the user also can't select already exiting elements, because both the "new" and the "add" icons vanish.

    Is this desired behavior?

     
  • Javier Paniza

    Javier Paniza - 2023-07-17

    Hi Gustavo:

    That is the way it works as explained in the documentation. Keep in mind the @ManyToOne is a reference, while @ManyToMany is a collection.

    Look at this doc, that applies to @ManyToMany:
    https://openxava.org/OpenXavaDoc/docs/view_en.html#View-Collection%20customization

    It says:

    @NoCreate (OX): If you set it then the final user doesn't get the link to create or add new objects of the referenced object type.

    No as it says "create or add", that is @NoCreate remove the Add and New buttons.

    You're right, it's not coherent with the behaviour of @ManyToOne, but it in this way for historical reasons, some time ago there was not Add and New actions as different actions, but just one that adds or creates depending of the collection type, @NoCreate was to remove that unique action, afterwards we add the two actions for certaion collections, then we keep the behavior to not broke current code. The right thing would be create a @NoAdd annotation for collections and changing the behavior of @NoCreate so it works like in @OneToMany, just removing the new action. The problem with this is that it could do that already existing applications that rely in this behavior started (inadvertently) to work differently, showing a extra button.

    In you case don't use @NoCreate, just use @NewAction("") instead.


    Help others in this forum as I help you.

     

    Last edit: Javier Paniza 2023-07-17
  • Gustavo Almeida

    Gustavo Almeida - 2023-07-21

    Thank you.
    @NewAction("") worked well.
    Don't know if there is a @NoView to remove the eye icon. Tried @ViewAction("") but it only applies to @ReadOnly collections.

    Maybe you could deprecate the @NoCreate for @ManyToOne, stopping new users from using it, and signaling to old users that it shouldn't be used, without breaking running code. Then create a @NoAdd and @NoCreate2 (or@NoCreateCollection) as a replacement.

     
  • Javier Paniza

    Javier Paniza - 2023-07-24

    Hi Gustavo:

    Tried @ViewAction("") but it only applies to @ReadOnly collections.

    Use @EditAction("") for not @ReadOnly collections, because they are two differente actions, one just for view and the other for editing.


    Help others in this forum as I help you.

     
  • Gustavo Almeida

    Gustavo Almeida - 2023-07-24

    Use @EditAction("")

    It didn't work to remove the eye icon or to stop a popup windows when user clicks on an element of the collection. It has the same effect of @NoModify. The pen icon is replaced by the eye icon.
    It's not big deal. In the end the user can't modify the item.

     
  • Javier Paniza

    Javier Paniza - 2023-07-27

    Hi Gustavo:

    It didn't work to remove the eye icon

    Yes, because @EditAction is the action for editing th row, while the eye icon is the view action, a different action. If you want no action for row for editable and no editable action use:

    @EditAction("") @ViewAction("")
    Collection ...
    

    Help others in this forum as I help you.

     
  • Gustavo Almeida

    Gustavo Almeida - 2023-08-21

    Thank you. It worked.
    I had already tested @EditAction("") in conjunction with @ViewAction("") but it didn't work at the time. Now I get it was because of the @NoModify that I was using too.

     

Log in to post a comment.