0

I'm wondering if I'm having the same findings but after creating a javaee6 web project generated from jboss maven archetype I have the following result.

f:viewParam, did not work on dependent or view scope only in request scope.

public class BaseBean {
    protected boolean edit;

    public boolean isEdit() {
        System.out.println("get edit=" + edit);
        return edit;
    }

    public void setEdit(boolean edit) {
        System.out.println("set edit=" + edit);
        this.edit = edit;
    }
}

@Named
@RequestScoped
public class RequestBean extends BaseBean { }

@Named
public class DependentBean extends BaseBean { }

@Named
@ViewScoped
public class ViewBean extends BaseBean { }

<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"
    template="/WEB-INF/templates/default.xhtml">

    <ui:define name="metadata">
        <f:metadata>
            <f:viewParam name="edit" value="#{dependentBean.edit}" />
        </f:metadata>
    </ui:define>


    <ui:define name="content">
        <h:outputText value="#{dependentBean.edit}"></h:outputText>
    </ui:define>
</ui:composition>

For the request and view scope views, it's almost the same as the one above except for the manage bean used.

Any idea?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
czetsuya
  • 4,773
  • 13
  • 53
  • 99

1 Answers1

3

The problem is that you're mixing JSF annotations from package javax.faces.bean with CDI annotations (noticed by the usage of @Named) from package javax.enterprise.context and they can't be used altogether for being handled by different managers (JSF and CDI managers). In your application, your managed beans should be from JSF or from CDI, not from a mix of both.

Note that CDI doesn't support @ViewScoped yet, this scope is available only for JSF. More info: CDI missing @ViewScoped and @FlashScoped

Community
  • 1
  • 1
Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
  • I have a hunch about that problem but was not able to find a clear documentation. So still with the same problem, how can we implement f:viewParam in dependentScope? Why is it only working on requestScope? – czetsuya Jun 09 '13 at 12:13
  • @czetsuya the problem is that `@ViewScoped` is from JSF and doesn't mix with CDI `@Named` annotation, thus giving you errors. If you change `@Named` to `@ManagedBean` and other CDI to proper JSF annotations, it will work as expected. – Luiggi Mendoza Jun 09 '13 at 17:24
  • yes I already updated that part but still f:viewParam only works on requestScope and not on dependentScope. – czetsuya Jun 13 '13 at 07:29