0

Currently I'm trying to open a modal dialog that contains a form filled with the values from a backing a bean. The bean is loaded (or should be loaded, as at the moment isn't working) with an object provided in the button as each button is linked with an entry in a table. The current code for the button is the following one.

The modal and the button that triggers the event are on the same page, but this page has 2 beans. One used for the modal that should be shown as soon as you click the button (used to modify the given object) and another one to print all the data in the main window.

Basically what I'm trying to do is to instantiate a bean passing a given object to the @PostConstruct method that the second bean has via the request, and having the modal shown after all that process is completed, refreshing the modal and then showing it up.

<b:button value=""
    icon-size="2x"
    onclick="#{bean.dummy()}"
    style="height: 64px; width: 64px; float: right; border: none; margin-top: 25px; border-radius: 0px;"
    oncomplete="$('.config_modal').modal()">
        <f:param name="action" value="#{bean.value}" />
</b:button>

Apart from that code I've tried several modifications listed below. The previous one is the most recent.

  • Previously the JS modal() call was inside an 'onclick' event'.
  • Added a 'dummy' method as the modal dialog is never shown with the actual code, as I thought I needed a kind of trigger to it.
  • It's not a b:commandButton as it refreshes the whole page and dialog is never shown.
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
SkPr0
  • 15
  • 4
  • could you try `oncomplete="$('.config_modal').modal('true');"` and make sure the `b:modal` has styleClass as config_modal i.e. `b:modal id="config_modal" styleClass="config_modal"` – MitchBroadhead Oct 19 '17 at 13:57
  • but the oncomplete will not fire after a page reload. you would need to use ajax. e.g. ``. any part of the page you want redrawn would have to be inside the `` – MitchBroadhead Oct 19 '17 at 14:14
  • 1
    @MitchBroadhead thanks for the reply Mitch, I did what you recommended in your second comment but still isn't working, I still don't know what I'm doing wrong... The value is being received properly in the other bean. Ok found the typo in my case, removed **'true'** from inside .modal() and now it's working. Thanks a lot! Reply with an answer so I can accept it. – SkPr0 Oct 19 '17 at 17:09
  • glad it is working now. i have copied the comment as an answer as you have suggested – MitchBroadhead Oct 19 '17 at 18:17

1 Answers1

0

the oncomplete will not fire after a page reload. you would need to use ajax. e.g. <h:form><b:commandButton value="click" action="#{bean.dummy}" oncomplete="$('.config_modal').modal('true');"><f:ajax render="@form"/></b:commandButton></h:form>. any part of the page you want redrawn would have to be inside the <h:form>

MitchBroadhead
  • 811
  • 14
  • 23