0

問題は本質的に上記のとおりです。ここの例では:

http://www.primefaces.org/showcase-labs/ui/mindmap.jsf

NS(s) をクリックすると、選択した子ノードの 1 つ (ns7.google.com など) をクリックして、それらを結合する線が残っているので NS(s) に戻ることができます。

1,2,3,4,5,6 という 6 つのエントリがあります。それらはすべてさまざまな方法でリンクされており、マインドマップでは色で示されています。「1」がルートノードだとします。次に、2,3,4,5,6 が表示されます。6 をクリックすると、マインドマップが再描画されて 6 のリンクが表示され、隅に 1 が離れてルートであることを示します。ただし、そこから 1 以外のノードをクリックすると、ほとんどのノードと同様に、リンク線がすべて消えます (一部のノードである場合もあれば、別のノードである場合もあれば、すべてのノードである場合もある理由がわかりません)。そしてもう後戻りはできません。以下は、マインドマップ Bean と html のコードです。

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jsf;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
import jpa.entities.Enginetable;
import jpa.session.EnginetableFacade;
import org.primefaces.event.SelectEvent;
import org.primefaces.model.mindmap.DefaultMindmapNode;
import org.primefaces.model.mindmap.MindmapNode;

/**
 *
 * @author AOL
 */
@Named(value = "mmBean")
@RequestScoped
public class mmBean implements Serializable{

    @EJB
    private jpa.session.EnginetableFacade ejbFacade;
    private MindmapNode root;

    private MindmapNode selectedNode;

    private List<Enginetable> elements;
    private List<Enginetable> filteredElements;
    private List<Enginetable> userlist;

    private Enginetable selectedElement;
    private Enginetable[] selectedElements; 


    private List<Enginetable> elementlist = new ArrayList<Enginetable>();

    private Enginetable nodeentity = new Enginetable();
    private Enginetable rootentity = new Enginetable();
    private Enginetable user = new Enginetable();

    private static final String[] username;

    static{

        username = new String[10];  
        username[0] = "Mercedes";  
        username[1] = "BMW";  
        username[2] = "Volvo";  
        username[3] = "Audi";  
        username[4] = "Renault";  
        username[5] = "Opel";  
        username[6] = "Volkswagen";  
        username[7] = "Chrysler";  
        username[8] = "Ferrari";  
        username[9] = "Ford";  
    }

    /**
     * Creates a new instance of MmBean
     */
    public mmBean() {
    }

    @PostConstruct
    public void init() {
        ///if(elements==null){
        elements = new ArrayList<Enginetable>(); 
        this.userlist = this.getFullList();
        Enginetable entity;
        //} 
        //remoteuser=null;
        // this.populateRandomElements(elements, 10); 
        this.populateRandomElements(elements,6);  

        // filteredElements = new ArrayList<Graphelement>();
        this.user = this.userlist.get(0);
        this.rootentity = this.user;
        root = new DefaultMindmapNode(user.getStartnode(), "Google", "006666", false);
        /*MindmapNode bmw = new DefaultMindmapNode("BMW", "IP Nos", "6e9ebf", true);
        MindmapNode volvo = new DefaultMindmapNode("Volvo", "Names", "6e9ebf", true);
        MindmapNode audi = new DefaultMindmapNode("Audi", "Malicious ", "6e9ebf", true);
        MindmapNode renault = new DefaultMindmapNode("Renault", "IP Nos", "6e9ebf", true);
        MindmapNode opel = new DefaultMindmapNode("Opel", "Names", "6e9ebf", true);
        MindmapNode volkwagen = new DefaultMindmapNode("Volkswagen", "Malicious ", "6e9ebf", true);
        MindmapNode chrysler = new DefaultMindmapNode("Chrysler", "IP Nos", "6e9ebf", true);
        MindmapNode ferrari = new DefaultMindmapNode("Ferrari", "Names", "6e9ebf", true);
        MindmapNode ford = new DefaultMindmapNode("Ford", "Malicious ", "6e9ebf", true);*/


        Object label = root.getLabel();


        for( int i = 0 ; i < this.userlist.size() ; i++){

                    entity = this.userlist.get(i);


                    if ( !label.equals(entity.getStartnode() ) && this.user.getEndnode().equals(entity.getStartnode() ) )  { ////this.rootentity.getEndnode().equals(entity.getStartnode())

                            root.addNode(new DefaultMindmapNode(entity.getStartnode() , "Malicious Software: ", "33FF00", true));

                    } 

                    else if ( !label.equals(entity.getStartnode() ) && this.user.getEndnode() != entity.getStartnode() ){

                            root.addNode(new DefaultMindmapNode(entity.getStartnode() , "Malicious Software: ", "CC0000", true));

                    }

        }

    }

    public void setElements(List<Enginetable> elements) {
        this.elements = elements;
    }

    public List<Enginetable> getElements() {
        return elements;
    }
    public void setFilteredElements(List<Enginetable> filteredElements) {
        //this.filteredElements = filteredElements;
        this.elements=filteredElements;
    }

    public List<Enginetable> getFilteredElements() {
        return filteredElements;
    }

    public void setSelectedElements(Enginetable[] selectedElements) {
        this.selectedElements = selectedElements;
    }

    public Enginetable[] getSelectedElements() {
        return selectedElements;
    }

    public void setSelectedElement(Enginetable selectedElement) {
        this.selectedElement = selectedElement;
    }

    public Enginetable getSelectedElement() {
        return selectedElement;
    }

    public MindmapNode getRoot() {
        return root;
    }

    public MindmapNode getSelectedNode() {
        return selectedNode;
    }
    public void setSelectedNode(MindmapNode selectedNode) {
        this.selectedNode = selectedNode;
    }



    public void onNodeSelect(SelectEvent event) {
        MindmapNode node = (MindmapNode) event.getObject();


            for( int i = 0 ; i < this.elements.size() ; i++){
                    Enginetable entity;
                    Object label = node.getLabel();
                    Object rootlabel = this.root.getLabel();

                    entity = userlist.get(i);

                    if ( entity.getStartnode() == rootlabel ){
                        this.rootentity = entity;
                    }
                    if ( entity.getStartnode() == label ){
                        this.nodeentity = entity;
                    }

            }
    //load children of select node and add via node.addNode(childNode);
    //populate if not already loaded
            if(node.getChildren().isEmpty()) {
               this.setChildNodes( node ); 
            }
        }


    public void onNodeDblselect(SelectEvent event) {
        this.selectedNode = (MindmapNode) event.getObject();        
    }


    private EnginetableFacade getFacade() {
        return ejbFacade;
    }



    private void populateRandomElements(List<Enginetable> list, int size) { 
        userlist = this.getFullList();
        for(int i = 0 ; i < size ; i++)  {

                Enginetable gel = new Enginetable();
                gel.setMoveid(i);
                gel.setUserid(i);
                gel.setStartnode(username[i]);
                gel.setEndnode(username[9-i]);
                gel.setConnections(username[9-i]);
         //       gel.setPurpose("dubious");
         //       gel.setRelationship("naughty");
         //       gel.setExperimentid(1);
                gel.setNewinfovalue(1);
                gel.setNewconnectioncost(1);
                list.add(gel);                
        }
    }

//


    public Integer getMoveId(Enginetable ent) {
        return ent.getMoveid();
    }

    public void setMoveId(Enginetable ent, Integer id) {
        ent.setMoveid(id);
    }

    public Integer getUserId(Enginetable ent) {
        return ent.getMoveid();
    }

    public void setUserId(Enginetable ent, Integer id) {
        ent.setMoveid(id);
    }

    public String getStartNode(Enginetable ent) {
        return ent.getStartnode();
    }

    public void setStartNode(Enginetable ent, String startnode) {
        ent.setStartnode(startnode);
    }

    public String getEndNode(Enginetable ent) {
        return ent.getEndnode();
    }

    public void setEndNode(Enginetable ent, String endnode) {
        ent.setEndnode(endnode);
    }

 /*   public int getExperimentid(Enginetable ent) {
        return ent.getExperimentid();
    }

    public void setExperimentid(Enginetable ent, int experimentid) {
        ent.setExperimentid(experimentid); 
    }*/

    public int getNewInfoValue(Enginetable ent) {
        return ent.getNewinfovalue();
    }

    public void setNewInfoValue(Enginetable ent, int totalinfovalue) {
        ent.setNewinfovalue(totalinfovalue);
    }

    public String getConnections(Enginetable ent) {
        return ent.getConnections();
    }

    public void setConnections(Enginetable ent, String connections) {
        ent.setConnections(connections);
    }

    public String getNewConnections(Enginetable ent) {
        return ent.getConnections();
    }

    public void setNewConnections(Enginetable ent, String newconnections) {
        ent.setConnections( newconnections );
    }

 /*   public String getUserName(Enginetable ent) {
        return ent.getUsername();
    }

    public void setUsername(Enginetable ent, String name) {
        ent.setUsername(name);
    }
 */

    // ADDED BY AODHÁN

    public List<Enginetable> getListByUsername(String user){
       return this.ejbFacade.getEnginetableByUsername(user);
    } 

    public List<Enginetable> getListByUserID( int id ){
       return this.ejbFacade.getEnginetableByUserid(id);
    } 

    public List<Enginetable> getFullList(){
       return this.ejbFacade.getFullEnginetable();
    } 

    public void setChildNodes( MindmapNode node ){

            for( int i = 0 ; i < this.userlist.size() ; i++){
                    Enginetable entity;

                    entity = this.userlist.get(i);

                    if ( (this.nodeentity.getStartnode() == null ? entity.getStartnode() != null : !this.nodeentity.getStartnode().equals(entity.getStartnode())) && (this.nodeentity.getEndnode() == null ? entity.getStartnode() != null : !this.nodeentity.getEndnode().equals(entity.getStartnode())) &&  (this.rootentity.getEndnode() == null ? entity.getStartnode() == null : this.rootentity.getEndnode().equals(entity.getStartnode()))  )  {

                            node.addNode(new DefaultMindmapNode(entity.getStartnode() , "Malicious Software: ", "33FF00"));

                    } 

                     else if ( (this.nodeentity.getStartnode() == null ? entity.getStartnode() != null : !this.nodeentity.getStartnode().equals(entity.getStartnode())) && (this.nodeentity.getEndnode() == null ? entity.getStartnode() == null : this.nodeentity.getEndnode().equals(entity.getStartnode())) &&  (this.rootentity.getEndnode() == null ? entity.getStartnode() == null : this.rootentity.getEndnode().equals(entity.getStartnode()))  )  {

                            node.addNode(new DefaultMindmapNode(entity.getStartnode() , "Malicious Software: ", "0066FF"));

                    }

                    else if ( (this.nodeentity.getStartnode() == null ? entity.getStartnode() != null : !this.nodeentity.getStartnode().equals(entity.getStartnode())) && (this.nodeentity.getEndnode() == null ? entity.getStartnode() == null : this.nodeentity.getEndnode().equals(entity.getStartnode())) &&  (this.rootentity.getEndnode() == null ? entity.getStartnode() != null : !this.rootentity.getEndnode().equals(entity.getStartnode()))  )  {

                            node.addNode(new DefaultMindmapNode(entity.getStartnode() , "Malicious Software: ", "FFCC00"));

                    }

                    else if ( (this.nodeentity.getStartnode() == null ? entity.getStartnode() != null : !this.nodeentity.getStartnode().equals(entity.getStartnode())) && (this.nodeentity.getEndnode() == null ? entity.getStartnode() != null : !this.nodeentity.getEndnode().equals(entity.getStartnode())) &&  (this.rootentity.getEndnode() == null ? entity.getStartnode() != null : !this.rootentity.getEndnode().equals(entity.getStartnode()))  )  {

                            node.addNode(new DefaultMindmapNode(entity.getStartnode() , "Malicious Software: ", "CC0000"));

                    }

                }
    }
}

HTML:

<h:form>
    <p:mindmap value="#{mmBean.root}" style="width:100%;height:600px">
        <p:ajax event="select" listener="#{mmBean.onNodeSelect}" />
        <p:ajax event="dblselect" listener="#{mmBean.onNodeDblselect}" update="output" oncomplete="details.show()"/>
    </p:mindmap>    

    <p:dialog widgetVar="details" header="Node Details" resizable="false" modal="true" showEffect="fade" hideEffect="fade">
        <h:outputText id="output" value="#{mmBean.selectedNode.data}" />
    </p:dialog>                 
</h:form>

どんな助けでも大歓迎です。

4

1 に答える 1

1

私は同じ問題に直面し、@SessionScoped代わりに を追加するだけで解決しました@RequestScoped

これで、PF の例に示すように、選択と二重選択ができるようになりました。

于 2013-05-21T18:51:35.667 に答える