Jay Tai

Ranch Hand
+ Follow
since Apr 25, 2012
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Jay Tai

Well, here's another context. A dataTable uses a DataModel as its Model façade. It does this because the DataModel can wrap a POJO model, but adds some useful JSF-specific features, much like the TreeNode does for PrimeFaces trees.



So to confirm TreeNode can wrap a POJO model but adds JSF specific features for Primefaces tree?


As far as I know, however, the PrimeFaces doesn't automatically generate TreeNode objects. So if you change the data model, you'd have to manually add/remove TreeNodes and map them to the corresponding added/removed data model objects.



So are you saying that there may be no automatic way (generic method) in PF which directly 'links' the TreeNode to its data model in the same way that say DataModel is linked to a ListDataModel? In that case, TreeNode has to rely on wrapping a POJO model to manually synch the TreeNode with its data model? Doesn't that imply that you could write an automatic way to generate a TreeNode object in the POJO wrapped by the TreeNode?
8 years ago
JSF

I want to correct a common misconception. JPA Models (also known as Persistence Models or Object Models) are NOT the same thing as JSF's GUI Modes



Ok so I can assume a number of generic models for each node element on terms of GUI and data, as well as the generic elements which I override on my own JPA classes and backing bean?

When I said "dynamic"



Right, so I'm already creating the tree on demand from the database, which indicates that PF does support dynamic trees. Both data and GUI models seem to be creating the tree view and firing the expand and select events if all I want is a tree that is renders and changes as database values are changed. I tried changing the DB values and it is successfully updated in the tree. The tricky part is if I want a reliable way to do anything OUTSIDE the tree component like use the selectednode to navigate to another page.

I can even do that in a messy way by searching for the string value of the selectednode and navigating to the page corresponding to that value. So can we agree that PF does seem to support at least a basic level of dynamic tree handling (taking your point about not reinventing the wheel through HTML)?

So, the problem SEEMS to be how I can maintain the connection between the data models and the tree so that the selectednode can be related to the entity ID (itemid) in displaying the detail from the selectednode? If we agree that this is my concrete problem, then is a bind attribute achieve that purpose? If I'm missing in my underlying understanding of the tree and JSF please let me know and thanks again!
8 years ago
JSF

So you can (and should) simplify your thinking by casting it in terms of the simpler Views and Models.



Ok so there are 3 sub views (Market, topic, item) mapping to 3 models? If i'm not mistaken, the sub views are the node branches and children. But i'm confused about what the model is. A model represents the data and nothing else, meaning it doesn't depend on the controller or the view. In my case, the JPA persistence class is used to populate a list which populates the treeNode in the managed bean. The MVC paradigm suggests the model should be the JPA class. There are 3 classes for each of the node views. The model for the market entity is:



If this is the model, then I am already using it to dynamically populate the tree from the database. Correct?

If I'm not mistaken, the tree's "selection" attribute will indicate which node was actually initiating the event



Correct and the console message confirms that the selected node correctly returns a String representation

If PrimeFaces doesn't have direct support for anything more dynamic, you can do it the hard way, which is to add a "binding=" attribute to the p:tree element and construct TreeNodes in Java code when the AJAX listeners fire.



By 'more dynamic' do you mean a method which integrates the tree back to the data model? The way I see it, i'm already pulling values from the database dynamically. The problem is that I'm using a list to create the tree. Once the tree is created it loses connection to the data model. I'm guessing the binding attribute would tie the tree directly to the data model so the entity values could be accessed by the TreeNode? Finally, if I'm creating trees manually and customizing the datamodel, doesn't the use of PF become e more redundant? Would it then be much harder to use a plain java tree and plain html?
8 years ago
JSF

But consider a common case where you have a 3-level menu tree of Country, State/Province, City.



Well your advice about leaves helped me figure out how to implement my example (which is actually similar to a common case - 2 branches and a eaf):



This is a messy way of doing it. It works as long as there are no duplicate item names, which is why I'd prefer to search for the item Id in the database. Any idea how I can do that?
8 years ago
JSF
That's very helpful to know but how does that work? Returning the nodes as hyperlinks would make all of the nodes as hyperlinks right? How would you distinguish between child and parent nodes so that only child nodes are clickable?

Are you using a Java function to do that? Are you extending the Ajax method?
Do you create a data model and integrate that in the tree constructor?

8 years ago
JSF
I figured out how to do the navigation through ajax:







This navigates regardless of whichever part of the tree is clicked so i'm still trying to figure out how to only fire the navigation if the final child node is selected. I now need to figure out how to fire the event ONLY IF the final child node is selected (and return null otherwise). This probably a conditional statement that invokes the method if the selectednode equals the child node. Looking again at the API and online doesn't give many clues...

I tried:


No Luck!
8 years ago
JSF
I'm sorry but you made me look at it too. After trying to learn retrospective English I decided to ignore most of it and go back to basics. No ajax, just good ole Java. I looked at the static example and simply tried to replace the key static fields with dynamic ones:



So that works fine and I'm able to navigate through a tree. What I now need to do is create an action using a commandLink which invokes a getRowData method ONLY when the user clicks the final child node (items) which takes the user to another page to read the selected item. As a reminder the jsf is:



This is a problem because it doesn't distinguish which part of the tree is clicked so a normal getRowData will result in a NoRowAvailable Exception if anything other than the final child node is clicked. I'm thinking I need to use an ajax onClick event handler here but I'm really not sure.

So my best guess would be that you'd attach a "click" AJAX event to nodes and have the event handler check the clicked node to see if its child list had been populated, and if not (or if stale), then populate it



Assuming I use an Ajax click method. Checking if the child node is populated makes sense, but are you saying that the Ajax will be able to process actual rows clicked thereby allow navigation based on the selected child node value?

I tried this:






This doesn't even navigate to any page no matter which node I click??
8 years ago
JSF
So I'm trying to get my teeth stuck in by adapting a generic PF tree method to be built dynamically from the database. The reason I keep mentioning Lists is because I've seen examples using Lists but mostly because I want to know how I would be able to use methods like getRowData to invoke actions from the dynamic tree model if I'm not going to use underlying lists in the data model?
8 years ago
JSF
Hope you're well and thanks for a typically insightful response :) in 'not too sarcastic English' ... great to know trees are so complicated. Easy to take for granted how easy it should be to have a list that simply expands and contracts based on user choice.

Tree controls require something similar, but more complex



My research suggests that 'something similar' could be recursive methods in the POJO which take care of the user functions (click, expand, etc). Before I set about trying to wrote such a method, is it recommended to use a List to populate the tree in this method or should the tree be populated directly from the database?

8 years ago
JSF
I have 3 entities in my JSF application - markets, topics, items which have parent child relationships to each other. I need to display a list in a tree like format so that clicking markets displays the related topic list to each market, clicking topic shows the item list related to each topic. I'm using Primefaces as my web interface so I figured the PF tree component is the right way to go. I looked at the official PF documentation. This only gives static examples and I don't understand how to create a tree dynamically from a database.

My jsf:



The backing bean:




The exception:


The facade for the child node (topics):


So I have a general question about trees and a specific one about how I'm going about this.

Is the above the correct approach where I'm grabbing the tree values using ArrayList objects from the parent and child entities to dynamically create the tree object and its nodes?

Specific to the above exception, the stack overflow error suggests that the application is going into an infinite loop. At the same time the exception shows UNKNOWN SOURCE next to the marketTopNorm (the child node list)? if it's an unknown source why is it being processed? Why does it not give a NullPointerException for example?

Thanks in advance!
8 years ago
JSF
Thanks for a typically insightful answer. Bear with my long response. The infrastructure is going to be my first port of call. In light of what you said, I also want to DO SOME JSF 'soul searching' and figure out if there's non infrastructure which flaws which can be non-violently fixed by JSF or outside JSF. First let me understand something about the limitations of JSF.

I've heard no end of horror stories about this. I've ended up with a virtually end to end enterprise application which I wrote almost purely in JSF with the usual compliments of POJOs, JPA and PF. The application covers security, document management, project management, stats management functionality and then some. Much of the insights for doing it gained from this forum, sleepless nights but minimal JSF violence. The application appears to work quite well for 30+ users SO FAR. Alongside the horrifying tales, including Gosling himself professing his passionate hate for JSF, I've been surprised at the framework's flexibility and reach. Maybe I've done something fundamentally wrong by relying so heavily on it? Or, maybe JSF isn't so bad after all. As I understand it, JSF simply promises the ability to interact fairly efficiently with POJOs and/or servlets. So, doesn't that mean flexibility is the core of JSF's design logic? I'm also aware of the JSF / Spring compatibility but in all honesty I've given in to development deadlines using what I know and simply haven't put in the time to learn enough about Spring YET!

So, I'm agreeing with your recommendation to look in the architecture first, but simply asking at this point if you agree that JSF has become quite a robust framework for good range of needs. Finally, coming back to your discussion about:

I had a little discussion the other day on this forum about JSF2.2 and how JSF seems to be turning from a "do 1 thing and do it well" framework to a "do HTTP no matter what sort of violence it involves".


Could you give an example of the 1 thing JSF does well and how everything else fits around that? Thank you!
9 years ago
JSF
I'm using Primefaces in a JSF application to upload and download files. This is fine for small files but becomes slow for larger files, even to the point that donwloaded files end up corrupted. My guess is that this is caused by network interruptions due to excessively long download times.
The network being used is broadband and the download speeds are similarly slow accross different types of networks.

My most immediate need is to speed up document downloads if that's possible so i"ll use the download methods as my example.


The jsf:




The backing bean method:


My questions are:

1) Can modifying my methods better optimize download speed? For instance, should I be thinking about using multithreading (even though I've read about the hazards of manually creating multiple threads)?
2) Is JSF and PF a sensible combination to use for these types of function?
3) Any other suggestions for how to optimize the speed in terms of what I'm trying to achieve?

Many thanks in advance!
9 years ago
JSF
I'm developing a filing system where I have 3 tables. PROJECTS table consists of projectid, project name and other details (see below). This is an existing class and populated schema and I do not want to modify this part of the application if possible.

Folders table (Called ProjectClassification) consists of folderid and foldername and is the owning side of a unidirectional onetomany relationship.

Project_Folders is a join table. I'm using JPA 2.0 (EclipseLink) and JSF 2.0 as my web framework.

My basic problem is I can't add duplicate records to the join table using a merge operation. MERGE is good for adding records until the owning key already exists, after which point it will only update the join table. I know this is the way it's supposed to work but I need to add new records even if there's a duplicate of the owning key. This will allow me to store different projects in the same folder.

The folder entity class:


The Project entity class is a pre existing code and I do not want to modify at all if possible:

I then use two html select lists to select values for projectid and proclassid which call the following methoid using a JSF managed bean:

My questions are:

1) Is MERGE the correct operation used to add records into a join table?

2) Is there a way to add records that contain duplicate keys (foreign keys represented as new records in the join table) using MERGE?

3) Should PERSIST be used to achieve question 2?

4) Would it be better to create an entity for the join table itself and simply use a PERSIST method to insert the records

Many thanks
So basically I just used the ProjectDocs class instead of classification for the entire application and was successfully able to display the folder and select appropriate documents from that list. This was largely thanks to your explanation and my understanding of the real role of the wrapper class.
9 years ago
JSF