SelectOneListbox值集

时间:2015-06-24 12:49:43

标签: jsf primefaces selectonelistbox

我正在尝试使用Primefaces在JSF中编写两个SelectOneListbox。问题是第二个Listbox没有将值设置为我的支持bean变量。第一个Listbox工作正常。

@ManagedBean
public class AnalyseBean implements Serializable {

private static final long serialVersionUID = 1L;

private CorpusFacade corpusFacade;
private String selectedCorpus;
private String selectedDocument;
private List<Corpus> corpusList;
private List<Document> documentList;

Corpus corpus;
Document document;

public void corpusListener(AjaxBehaviorEvent e) {
    corpus = getCorpusFacade().findCorpusById(Integer.valueOf(selectedCorpus));
    documentList = corpus.getAllDocuments();
}

public void documentListener(AjaxBehaviorEvent e) {
//      document = corpus.getDocumentByName(selectedDocument);
//      System.out.println(document.getName());
}

public CorpusFacade getCorpusFacade() {
    if(corpusFacade == null) {
        corpusFacade = new CorpusFacade();
    }

    return corpusFacade;
}
public void setCorpusFacade(CorpusFacade corpusFacade) {
    this.corpusFacade = corpusFacade;
}

public String getSelectedCorpus() {
    return selectedCorpus;
}

public void setSelectedCorpus(String selectedCorpus) {
    this.selectedCorpus = selectedCorpus;
}

public List<Corpus> getCorpusList() {
    if(corpusList == null) {
        corpusList = getCorpusFacade().listAll();
    }

    return corpusList;
}

public void setCorpusList(List<Corpus> corpusList) {
    this.corpusList = corpusList;
}

public List<Document> getDocumentList() {
    if(documentList == null) {
        Corpus tempCorp = new Corpus();
        Document tempDoc = new Document("", "", "", 0.0, null, tempCorp);
        tempCorp.addDocument(tempDoc);

        documentList = tempCorp.getAllDocuments();
    }

    return documentList;
}

public void setDocumentList(List<Document> documentList) {
    this.documentList = documentList;
}

public String getSelectedDocument() {
    return selectedDocument;
}

public void setSelectedDocument(String selectedDocument) {
    this.selectedDocument = selectedDocument;
}
}   

XHTML

<h:form>
    <p:selectOneListbox id="corpList" value="#{analyseBean.selectedCorpus}">
        <f:selectItems value="#{analyseBean.corpusList}" var="corpus" itemValue="#{corpus.id}" itemLabel="#{corpus.name}" />
        <f:ajax event="change" listener="#{analyseBean.corpusListener}" render="docList" />
    </p:selectOneListbox>

    <p:selectOneListbox id="docList" value="#{analyseBean.selectedDocument}">
        <f:selectItems value="#{analyseBean.documentList}" var="document" itemValue="#{document.id}" itemLabel="#{document.name}" />
        <p:ajax event="change" listener="#{analyseBean.documentListener}" />
    </p:selectOneListbox>
</h:form>

0 个答案:

没有答案