I think I have come up with a solution.
As I am using CODI I can leverage the ConversationGroup
annotation.
I ve created an emtpy interface AddressConversation
, then added this to all the backing beans that need to show the address/addressEdit.xhtml
view, as well as the backing bean for the addressEdit
view.
I m also using CODI view config so my action methods return ViewConfig
derived class objects.
@Named
@ConversationScoped
@ConversationGroup(AddressConversation.class)
public class AddressView implements Serializable
{
private Class<? extends Views> fromView;
private Address editAddress;
private Address returnAddress;
// Getters/setters etc...
public Class<? extends Views> cancelEdit()
{
returnAddress = null;
return fromView;
}
}
因此,我在呼吁中(PrimeFacestorLink)
<p:commandLink value="#{enquiryView.addressLinkText}" action="#{enquiryView.editAddress()}" immediate="true"/>
www.un.org/chinese/sc/presidency.asp EnquiryView 在正确的谈话小组中,我可以@Inject
例AddressView
,然后在使用行动方法时确定地址和回归观点。
@Named
@ConversationScoped
@ConversationGroup(AddressConversation.class)
public class EnquiryView implements Serializable
{
@Inject @ConversationGroup(AddressConversation.class) private AddressView addrView;
public Class<? extends Views> editAddress()
{
addrView.setAddress(editEnq.getAddress());
addrView.setFromView(Views.Enquiry.EnquiryEdit.class);
return Views.Address.AddressEdit.class;
}
}
I can also observe the navigation in EnquiryView
and update the enquiry entity when an address has been "saved" in the address edit view.
protected void onViewConfigNav(@Observes PreViewConfigNavigateEvent navigateEvent)
{
if (navigateEvent.getFromView() == Views.Address.AddressEdit.class &&
navigateEvent.getToView() == Views.Enquiry.EnquiryEdit.class)
{
onEditAddressReturn();
}
}
private void onEditAddressReturn()
{
if (addrView.getReturnAddress() != null) {
// Save pressed
editEnq.setAddress(addrView.getReturnAddress());
}
}