FORUM PLAN UPDATE
Date revision: This forum will remain open to new posts and responses until December 1, 2018. (After that date, you will still be able to view and search the forum.) Also, we're taking a second look at the best place to host future conversation. For now, keep using this forum, and stay tuned for more news.



Jun 8, 2016, 5:07 AM
45 Posts
topic has been resolvedResolved

Java Objects and Datagrid

  • Category: Managed Beans in NSF
  • Platform: All
  • Release: 9.0.1
  • Role: Developer
  • Tags:
  • Replies: 5

Hi

I am now developing almost all of my applications using Java objects. Typically I will display a 'view' of data using an ArrayList of objects derived from the underlying documents in a Repeat Control. I will then select an individual row to get that object for display and CRUD operations in a local form or dialog. Pretty standard stuff I think these days.

Due to their flexibility I use Repeat Controls extensively, however, I have an instance where I really need the functionality of a Notes View, ie scrolling up and down rows, sorting on any column etc. - nothing can touch the Notes View in my opinion, however,  I think the closest would be the dojo Datagrid. I am really struggling with the basic concept of how to get my Java ArrayList of objects into the Datagrid, how I can carry out CRUD operations for all data in the objects, ie. not just that on display, - ie.  I need to pop up a dialog with numerous fields from the object.

I am aware of several resources focusing on the Datagrid, but I cannot seem to determine if it is possible to implement the control using Java as outlined above or whether I need to abandon Java and go back to Views and Documents in this instance. I am aware of several resources on-line but know little of REST services or JSON etc. I have no problem going up the learning curve, but just needed to know I am not barking up the wrong tree before I spend days tearing my hair out!

Any advice on how to achieve my goal would be greatly appreciated.

Jun 13, 2016, 4:35 PM
589 Posts
hmmm

If you want to use any of the grid stuff the best way to feed them is with json I think.  Create an XAgent or servlet to feed the data back.  so you get your arraylist... then convert it all to json output...  the REST/JSON is the best path in my opinion.

You can get some sorting in by using comparators in your java objects...  probably wouldn't scale to like 20,000 documents... but if you're working with a couple hundred or so should work fine I'd think.

there are times when the view does make sense... and if you can feed it from a view... and you're doing a dialogbox... then you could load your java object from the viewEntry or key at that time...

Just my quick 2 cents.  But I think it's great that you're doing more with Java.  That really is the best way to go.

 

Dave

NotesIn9

 

Jun 13, 2016, 5:20 PM
45 Posts
Java Objects and Datagrid

Hi Dave,

I do only have a few hundred documents and I have radio buttons to load/filter the required object types in my ArrayList so I will attempt to go down the REST/JSON path and hopefully the pain won't be too great.

Many thanks for your help.

Jun 14, 2016, 8:07 AM
589 Posts
well...

Mark,

If that's all you're dealing with for document count I probably wouldn't go the REST / Grid route...  Arguable that's probably better in the long run for scalability but for a few hundred I'd personally stick with a repeat control most likely...

I'd try something like this...

You already have your java object right?  So that's done.  That represents the individual object.

I'd have a page controller....  so a java class for all the logic on your page... inside there would be an Arraylist<MyObject>...  the repeat control calls the pageController to get that arraylist of your objects...   

So now it's just a matter of different sorts of you're object right?  By different "columns"...  or in this case different properties of your java object right?

So inside your java class you can add as many Comparators as you want.  Java has Comparable and Comparator and I often confuse them. But as best as I can explain it a Comparator is like having a method in the object, techinically an inner class I think, that lets you determine what the sort order will be when you do a Collections.sort() or use a TreeSet of something like that.  Very handy.

http://www.mkyong.com/java/java-object-sorting-example-comparable-and-comparator/

That's a great article on the subject.

So if you did that... then you'd just need to make your column header clickable...  update the pageController so it knows what type of sort to use... and then refresh your repeat control... 

 

Something like that should work if I'm understanding the issue correctly.  Again REST/Grid is a GREAT skill to have in the long run too...  but so is the ability to sort your java objects directly.

 

Just my little thoughts....

 

 

 

Jun 14, 2016, 3:26 PM
45 Posts
Java Objects and Datagrid...

Hi Dave,

I have a View of around 1000 items in total, each item in the view represent one of several  types of product (WiFi Controller, Router, Telephone System Controller etc) for which we need to record data, such as Serial Number, IP Address, Connection Detail etc. So I generate an ArrayList of items filtered by  'product type' using radio buttons and then display the list of objects on a page which contains an Extension Library Dynamic Content Panel with a repeat control inside. Click on a row to pop up a Dialog Box to populate the necessary fields. It seems to work very well.

Having spent some time over the past few evenings trying to get my head round CustomRestService I have decided it is a bridge too far for me at this stage.  I do have a Comparable, which just gives objects in one order, I was just about to start researching into what you have above, so your timing is could not have been better and your advice as always is spot on.

Thank you for your time and for putting me on the right path.

Jun 15, 2016, 9:48 AM
589 Posts
hmmm

Sounds like you're where I was not that long ago...

Something to think about...

I have an object called "Item".  Which is similar to what you have... these products...  now my name "Item" sucks..  don't EVER name a class that...  sadly I'm married to it for now.  :)

anyway...  In addition to "Item" I have another object called "ItemGroup"...  this is able to hold a collection of items if need be.  So rather then using a pure ArrayList I made this class for additional features...  Inside the class might be something like : 

Map<String, Set<Item>>    // I forget... I'm not actually looking at the code...

so when I add an item to this object...  It get's "filtered" into a Set that goes into a Map...  the String for you might be "Telephone"...  So then I can easily do something like

 

return myItemGroup.getArrayList("Telephone")

 

And now I can easily send all the Telephones to a repeat or whatever..  Now possibly you don't need to store everything in the object like I do...  you could build Static methods to do this...  convert them to your custom java object and return them on the fly...  to me storing them is a little better and gives me some basic caching...  but can be problematic somethings also...

Also the key "String" should really be an enum most likely... but that's another story.

 

Yeah the REST stuff does have a learning curve...  I've only don't a little bit myself yet...  it's high on my list...  huge skill to master really.  very important... but like it sounds like you're doing..  i stick more with the java objects to keep the process moving.

 

If you need anything don't be afraid to email me or even come and join the XPages Slack chat - xpages-slack.herokuapp.com - where other xpagers hang out.  

 

Dave

NotesIn9


FORUM PLAN UPDATE
Date revision: This forum will remain open to new posts and responses until December 1, 2018. (After that date, you will still be able to view and search the forum.) Also, we're taking a second look at the best place to host future conversation. For now, keep using this forum, and stay tuned for more news.