1
votes

I have a page with datatable with product information from which at a product selection action I redirect to product info page passing a parameter:

configurableNavigationHandler.performNavigation("productInfo?faces-redirect=true&prId=" + selectedCpl.getP().getPrId());

In my viewscoped bean in my init method I get the request parameter and fill the objects needed:

@ManagedBean
@ViewScoped
public class ProductInfo implements Serializable {

private Product p;
private Integer prId;

@PostConstruct
private void init() {
    HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
    if (request.getParameter("prId") != null) {
        prId = Integer.parseInt(request.getParameter("prId"));
        p = pf.find(prId);

On my productInfo.xhtml I have a product info view and a dialog to edit the product info but when I press submit my the request parameter is null:

<p:commandButton styleClass="button-edit" value="Submit" actionListener="#{productInfo.saveProduct()}" update="prodInfo" oncomplete="dlg.hide();"/>  

I'm using jsf 2.0 with primefaces elements.

Can anyone help me? Thank you.

1

1 Answers

1
votes

That's not a session parameter. That's a request parameter. That it's null is because you are not sending it along with the submit request. Send it by <f:param>.

<p:commandButton ...>
    <f:param name="prId" value="#{productInfo.prId}" />
</p:commandButton>

Unrelated to the concrete problem, there are several other potential problems. First, the view scoped bean should not be recreated when you submit the form. Perhaps you're using tag handlers in the view. Second, you should absolutely avoid hauling the raw javax.servlet API from under the JSF covers as much as possible. Use ExternalContext#getRequestParameterMap() instead. Third, the <f:viewParam> is much cleaner than that postconstruct. Fourth, redirecting by a navigation handler smells like a design problem in the view, e.g. why not use just a GET link?

The in-depth explanations on all of those issues are available in Communication in JSF 2.0.