I'm developing a web application using JSF 2 and prettyfaces. I annotated one of my @ViewScoped
beans with pretty annotations. That's what I have:
@ManagedBean
@ViewScoped
@URLMapping(parentId = "app-list", id = "app-view", pattern = "/detail/#{appId}",
viewId = "/system/manage_app/content/app_detail/app_detail.xhtml")
public class NavegableAppView extends SystemNavegable {
/**
Basically that shows the details of an application which is installed in my system. This bean can be instanced in two ways, passing #{appId}
param, which indicates the id of the application which I want to load, or without that param, in this case the bean will recover this id from a @SessionScoped
bean.
That's how the page /system/manage_app/content/app_detail/app_detail.xhtml
is managing the parameter:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:p="http://primefaces.org/ui"
template="/templates/general_template.xhtml">
<ui:define name="metadata">
<f:metadata>
<f:viewParam id="appId" name="appId"
value="#{navegableAppView._ParamApp}" required="false" />
<f:event type="preRenderView"
listener="#{navegableAppView.initialize}" />
</f:metadata>
</ui:define>
<ui:define name="general_content">
<p:panel>
<!--More stuff-->
The problem here is I want NavegableAppView
bean to be created, with or without param. I have tried this way <p:button value="prueba" outcome="pretty:app-view" />
which works but limits me to do nothing more than outcome and also <p:commandButton value="prueba2" action="pretty:app-view" ajax="false" />
, which is the equivalent to call an action method and return the navigation case (that's what really I want).
First choice creates the bean properly and loads the value from the session. Second case, is giving me this error:
HTTP 500 - PrettyFaces: Exception occurred while building URL
for MappingId < app-view >, Required value < #{appId} > was null
So my target bean is not getting constructed. I have tried adding the parameter manually to the navigation case: return pretty:app-view?appId=1
and it works, but I want the target bean to recover it from the session itself. Do I have to call a redirect or something like that in my action method?
Pool your ideas.