I\'m developing a web application using JSF 2 and prettyfaces. I annotated one of my @ViewScoped
beans with pretty annotations. Th
So you are actually running into one of the "edge" effects of PrettyFaces. The "appId" parameter you have defined is actually treated both a parameter name, and also an EL bean value location for building links.
@URLMapping(parentId = "app-list", id = "app-view", pattern = "/detail/#{appId}",
viewId = "/system/manage_app/content/app_detail/app_detail.xhtml")
When you use the postback-action navigation functionality of PrettyFaces, it requires an EL bean name. Now, it just so happens that since you have not provided one in your @URLMapping
annotation, that PrettyFaces is going to try to use the parameter name anyway, and hope that it can find what you want. In this case, obviously, there is no bean value called #{appId}
.
You're really mixing two types of functionality that attempt to solve the same problem. Your <f:metadata>
and <f:viewParam>
definitions are doing the same thing that PrettyFaces does with its path-parameters and action methods. You should use one or the other mechanism. If you really want to mix them, then as you said, you should be invoking actual navigation from your <h:commandButton>
, like so:
<p:commandButton value="prueba2" action="#{navegableAppView.goToAppId}" ajax="false" />
Then, you'll need to make sure you return a valid JSF2 navigation string WITH the appId
parameter, such as:
public String goToAppId() {
return "/system/manage_app/content/app_detail/app_detail.xhtml?faces-redirect=true&appId=" + appId";
}
PrettyFaces will then understand that you are redirecting to a URL that has been mapped, and will perform outbound rewriting on the URL, and send you to the proper, /detail/#{addId}
instead. This is all in the docs.
The final option would simply to remove the <f:metadata>
and <f:viewParam>
, and use the built-in PrettyFaces functionality for managing view parameters instead. Simply removing the metadata and updating your @URLMapping
to this, would solve your problem:
@ManagedBean
@ViewScoped
@URLMapping(parentId = "app-list", id = "app-view", pattern = "/detail/#{appId : navegableAppView._ParamApp}",
viewId = "/system/manage_app/content/app_detail/app_detail.xhtml")
public class NavegableAppView extends SystemNavegable {
@URLAction
public String initialize() {
if ( appId != null ) {
this.item = appsDB.findById(appId);
return null;
}
// Add a message here, "The item {..} could not be found."
return "pretty:app-list";
}
This is how you initialize pages using PrettyFaces. When it comes down to it, if you are using pretty:mappingId
navigation, you should only use PrettyFaces features. If you are going to use normal JSF2-style navigation where you specify the view-id and all the parameters of the URL, then you can mix-and match (as long as you are using named path-parameters in your URL mappings.
I hope this helps.