2011-03-23 48 views
1

我目前正在探索總理的面孔,我想知道我們如何驗證樹視圖中的選擇?隨着例如inputtextarea,這是很簡單的總理面臨驗證樹視圖

<p:inputTextarea id="description" 
    value="#{createAdd.add.description}" cols="50" rows="5" 
    validatorMessage="Max length is 25" required="true" 
    requiredMessage="Description is required"> 
    <f:validateLength maximum="25" /> 
</p:inputTextarea> 
<p:message for="description" /> 

在這裏,我們得到valdation使用所需的屬性和標籤的TextInput。但是對於TreeView組件沒有必需的屬性,並且標記不起作用。

因此,例如

<p:tree value="#{treeBean.root}" var="node" dynamic="true" 
id="category" selectionMode="single" 
    selection="#{createAdd.add.category}" > 
    <p:treeNode> 
     <h:outputText value="#{node}" /> 
    </p:treeNode> 
</p:tree> 

我們如何可以驗證一個節點實際上已經給出選擇?

回答

3

我認爲驗證必須在您的提交按鈕的操作方法中完成。

如果我理解正確,那麼您的p:tree有兩個豆子:TreeBeanCreatAdd豆子。我假設你的操作方法是在CreateAdd豆:

如果你的提交按鈕看起來是這樣的:

<h:commandButton value="#{bundle.del}" action="#{CreateAdd.doSubmitAction}"/> 

然後,你可以在操作方法檢查所選值:

public String doSubmitAction() { 
    if(category == null) { 
    FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "No node selected", "No node selected"); 
    FacesContext.getCurrentInstance().addMessage(null, facesMsg); 
    return null; 
    } 
    // do other stuff 
} 
+0

看起來像這正是我需要的。對不起,如果這是一個非常明顯的問題,但是我開始在同一時間開始使用JSF,Spring和Primefaces有點困惑:-) – Daniel 2011-03-24 15:58:44

0

你可以在你的支持bean中進行驗證。