Menu

Reload Module, Change Controller on Reload

Sean
2014-06-16
2014-06-18
  • Sean

    Sean - 2014-06-16

    Hi. I have a module that loads a list of customers that have NOT been invoiced. This is the default tab defined for the Customer entity (the base condition for this tab returns records where invoiced=0). I have a controller for this module defined called "invoiced", which displays an "Invoiced" button at the bottom of the list view. When the "Invoiced" button is clicked, the defined action reloads the same module and sets the Tab to an "Invoiced" tab I have defined in the Customer entity with a base condition filters the list to show only invoiced customers (invoiced=1). This works fine, but what I would like to do is change the controller for this invoiced view to have a button that says "Non-Invoiced" which will execute an action to return the user back to the default view that shows non-invoiced customers. Below is the code for the Action that executes when the "Invoiced" button is clicked. This works fine after the initial loading of the module with non-invoiced customers. When the user clicks the "Invoiced" button, the module reloads displaying only invoiced customers. I need to add a controller that I can use to switch back to the default.

        public class InvoicedCustomersAction extends BaseAction 
            implements IChangeModuleAction,                                           
                        IModuleContextAction {
    
            @Inject
            private Tab tab;
            private ModuleContext context;
    
            public void execute() throws Exception {
                Tab customerTab = (tab);
                context.get("Customers",getNextModule(),"xava_tab");
                customerTab.setTabName("Invoiced");
                customerTab.setBaseCondition("${invoiced}=1");
            }
    
            public Tab getTab() {
                return tab;
            }
    
            public void setTab(Tab tab) {
                this.tab = tab;
            }
    
            public ModuleContext getContext() {
                return context;
            }
    
            public void setContext(ModuleContext context) {
                this.context = context;
            }
    
            @Override
            public String getNextModule() {
                return null; 
            }
    
            @Override
            public boolean hasReinitNextModule() {
                return false;   
            }
        }
    

    I have been following the OpenXava book, Chapter 10, section 10.4 and the Calling Another Module section on the wiki.

     
    • Sean

      Sean - 2014-06-18

      I realize a simple work-around is to just have two actions for the Customer module's controller, with one button to display "invoiced" customers and a second to display "non-invoiced." I was hoping to have just one button displayed that toggles between "invoiced" and "non-invoiced", but having the two buttons is fine.

       
  • Javier Paniza

    Javier Paniza - 2014-06-18

    Hi Sean,

    from your action code you can remove and add action programatically. In this way:

    removeActions("Customer.showNotInvoiced");
    addActions("Customer.showInvoiced");
    

    Help others in this forum as I help you.

     

Log in to post a comment.