@PostConstruct初始化不会被隐式调用

时间:2014-01-16 09:46:51

标签: jsf jsf-2 primefaces

使用-Primefaces 3.4 + JSF 2.0- 我正在显示数据库中的一些下拉值,并且Postconstruct初始化方法没有隐式调用。 当我从其他bean调用init方法时它正在工作。 xhtml代码:

<p:panelGrid style="width:50%" styleClass="panelgrid">
    <p:row>
                        <p:column styleClass="columnA" style="width:10%">#{msgs.partTypeTitle}</p:column>
                        <p:column styleClass="columnB">
                            <h:selectOneMenu id="partTypeDpDnId" value="#{ppcrDetails.newPpcr.selectedPartType}" style="width:150px;font-size:13px;" >
                                <f:selectItems value="#{ppcrDetails.newPpcr.partsType}" />
                            </h:selectOneMenu>
                        </p:column>
                    </p:row>

                    <p:row>
                        <p:column styleClass="columnA" style="width:25%">#{msgs.familyTitle}</p:column>
                        <p:column styleClass="columnB">     
                            <h:selectOneMenu id="familyDpDnId" value="#{ppcrDetails.newPpcr.selectedFamilyValues}" style="width:150px;font-size:13px;">
                                <f:selectItems value="#{ppcrDetails.newPpcr.familyValues}" />
                            </h:selectOneMenu>
                        </p:column>
                    </p:row>
                </p:panelGrid>

-Bean:

@ManagedBean(name = "newPpcr" , eager = true)
@SessionScoped
public class NewPpcr implements Serializable {
@PostConstruct
    public void initialize() throws QtException {

        LOGGER.log(Level.DEBUG, "QuotationTool: NewPpcr initilize.");

        partsType.clear();
        List<MdPartsType> partList = partsTypeFacade.findAll();
        int partSequence = 0;
        for (MdPartsType part : partList) {
            partsType.add(new SelectItem(partSequence++, part.getPartType()));
        }

        familyValues.clear();
        List<MdFamily> familyList = familyFacade.findAll();
        int familySequence = 0;
        for (MdFamily family : familyList) {
            familyValues.add(new SelectItem(familySequence++, family.getFamily()));
        }

    }

但这不起作用,所以我从其他bean调用initialize方法然后下拉填充:

@ManagedBean(name = "ppcrDetails", eager = true)
@SessionScoped
public class PpcrDetails implements Serializable{
    private List<SelectItem> partType = new ArrayList<SelectItem>();
        private List<SelectItem> familyValues = new ArrayList<SelectItem>();


        public List<SelectItem> getPartType() {
            try {
                partType.clear();
                if (partType == null || partType.isEmpty()) {
                    newPpcr.initialize();
                    this.partType = newPpcr.getPartsType();
                }
            } catch (QtException e) {
                LOGGER.error(e.getMessage(), e);
            }
            return partType;
        }

        public void setPartType(List<SelectItem> partType) {
            this.partType = partType;
        }

        public List<SelectItem> getFamilyValues() {
            try {
                familyValues.clear();
                if (familyValues == null || familyValues.isEmpty()) {
                    newPpcr.initialize();
                    this.familyValues = newPpcr.getFamilyValues();
                }
            } catch (QtException e) {
                LOGGER.error(e.getMessage(), e);
            }
            return familyValues;
        }

        public void setFamilyValues(List<SelectItem> familyValues) {
            this.familyValues = familyValues;
}

从这种方法我可以显示值,但它打破了一些功能。

0 个答案:

没有答案