简体   繁体   中英

f:viewParam not working in dependent or view only in request scope

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM