The inner class tree property of ZK cannot be accessed

I am encountering a similar issue to the one discussed in this question: Property not readable on a inner class in a TreeModel

However, the solution provided does not seem to work for my case.

I have successfully implemented my Entity and TreeModel for a tree structure. Despite everything working fine, the "data" property is not being recognized on the treecell in my .zul file.

Below is a snippet of the code:

-The structure implementation, executed @AfterCompose:

 // Code snippet showing hierarchy creation
private void montarEstrutura(){

    Unidade ub1 = new Unidade();
    // Setting up parent-child relationships and details
    
    unidadeTreeModel = new UnidadeTreeModel(ub1);
    tree.setModel(unidadeTreeModel);

}

-A summary of the entity (Unidade):

@Entity
@Audited
public class Unidade extends AbstractSuseTools{
    // Definition of fields and methods for Unidade entity
}

And here's the relevant part of the .zul file where the property of the entity is not being read:

// .zul file component setup
<tree id="tree" model="@load(vm.unidadeTreeModel)" selectedItem="@bind(vm.unidadeSelected)" >
    // Tree column and cell definitions
</tree>

The custom UnidadeTreeModel I am using:

// Custom TreeModel implementation for Unidade entity
public class UnidadeTreeModel extends AbstractTreeModel<Unidade> {
    // Detailed implementation for tree functionality
}

The reported error:

The sub-levels of the object are not being displayed even though there are no errors being shown.

I am unsure about how the internal workings of the tree interact with the data, hence unable to debug why it is not readable as expected.

Answer №1

To eliminate this information from your zul file, simply do the following:

<treecell label="@load(each.number)"/>
   <treecell label="@load(each.name)"/>

Answer №2

It's completely normal (since you haven't implemented the toString method).

The issue lies within your model (which was being tested). One thing I suggest changing is this:

public class UnidadeTreeModel extends AbstractTreeModel<Object> {

to

public class UnidadeTreeModel extends AbstractTreeModel<Unidade> {

This change will make it easier for you to handle castings and result in cleaner code. Could you please update the question with the new model code? It will help me review the code more efficiently.

After taking a closer look at your code, I have an issue with this :

public int getIndexOfChild(Object parent, Object child) {
    String data = (String)child;
    int i = data.lastIndexOf('.');
    return Integer.parseInt(data.substring(i + 1));
}

What exactly are you trying to accomplish here? The String data will contain the address (due to lack of a toString method)

Instead, try changing it to:

 public int getIndexOfChild(Unidade parent, Unidade child) {
    for (int i  = 0; i<parent.getUnidades().size();i++) {
        if (child.equals(parent.getUnidades().get(i))) { return i;}
    }
    return -1; //or throw an exception, whichever you prefer.
}

As for the isLeaf method (I'm not sure about the 4th level, but maybe just check with the root?)

public boolean isLeaf(Unidade node) {
    return getRoot().equals(node);    
}

Please update the latest question:

I use this function to expand the tree after clicking a button:

private void doCollapseExpandAll(Component component, boolean expand) {
    if (component instanceof Treeitem) {
        Treeitem treeitem = (Treeitem) component;
        treeitem.setOpen(expand);
    }
    Collection<?> com = component.getChildren();
    if (com != null) {
        for (Iterator<?> iterator = com.iterator(); iterator.hasNext();) {
            doCollapseExpandAll((Component) iterator.next(), expand);

        }
    }
}

public void fullyExpandTree(Component root){
    doCollapseExpandAll(root, true);
}

Now you don't need to go all the way, just count to 4. I trust you can update that code ;).

Regards, chill.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for customizing bootstrap code for registration form to validate against duplicate emails?

The contact_me form utilizes default code to handle success or failure responses from the server. The code calls msend_form.php for communication with the database and always returns true. It allows checking for pre-existing email addresses in the database ...

Why does my JSON parser consume significantly more memory when utilizing the Streaming API?

My current code is parsing the whole file using jsonparse: ConcurrentHashMap<String, ValueClass<V>> space = new ConcurrentHashMap<String, ValueClass<V>> (); Map<String, ValueClass<V>> map = mapper.readValue(new FileRead ...

Before sending an XHR request with Ajax, access can be granted

My goal is to implement a redirect for ajax requests. In the event of a session expiration, my backend currently redirects to the login page instead of sending data. However, I have come across discussions on StackOverflow highlighting that ajax does not h ...

Load the current webpage using Ajax with PHP

I am encountering an issue with my AJAX script and I am looking to dynamically load a page without having to refresh it. Here is the code snippet: index.php <div class="header-page" class="clearfix" role="banner"> <div class="container"& ...

I am seeking to pull out a specific value from a JSON array

{ "data": { "tech-spec": "377.pdf", "additional-details": { "item": [ "Currency:GBP", "Scaleprice:", "Priceunit:" ] }, "currency-code": "GBP" } } I am looking to parse the JSON string above in Java to extract th ...

When using Selenium, the moveToElement method does not properly click on the desired target in Internet Explorer but works correctly

While using Selenium to navigate a menu, I have encountered an issue specifically with IE where the submenu item becomes inaccessible as it ends up clicking on the menu below my target. This method works perfectly in Chrome but not in IE. // Actions not s ...

Could not find an iframe element using the specified xpath

Every time I attempt to run the code below, I encounter an InvalidSelector exception: List<WebElement> allFrames = driver.findElements(By.xpath("//iframe")); org.openqa.selenium.InvalidSelectorException: Unable to find any element using the xpat ...

An IllegalAccessError was encountered when attempting to access a method in the com.google.common.util.concurrent.SimpleTimeLimiter class while using Selenium ChromeDriver with Java

My version of Chrome is currently 75.0.3770.142 and I am incorporating ChromeDriver 75.0.3770.90 into my code with the following pom dependency: <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId> ...

Handle Ajax requests to prevent multiple submissions upon clicking

Seeking a solution to avoid multiple requests when the user clicks on the login or register button. The code provided below is not functioning as expected; it works fine the first time but then returns false. $('#do-login').click(function(e) { ...

Is it possible for DWR to handle method calls using GET requests?

Can DWR handle method calls using the GET method? This would allow me to cache the results of the call using http caching... Is this a feasible option? ...

Transferring a multidimensional array from a controller in CodeIgniter to DataTables using jQuery

Is there a way to pass a multi-dimensional array from the controller into dataTables? While using CodeIgniter and jQuery dataTables, I encountered no issues when working with just a single array. However, when attempting to use a 2D array, the data does n ...

"Error encountered: java.lang.NoClassDefFoundError while attempting to execute a jar file using ant

Reaching out to the Selenium community in case anyone has encountered a similar issue while setting up selenium tests using Ant. I have tried multiple solutions posted on various forums, but I am still unable to resolve my issue. When I compile the code ( ...

Selenium encountered an error: java.lang.IndexOutOfBoundsException due to an invalid index value of 92 being referenced in a list of size 92

Even though this question has been asked multiple times, I have tried several solutions and am now posting for further help. If I missed any solution, please point me in the right direction. Thank you. I'm attempting to navigate to a page, extract al ...

Testing for ajax failure using Q-Unit in a unit test

While utilizing jQuery's $.when method to manage ajax callbacks, I am also implementing mockjax for simulating various responses in my unit tests. One of these responses results in a status error of 500. Unfortunately, when catching this error using Q ...

$.ajax causing a JSON input string malfunction

My web API requires the following JSON format for input: [{ "atrSpaUserId": "47fe8af8-0435-401e-9ac2-1586c8d169fe", "atrSpaClassLegendId": "00D18EECC47E7DF44200011302", "atrSpaCityDistrictId": "144d0d78-c8eb-48a7-9afb-fceddd55622c"}, { "atrSpaUserId": "47 ...

Encountering the GDK_BACKEND error that does not correspond to the displays available on Debian

While attempting to execute a headless browser on a remote Debian server using Selenium, I encountered an issue. The server has Firefox 46.0.1 installed and I am using version 2.53.1 of Selenium. Every time I try to run a specific test, the following erro ...

How to pass a null parameter with jquery's .ajax method

I am facing the following scenario function AddData(title, id) { $.ajax({ type: "POST", url: "topic.aspx/Add", data: JSON.stringify({ "title": title, "id" ...

Unlocking secure content with Ajax

Trying to access a webservice or webpage solely through ajax, as it is the only allowed method for some reason. The webservice is secured with corporate SSO. When requesting webpage X for the first time, you are redirected to login page Y, outside of the a ...

Solving the Challenge of URL Issue in Ajax Call to MVC Controller

I have searched extensively for a solution to my jQuery/MVC problem, but haven't found one that works. Here is the JavaScript code I am using: $.ajax({ type: "POST", url: '@Url.Action("Search","Controller")& ...

What is the most effective method to prevent the auto-complete drop-down from repeating the same value multiple times?

My search form utilizes AJAX to query the database for similar results as the user types, displaying them in a datalist. However, I encountered an issue where it would keep appending matches that had already been found. For example: User types: "d" Datali ...