Hiding an action button.

Anonymous
2013-09-09
2013-11-09
  • Anonymous - 2013-09-09

    I've looked through the forums and the book, but I can't find a simple answer.

    I'm trying to hide an action when the user isn't authorized to perform the action, or when the action just shouldn't be available. Add/Remove works fine, until I add the same action multiple times, which results in multiple buttons showing up.

    Really I just want to hide the action based on either user state, or if they're editing an existing row or adding a new one. I've found the IShowActionAction and the IHideActionAction interface, but I'm both not certain how this works, and it seems overly complicated for simply wanting to hide or unhide an action to a user. (I don't need to hide/unhide while they're editing a data entry).

    Is there a simple way of directly hiding/unhiding an action? If I could find a way of determining if the action is already present I could use the add/remove method, and just not add the action if it's already present.

     
  • Javier Paniza

    Javier Paniza - 2013-09-11

    Hi Steve,

    try to do it in this way:

    removeActions("MyController.myAction");
    if (actionMustBeAvailable) {
       addActions(("MyController.myAction");   
    }
    

    That is, you can remove the action always to prevent the duplicates.

    Anyways, I cannot think in a case where showing several times the same action in the same button bar could be useful, so add as a bug the fact of that adding the same action twice duplicates the action.


    Help others in this forum as I help you.
    Need more help? Get OpenXava professional support.

     
  • Anonymous - 2013-09-11

    Thanks for the fix. I should have thought of something so simple!

    I created a bug report and since the bug is so simple a proposed fix. I'm having trouble building the project so I haven't tested it, but I don't see why it wouldn't work. Bug is 374.

     
    Last edit: Anonymous 2013-09-11
  • Dirk Coetsee

    Dirk Coetsee - 2013-09-19

    May I ask in which module to place the code
    removeActions("MyController.myAction");
    if (actionMustBeAvailable) {
    addActions(("MyController.myAction");
    }

     
  • Javier Paniza

    Javier Paniza - 2013-09-23

    Hi Dirk,

    May I ask in which module to place the code

    Well, I don't know where you want to hide/show your actions. Surely this logic is an action, but an action can be a button, an on-init action, an on-change action, etc. It depends on your goal.


    Help others in this forum as I help you.
    Need more help? Get OpenXava professional support.

     
  • Marc

    Marc - 2013-11-04

    Hi,

    I append on this thread since I have the same question as originally posted here:

    How to show/hide actions when opening an entity instance, based on the value of a property, in my case the with name “state”.

    I tried

    -OnChange action based on the property “state”. This does not deliver the required behavior: Each time when I open the entity, the same initial actions are shown. My intention is the opposite: show other actions when opening the entity instance, depending on the value of “state”. (OnChange is designed to be used for changes during the user session, and not what I look for)

    -controller action with after-each-request=true. Problem here is that I get an error when the users performs an action of a referenced entity. Also this action seems a bit overkill to my goal (only execute action when opening entity instance. So I think also not designed for I am looking for)

    Can anybody indicate a way to achieve the desired behavior?

    Thanks,
    Marc

     
  • Federico Alcantara

    Hi Marc,

    I haven't found an easy way. To do that we customizes buttonBar.jsp, barButton.jsp , bottomButton.jsp to filter the buttons which must be shown.

    We also, override the dwr.Module class with a class of our own, that takes care of cancelling the keystrokes associated with the button without touching the MetaAction properties. The keystroke assignmente is not part of the button rendering even though they are related.

    Each time a page is shown, the buttons are drawn by interpreting the MetaAction's instances properties state. If, for example, the MetaAction instance has the hidden property set, then the associated button is not shown. But changing the state of the hidden property in the MetaAction affects EVERYONE which use that MetaAction,

    Regarding the key triggering, the dwr.Module sets the key/action combination every time the page is rendered and according to the MetaAction's properties. Si this also must be taken into consideration if you are cancelling a button with key assigned to it.

    I don't know if this information is useful to you,

    Federico

     
  • Javier Paniza

    Javier Paniza - 2013-11-07

    Hi Marc,

    put your logic for hidding/showing actions in the XAVA_SEARCH_ACTION.


    Help others in this forum as I help you.

     
  • Marc

    Marc - 2013-11-09

    Javier,

    With XAVA_SEARCH_ACTION it works perfect!

    Thanks,
    Marc

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks