1

状況は次のとおりです。3 つの異なるタイプのオブジェクトを持つ treeTable があります。テーブルには、event="select" を指定した p:ajax が含まれています。タイプごとに1つずつ、3つの異なるcontextMenusを作成しました...そしてすべてうまくいきます。

私の問題は、いくつかのメニューアイテムを有効/無効にしたいということです。そのために、選択したノードのプロパティに基づく条件で「レンダリング」属性を使用します。すべてが機能しますが、同じオブジェクトを 2 回目に右クリックしたときだけです (contextMenu がフィルター処理されていないのは初めてです)。

コードは次のとおりです...(semplicityのために1つのタイプのオブジェクトのみを含めています)

ツリーテーブル ページ:

<h:form id="form" prependId="false">
    <p:treeTable value="#{documentsController.root}" var="document" id="docs" 
            selectionMode="single" selection="#{documentsController.selectedNode}">

        <p:ajax event="select" process="@this" update=":form:menus"/>

        <p:column headerText="#{msg['name']}">
            <h:outputText value="#{document.name}" />
        </p:column>
    </p:treeTable>

    <h:panelGroup id="menus">
        <ui:include src="/menu/document_menu.xhtml"/>
    </h:panelGroup>

    <p:dialog id="document-rename-dialog" widgetVar="documentRenameDialog" header="#{msg.rename}">
        <h:panelGrid id="doc-rename" columns="2">
            <h:outputLabel for="name" value="#{msg.name}:" />
            <h:inputText id="name" value="#{documentsController.name}"/>
        </h:panelGrid>

        <div class="spacer-10" />

        <h:panelGroup layout="block">
            <p:commandLink onclick="documentRenameDialog.hide();" value="#{msg.cancel}"/>
            <p:commandLink actionListener="#{documentsController.renameDocument(documentsController.selectedNode.data)}"
            process="@this :form:document-rename-dialog:doc-rename"
            update=":form:docs"
            oncomplete="documentRenameDialog.hide();"
            value="#{msg.check}">
        </h:panelGroup>
    </common:dialog>
</h:form>

document_menu ページ:

<p:contextMenu id="contextMenuDocument" for="docs" nodeType="document">
    <p:menuitem value="#{msg.rename}" process="@this docs" update=":form:document-rename-dialog:doc-rename"
        actionListener="#{documentsController.setName(documentsController.selectedNode.data.name)}"
        rendered="#{documentsController.canWrite}"
        icon="ui-icon-pencil" oncomplete="documentRenameDialog.show();"/>
</p:contextMenu>

DocumentsController クラス:

@ManagedBean
@ViewScoped
public class DocumentsController {
    private TreeNode root;
    private TreeNode selectedNode;
    private String name;

    public TreeNode getSelectedNode() {
        return selectedNode;
    }

    public void setSelectedNode(TreeNode selectedNode) {
        this.selectedNode = selectedNode;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void renameDocument(ArterDocument selectedDocument) {
        if(name != null && !name.equals("")) {
            System.out.println("Document renamed in: "+name);
            ((MyDocument)selectedNode.getData()).setName(name);
        }
        else
            addErrorMessage("Error renaming document.");
    }

    public static boolean canWrite() {
        if(((MyDocument)selectedNode.getData()).isWriteable())
            return true;
        return false;
    }
}

MyDocument クラスは、文字列 (名前) とブール値 (書き込み可能) を持つ単純なクラスです。

最初のショットでフィルター処理された contextMenu を表示する方法を教えてもらえますか?

ありがとうございました!

4

0 に答える 0