Menu

Display custom action on Condition

2017-09-15
2017-11-21
  • Medasha Govender

    Hi,

    Is ot possible to display an action when a specific condition is fullfilled ?

    I have a custom action called Transfer which I defined in my Controller as :

    <controller name="Bl201">
    <extends controller="Typical"/>
    <action name="Transfer" mode="detail" class="org.openxava.billing.actions.TransferAction" image="images/report.gif">
    </action>
    </controller>

    I only want this button to be displayed if the user has the privelege to use the transfer button.

    Will this be possible ?

    Regards

    Med

     
  • Javier Paniza

    Javier Paniza - 2017-09-18

    Hi Med:

    Of course it's possible. You can use the methods add/removeActions from inside your action (a on-init action for example).

    But given you're using XavaPro, why not just use the feature for restricting actions for role.


    Help others in this forum as I help you.

     
  • Francis

    Francis - 2017-09-22

    Good day
    Here is a sample part of the code

    //part of code to hide and show an action button

                       removeActions("ControllerName.ActionName");
               if (YourCondition_Here) 
               {    
    
                   addActions("ControllerName.ActionName");//same ControllerName & ActionName //as in removeActions
    
                        }
    
     
  • Medasha Govender

    Hi,

    I used Francis's code in a "load" action and I am able to remove the action conditionally. However, once I capture a entry in my collection and close the dialog box, the action that I removed is displayed again. Is there a way to prevent the action from reappearing when I close the dialog box ?
    I am using OX 5..7.0.

    Thanks in advance.

    Med

     
  • Javier Paniza

    Javier Paniza - 2017-11-13

    Hi Med,

    That is known bug.

    Anyways, you can solve your case now using an action on-each-request. This action ask if it is inside a dialog (with getManager().getDialogLevel() > 0), if not it can add or remove the correct actions.


    Help others in this forum as I help you.

     
  • Medasha Govender

    Hi Javier,

    Thank you for the response.

    I am attempting to try what you have suggested but I am not getting any success.

    I amended my controller as follows:

    <action name="settrns" class="org.openxava.billing.actions.SetTransferFromDialog" hidden="true" on-each-request="true"/>

    Then in my action I have the following code:

    package org.openxava.billing.actions;

    import javax.persistence.*;

    import org.openxava.actions.;
    import org.openxava.jpa.
    ;

    public class SetTransferFromDialog extends BaseAction implements IAction {

        public void execute() throws Exception {
             Query query1 = XPersistence.getManager().createNativeQuery("select cotrns from gen.control where cono = (?)");
             query1.setParameter(1, "01");
             String cotrns = (String) query1.getSingleResult();
             addActions("Bl201.Transfer");
                 if (cotrns.equalsIgnoreCase("N")) {
                    removeActions("Bl201.Transfer");
                }
        }
    

    }

    I have 2 problems when I try to implement this code.

    Firstly, when the user saves the collection, the save and remove buttons are no longer displayed in the dialog of the collection.
    The transfer button is not displayed when I load the module, but once the user closes the collection dialog, the transfer button is displayed again.

    Am I doing something wrong ?

    Regards

    Med

     
  • Medasha Govender

    I amended my controller to "after-each-request" and the button does not redisplay when I close the dialog box, which is the way I want it to behave. However, all the other actions like Save and Close are also being removed.

    I will appreciate any assistance in this regard.

    Regards

    Med

     
  • Javier Paniza

    Javier Paniza - 2017-11-20

    Hi Med,

    I said you "ask if it is inside a dialog (with getManager().getDialogLevel() > 0)", and you have not tried my tip. Try it first:

    public void execute() throws Exception {
        if (getManager().getDialogLevel() > 0) return;
        ...
    

    Help others in this forum as I help you.

     
  • Medasha Govender

    Hi Javier,

    I tried your suggestion again and it worked.

    Thank you for your assistance.

    Regards

    Med

     

Log in to post a comment.