CDI bean不起作用,但托管bean是

时间:2013-08-27 19:33:52

标签: java-ee primefaces cdi managed-bean

我正在尝试填充PrimeFaces数据表:

<p:dataTable var = "milestoneIndentifier" id="milestoneTable" value = "#{milestoneIdentifierManager.milestoneIdentifiers}" paginator="true" >
    <p:column sortBy="name" headerText = "Milestone">
        <h:outputText value ="#{milestoneIndentifier.name}" /> 
    </p:column>

    <p:column sortBy="acroynm" headerText = "Acroynm">
        <h:outputText value ="#{milestoneIndentifier.acronym}" />
    </p:column>

    <p:column sortBy="phaseName" headerText = "Phase Name">
        <h:outputText value ="#{milestoneIndentifier.phaseName}" />
    </p:column>

    <p:column headerText = "Action">
    </p:column>
</p:dataTable>

我正在使用这个支持bean:

//@ManagedBean
//@ViewScoped
@Named
@ViewAccessScoped
public class MilestoneIdentifierManager extends PageBean {    
    private static final long serialVersionUID = 1L;

    private List<MilestoneIdentifier> milestoneIdentifiers; 
    @Inject
    private MilestoneIdentifierBusinessBean milestoneIdentifierBusiness;

    public MilestoneIdentifierManager() {
    }
    /**
     * @param name
     * @param acronym
     * @param phaseName
     */
    public void addMilestoneIdentifier(String name, String acronym, String phaseName)  {
        try {
            milestoneIdentifierBusiness.addMilestoneIdentifier(name, acronym, phaseName);
        } catch (AllValidationException e) {
            // TODO Auto-generated catch block
        }
    }

    public List<MilestoneIdentifier> getMilestoneIdentifiers() {
        return milestoneIdentifiers;
    }

    @PostConstruct
    public void init() {
        milestoneIdentifiers = new ArrayList<MilestoneIdentifier>();
        milestoneIdentifiers.add(new MilestoneIdentifier("Milestone A", "MSA", "Milestone A1"));
    }
}

当我尝试这样做时,表格表示没有找到记录。如果我发表评论:

@Named
@ViewAccessScoped

并取消注释:

@ManagedBean
@ViewScoped

然后该表将显示我在init方法中创建的里程碑。

编辑:我在WEB-INF文件夹中有一个beans.xml文件。

以下是代码导入:

import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.enterprise.context.SessionScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.inject.Inject;
import javax.inject.Named;

import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.ViewAccessScoped;

其中一些未使用,我还没有清理代码。

0 个答案:

没有答案