I have a template with button which opens dialog:
<p:commandButton
id="roles-button"
icon="fa fa-key">
<f:setPropertyActionListener value="#{user}" target="#{userAdministrationView.selectedUser}" />
<f:actionListener binding="#{userAdministrationView.openUserRolesDialogWithParameters()}"/>
<p:ajax
event="dialogReturn"
listener="#{dialogHandler.showMessage}"
update=":user-administration-form:user-administration-table"
global="false"
/>
</p:commandButton>
Backing bean for template (userAdministrationView) is @ViewScoped.
I want to pass parameter selectedUser
to the dialog. Is it possible with using Faces.setContext/Request/FlashAttribute, like adviced here? I tried to implement it like:
public void openUserRolesDialogWithParameters() {
Faces.setContextAttribute("user", selectedUser);
dialogHandler.openDialog("user-roles-dialog");
}
and in dialogs backing bean (which is @ViewScoped too):
@PostConstruct
public void init() {
this.user = Faces.getContextAttribute("user");
...
}
but I get null
in user
. The same result is with setRequestAttribute and setFlashAttribute.
Here it is suggested to create @SessionScoped bean with properties, but this decision looks not very relevant for me. Is it the only way?
Thanks to BalusC, i started to search in right direction, and I found this explanation. So, it works like this:
template backing bean :
dialog backing bean: