1

I'm trying the include a component (with ui:include) and set a navigation rule for the caller page. The included component has a form; when submitted I want to display a feedback message (like growl) and conditionally display the included panel again.

What is the best way to achieve this?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
nuno
  • 1,771
  • 1
  • 19
  • 48
  • Wait, you say you need a navigation rule to conditionally re-render the ``? You sound like as if you're already using Ajax and would like to stay in the same page and only update a part of it. Why the need for navigation rules then? – BalusC Aug 20 '14 at 10:09
  • The `ui:include` component has a submit form; when submitted, the `action` of a `h:commandButton` runs some business logic, and at this point I want to display a feedback message (at page level) - the `action` method returns `success`/`error` in order to reload the page (although loosing table selection states). Your point with Ajax: I don't know how to control via ajax the components of a parent page (caller of the `ui:include`) – nuno Aug 20 '14 at 10:15
  • Okay. I answered the question outright, but that doesn't mean that this is the "best" approach for whatever you *really* needed. This is going to be a too long story. Start with a JSF2 book which covers ajax concepts. – BalusC Aug 20 '14 at 10:19

1 Answers1

1

You can use <ui:param> to let the caller specify custom parameters for an <ui:include>.

<ui:include ...>
    <ui:param name="foo" value="..." />
</ui:include>

You could pass them through to the method in the <h:commandButton> of the include page.

<h:commandButton ... action="#{bean.submit(foo)}" />
public String submit(String foo) {
    // ...
}
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • I accept this answer under the assumption that the caller component passes as parameter the list of tokens to return (by the actions of included component), appropriately mapping error and success cases - I don't consider it an elegant solution, but it gets the job done. Thanks – nuno Aug 22 '14 at 08:34
  • A custom tag or composite like `` is indeed more elegant than an ``, however you specifically asked for ``. See also http://stackoverflow.com/questions/6822000/when-to-use-uiinclude-tag-files-composite-components-and-or-custom-componen Again, as mentioned in my previous comment, start with a good JSF2 book. This knowledge is covered in there. – BalusC Aug 22 '14 at 08:38
  • The navigation for this solution is not working as expetected for me (when using a composite component) - I created another question here http://stackoverflow.com/questions/25501810/composite-component-with-navigation-using-managed-bean. Do the navigation rules need additional configurations? – nuno Aug 26 '14 at 10:08