Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

b:tree data always is null #422

Closed
cooperlyt opened this issue Jun 20, 2016 · 18 comments
Closed

b:tree data always is null #422

cooperlyt opened this issue Jun 20, 2016 · 18 comments
Assignees
Labels
Milestone

Comments

@cooperlyt
Copy link
Contributor

cooperlyt commented Jun 20, 2016

    new DefaultNodeImpl("title","asterisk","data");

    public void processValueChange(TreeNodeSelectionEvent treeNodeSelectionEvent) {
       Node node = treeNodeSelectionEvent.getNewSelectedNode();
       logger.config("data:" + node.getData());
    }

@SessionScoped or @RequestScoped call getData() always is null;

@asterd
Copy link
Collaborator

asterd commented Jun 20, 2016

Hi @cooper-lyt, I've done some tests in my environment and I can't reproduce your issue.
Actually, the selection listener fires only on row selection and not row check, but anyway, the newSelectedNode is correctly populated. Can you post a more detailed example? In this way, I can understand better what's the problem!

@cooperlyt
Copy link
Contributor Author

cooperlyt commented Jun 20, 2016

@asterd

public class OfficeTreeProducer implements java.io.Serializable{

         public class OfficeTypeNodeImpl extends DefaultNodeImpl{

        public OfficeTypeNodeImpl(Office.Type type) {
            super(enumHelper.getLabel(type), type.getIcon(),true);
            setData(type.name());
        }

        public Office.Type getType(){
           return Office.Type.valueOf(getData());
        }
    }

    @Inject
    private OfficeRepository officeRepository;

    @Inject
    private EnumHelper enumHelper;

    @Produces
    @Named
    @SessionScoped
    public Node getOfficeTree(){
        Node result = new DefaultNodeImpl("root");
        List<Office.Type> types = new ArrayList<Office.Type>(EnumSet.allOf(Office.Type.class));
        Collections.sort(types);
        for(Office.Type type: types){


            List<Office> offices = officeRepository.findByCategoryVaild(type);
            if (!offices.isEmpty()) {
                Node typeNode = new OfficeTypeNodeImpl(type);
                for (Office office: offices){
                    typeNode.getChilds().add(new DefaultNodeImpl(office.getName(),"asterisk",office.getId()));
                }
                result.getChilds().add(typeNode);
            }
        }
        return result;

    }

}
@Named
public class EmployeeList implements TreeNodeEventListener, java.io.Serializable {

    @Inject
    private OfficeHome officeHome;

    @Inject
    private Logger logger;



    public void processValueChange(TreeNodeSelectionEvent treeNodeSelectionEvent) {
        Node node =treeNodeSelectionEvent.getNewSelectedNode();

        logger.config("dd" + node.getClass().getName());
        if (node instanceof OfficeTreeProducer.OfficeTypeNodeImpl){
            logger.config("1.select type node!");
        }else{
            logger.config("1.not select type node data:" + node.getData());
        }
    }

    public void processValueChecked(TreeNodeCheckedEvent treeNodeCheckedEvent) {

    }

    public void processValueUnchecked(TreeNodeCheckedEvent treeNodeCheckedEvent) {

    }

    public boolean isValueSelected(Node node) {
        if (node instanceof OfficeTreeProducer.OfficeTypeNodeImpl){
            logger.config("select type node!");
        }else{
            logger.config("not select type node data:" + node.getData());
        }
        return true;
    }

    public boolean isValueChecked(Node node) {
        return true;
    }
}
    <b:tree value="#{officeTree}" renderRoot="false" showCheckbox="false" showTags="true"
                       enableLinks="false" nodeSelectionListener="#{employeeList}"
                       showBorder="true"/>

@asterd
Copy link
Collaborator

asterd commented Jun 20, 2016

Thank you @cooper-lyt. Just a rapid question before looking deeper in your code: have you put the b:tree component inside a form?

@asterd
Copy link
Collaborator

asterd commented Jun 21, 2016

Sorry for my silence but i can't reproduce your bug.. Are you using the latest version of bootsfaces?anyway i'll try to look at this problem in the next few days..please be patient! :)

@cooperlyt
Copy link
Contributor Author

cooperlyt commented Jun 21, 2016

@asterd version is 0.8.6

i use showcase source
modify code add a "datadata" to data:

    private void initStatefullRootNode() {
        statefullRootNode = new DefaultNodeImpl("root", "arrow-right").withBackColor("#FF1188");
        List<Node> nodeList = new ArrayList<Node>();
        nodeList.add(new DefaultNodeImpl("Node1", "user","datatata"));
        nodeList.add(new DefaultNodeImpl("Node2", "envelope","datatata"));

        List<Node> subNodes = new ArrayList<Node>();
        subNodes.add(new DefaultNodeImpl("Subnode1", "user","datatata"));
        subNodes.add(new DefaultNodeImpl("Subnode2", "main","datatata"));
        subNodes.add(new DefaultNodeImpl("Subnode3", "arrow-left","datatata"));
        DefaultNodeImpl nx = new DefaultNodeImpl("Child4-Link", "arrow-right","datatata");
...
}


 @Override
    public void processValueChange(TreeNodeSelectionEvent event) {
        System.out.println("SELEZIONATO NODO:");
        System.out.println("NEW TITLE: " + event.getNewSelectedNode().getText());
        if(event.getOldSelectedNode() != null)
            System.out.println("OLD TITLE: " + event.getOldSelectedNode().getText());

        selectedNode = event.getNewSelectedNode();
        System.out.println("DATA is:" + selectedNode.getData());
    }
            <h:form prependId="false">
                <b:container id="treeContent">
                    <b:row>
                        <b:column>
                            <b:tree render-root="false" value="#{test.treeModel}"
                                    node-selection-listener="#{test}" showCheckbox="true"
                                    enableLinks="true" showBorder="false" update="chkItems" />
                        </b:column>
                    </b:row>
                    <b:row>
                        <b:inputText id="chkItems" styleClass="test" value="#{test.checkedColumns}" />
                    </b:row>
                </b:container>
            </h:form>

output is

07:07:06,785 INFO  [stdout] (default task-13) SELEZIONATO NODO:
07:07:06,786 INFO  [stdout] (default task-13) NEW TITLE: Node1
07:07:06,786 INFO  [stdout] (default task-13) DATA is:null

@yasinkasap
Copy link

yasinkasap commented Jun 30, 2016

Hi @asterd ,

We use bootsfaces on our project and we have upgraded version 0.8.1 to 0.8.6. The tree component new and came from 0.8.6. I faced the same issue @cooper-lyt said. I will try to do clear explanation my issue.

in jsf (xhtml) the tree component is :

                        <b:tree id="soruListesi" value="#{soruTanimlariMb.sorularTreeList}" 
                            render-root="false" node-selection-listener="#{soruTanimlariMb}">
                        </b:tree>

soruTanimlariMb is Viewscoped managed bean and sorularTreeList is a Node property of mb. The mb has also a Node property seciliNode for selected node.
On mb's init method, i reproduced sub nodes of sorularTreeList root node from db and the node list shows on page properly. The soruTanimlariMb is also a listener for node events. The mb is shortly as follows.

@ManagedBean (name = "soruTanimlariMb")
@ViewScoped
public class SoruTanimlariManagedBean extends BaseManageBean implements TreeNodeEventListener {

....
    private Node sorularTreeList;
    private Node seciliNode;
....

// The init method

    @PostConstruct
    public void init () {
            //root node definition, the node has no data        
            sorularTreeList = new DefaultNodeImpl("Soru Tanım Listesi", null, null);
           // Sub node of sorularTreeList population from db codes
           for (Entity item : aList) {
              // i set subnode's custom data from here
              Node subNode = new DefaultNodeImpl(item.getName(), null, item.getId().toString());
              sorularTreeList .getChilds().add(subNode);
           }
        }

//action method of some commandbutton. At this method, the selected node's (seciliNode) custom data was null

    public void actionEkleTekrarliSoru() {
                    String data = seciliNode.getData();  // data comes null at here 

        }

// Listener impl. event method

    @Override
    public void processValueChange(TreeNodeSelectionEvent event) {
        seciliNode = event.getNewSelectedNode();
    }

At the last line of processValueChange method, i watched on debug, the secilinode's text came from the entity's getName() method but data was null. At here as text came form entity's getName() why data doesn't come from entity's getId() ? At init method, i set up all subnode's data from entity's getId()

Thanks for interest

@asterd
Copy link
Collaborator

asterd commented Jun 30, 2016

Hi @yasinkasap, I'll going crazy to try to debug this problem, because in my environment, with the same configuration, it works without problems. Now, with your example, I have found another hint to follow: have you implemented in a correct way, the "isValueSelected" method of the TreeNodeEventListener interface?
for example, in my environment, the method is implemented as follow:

    private Node selectedNode;

    [...]

    @Override
    public boolean isValueSelected(Node arg0) {
        if(selectedNode != null) {
            return selectedNode.getText().equalsIgnoreCase(arg0.getText());
        }
        return false;
    }

I know that is a trivial implementation, but the renderer of the tree component, to find the real selected node, needs this method. Can you try to implement it and give me a feedback please?

@yasinkasap
Copy link

Hi @asterd

My impl is :

@Override
public boolean isValueSelected(Node data) {
    if(seciliNode != null) {
        return seciliNode.getText().equalsIgnoreCase(data.getText());
    }
    return false;
}

page screenshut :

image

eclipse debug screenshut at processValueChange method :

image

for be sure, node's data set to some value at init method :
As a see from screenshut,subnode's data was set to a value. The two node's text same so the two node same but in processValueChange method, the node's data lost despite node's text still exist.

image

@asterd asterd added the bug label Jun 30, 2016
@asterd asterd added this to the v0.9.0 milestone Jun 30, 2016
@asterd asterd self-assigned this Jun 30, 2016
asterd added a commit to asterd/BootsFaces-OSP that referenced this issue Jun 30, 2016
@asterd
Copy link
Collaborator

asterd commented Jun 30, 2016

Ok! finally I've found the bug!! I've committed on cc0eab5 the resolution for this issue. Maybe you have to wait for the next release or for a developer snapshot if @stephanrauh can please do that! Obviously, there is a better and more flexible way to fix this bug but now I'm a little bit busy, so I think that the "beautiful" resolution is postponed to 0.9.1 or later.. but for now, it works (i hope :) )!

@yasinkasap
Copy link

Hi @asterd ,

Thanks for reply. I'm waiting your news :). This will be good for us. I tried to use different tree components such as in primefaces and butterfaces. These components didn't work properly on our project. if the issue is solved, everything ok for us.

One more think, it be nice a search text box for tree component :)

Thanks.

@asterd
Copy link
Collaborator

asterd commented Jun 30, 2016

Ok.. I've done it in a more flexible way! :) waiting for developer snapshot!

@stephanrauh
Copy link
Collaborator

I've just uploaded the snapshot. See #369 on how to get it.

@stephanrauh
Copy link
Collaborator

stephanrauh commented Jun 30, 2016

@yasinkasap @cooper-lyt Could you give the snapshot a try and report us back if the bug has been fixed, please?

Thanks in advance!
Stephan

@yasinkasap
Copy link

Hi @stephanrauh,

I couldn't try to the fix, because after adding new repository as you said #369 https://oss.sonatype.org/content/repositories/snapshots on pom xml and maven settings.xml, it recognized 0.9.0-SNAPSHOT version but in java classes import net.bootsfaces.* packages were not recognized. We used the packages in many classes, managed beans. Whrn i changed to 0.8.6 version errors has gone.

@stephanrauh
Copy link
Collaborator

stephanrauh commented Jul 1, 2016 via email

@yasinkasap
Copy link

Hi @stephanrauh ,

sorry for late. I tested 0.9.1 snapshot version in different environment. The bug was solved and i able to get node's data many places in code.

Can i a request, may you give a forecast about 0.9.1 production version date ?

thanks.

@stephanrauh
Copy link
Collaborator

Let's publish 0.9.0 first :). Current forecast: soon. Maybe even this weekend, depending on the result on our tests.

@yasinkasap
Copy link

Excuse :) i wrote wrong.
Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants