Menu

custom controller adds unwanted "New" action button

2021-04-24
2021-04-27
  • Lucio Crusca

    Lucio Crusca - 2021-04-24

    When my application uses the default "Typical" controller, at the end of detail forms I have only the "Save" button and that's exactly how I like it.

    However I need to define a custom controller so that my application does not show a new empty record after "Save" was clicked, but keeps the saved record on screen for further editing.

    I then added this in controllers.xml

        <controller name="KeepEditingEntityAfterSave">
            <extends controller="Typical"/>
            <action name="save" mode="detail"
                class="org.openxava.actions.SaveAction"
                keystroke="control s"
                confirm="false"
                label="Salva">           
                <set property="resetAfter" value="false"/>
                <use-object name="xava_view"/>
            </action>               
    
        </controller>
    

    and changed this in application.xml

        <default-module>          
            <controller name="KeepEditingEntityAfterSave"/> 
            <!--  <controller name="Typical"/>   -->    
        </default-module>
    

    It mostly works, but now the detail view shows two buttons at their bottom (see the attached image), and I want only one (only the "Save" button like before).

    How do I achieve that?

     
  • Javier Paniza

    Javier Paniza - 2021-04-27

    Hi Lucio:

    You have to add by-default="if-possible" to your action, thus:

     <controller name="KeepEditingEntityAfterSave">
            <extends controller="Typical"/>
            <action name="save" mode="detail"
                 add by-default="if-possible"    
                class="org.openxava.actions.SaveAction"
                keystroke="control s"
                confirm="false"
                label="Salva">           
                <set property="resetAfter" value="false"/>
                <use-object name="xava_view"/>
            </action>
    
        </controller>
    

    BTW, OpenXava already includes a controller like yours, it is called TypicalNotResetOnSave, so you could solve your case just with this:

    <default-module>          
        <controller name="TypicalNotResetOnSave"/> 
    </default-module>
    

    Help others in this forum as I help you.

     
    👍
    1

    Last edit: Javier Paniza 2021-04-27

Log in to post a comment.

MongoDB Logo MongoDB