Categories
Community Java Learning XPages XPages

Discussion on using PageControllers in XPages

WARNING:  This is a long one.  Enter if you dare.  

In the XPages Slack chat, which is free for anyone to join, hint hint.  Whenever I see people working together to solve an interesting problem I always try and suggest that someone blog it so the content and solution they’ve worked though gets a bigger audience. I’ll publish it myself if the person doesn’t have a blog. I don’t think I’m always successful but I try.  Anyway today is my turn to try and lead by example. I was typing up a long response to an email and thought – F this… I’ll just blog this for everyone.

Below is an email I got from a NotesIn9 Viewer (and friend) who is having some questions related to episode 182.  In that episode I tried to just do a quick take on how to do CRUD (Create, Read, Update, Delete) operations using Java and XPages.  I think one of the points of confusion was that I was more focused on the Java bits, and didn’t do a great job at hooking into the actual pageController for the “Project” XPage.  I didn’t want to use Jesse Gallagher’s awesome Frostillicus framework and have that dependency.  I ended up using a manual managed bean when I should have used Object Data Source.  I simply never thought of using Object Data for a page controller until I think it was Paul Withers that mentioned it in the Slack Chat.  doh!

Anyway here’s the last email he sent in this thread…

I never did figure out why faces-config was empty whenever I created a new database, but since I’m able to manually create the XML file, I got over it.

I must admit to being confused about how you did the data sources for NotesIn9-182. I see from what you wrote above that I can handle this by either importing Jesse’s framework or by using Object Data. But you indirectly also said that’s not how you did it for NotesIn9-182.

I’m looking at the Project XPage. The XPage doesn’t have a Data Source but computedField1 gets its value via Simple data binding with Data source set to “ProjectControl” and Bind to set to “currentProject.unique.

So how DID you set the value for computedField1? I guess it really doesn’t matter since I need to either use Jesse’s or Object Data, but this does make me curious.

And it turns out that creation order of the design elements seems to matter some, but in a Captain Obvious kind of way. For example, controller.project.java requires both controller.base.java and com.notesin9.tracker.Project and com.notesin9.tracker.Task. to be created first (at least in part) because controller.project uses all of them.

So if in the project page, I want to display the name of the person who created the project.

  • The name of the project creator is the property “creator” of the class “Project”
  • “Project” is imported by the class “project”.
  • “currentProject” is an object declared in the class “project”.
  • In faces-config or in Object Data, methods and properties in the object “project” are referenced by the Data Source name “ProjectControl”.
  • So the value of the computed field that displays the creator used ProjectControl as the data source from which currentProject.creator is retrieved.
  • Wow. As dumbed down as this is, this is still a lot.

Time for me to File.Application.New and reduce it to its bare essentials.

Thanks again for your help.

And my response is :

I think I’ve seen the blank faces-config thing before..  not sure…  I just now created a new database and went in and all it gave me was :

<?xml version="1.0" encoding="UTF-8"?>
<faces-config/>

Is that what you’re seeing? or is it totally blank?

It used to be more like this by default

<faces-config>
  <!--AUTOGEN-START-BUILDER: Automatically generated by IBM Domino Designer. Do not modify.-->
  <!--AUTOGEN-END-BUILDER: End of automatically generated section-->
</faces-config>

And then you’d add beans like this :

<faces-config>
  <managed-bean>
    <managed-bean-name>ProjectControl</managed-bean-name>
    <managed-bean-class>controller.project</managed-bean-class>
    <managed-bean-scope>view</managed-bean-scope>
  </managed-bean>
  <!--AUTOGEN-START-BUILDER: Automatically generated by IBM Domino Designer. Do not modify.-->
  <!--AUTOGEN-END-BUILDER: End of automatically generated section-->
</faces-config>

interesting…

I might not have full understood the last email.  The order does matter when it comes to Java.  The order of elements for the other stuff doesn’t really matter.  I could link an xpage to a page controller that didn’t yet exist if needed.  The XPage wouldn’t care because it doesn’t know about it from designer itself.

Ok… regarding the Project Page….

for every XPage these days I want to have a Java class acting as a “pageController”.  This lets me put almost all my logic in a nicely coded class and gets it off the XML of the XPage and all that “CDATA” crap.  There are just a lot of benefits to this approach.

In that show I choose to make a viewScoped managed bean in the faces config.  I did this because 1. I didn’t want the frostillicus dependency and 2. Stupidly I didn’t think of using object data.  Object data would have been better to use for the controller.

Because it’s a managed bean… there doesn’t need to be anything defined in the xpage dataSource… That’s what a managed bean is… you define it at faces-config and now it’s available anywhere in the application whenever you call it.  The XPages runtime will create it automatically – which is why managed beans require an empty constructor.  It’s not a bad thing to have managed beans…  and a great example of needing a managed bean might be for a shopping cart object… something that lives in sessionScope… so it has the longer life..  though technically a you could also manually put a cart object in sessionScope from a page Controller..  retrieve it when you want and get the same results…  like everything there’s multiple ways to arrive at the same destination.

So how did computedField1 get it’s value?   Let’s look.  

Here’s what it looks like in the main “pretty pane” : 

figure1

The dataSource is the managed bean.  Which holds a custom object called “currentProject”.  Which has a method to get the unique value.

So this screenshot translates to : 

ProjectControl.getCurrentProject().getUnique().

And that would work if using SSJS.

But you can’t type “ProjectControl” into the dropdown.  That’s annoying and I’ve mentioned that to IBM recently in fact.  So you need to go to the Advanced Tab and choose Expression Language (EL) and just type it in there :

figure2

And in the source it will then render as this : 

<xp:text escape="true" id="computedField1"
value="#{ProjectControl.currentProject.unique}" styleClass="form-control">
</xp:text>

Just a side note – since this value doesn’t change I probably should have set it to Compute on page Load….

Anyway….

Now regarding your bullet lists….

First remember what’s going on here…  We’re trying to get to at least some form of “MVC” which is “Model”, “View”, and “Controller”…  And honestly I don’t know all the technical purist definitions of this so here’s how I like to think of it when I work.

VIEW: The XPage is to display information to the user.  I guess this is the “View” but I’m not sure.  It’s responsible the UI and everything you display.  BUT ideally it’s NOT responsible for anything that requires “logic”. No heavy lifting. And it doesn’t talk directly to the data itself.  No binding to documents or views. (Of course there might be exceptions)  All that belongs in the “Controller”.  So ideally the XPage only talks to the Controller.

CONTROLLER: The controller is just a java class to hold any logic that the XPage needs and is also the gatekeeper between the xpage and the actual data. Any logic to show or hide content belongs here.  All this controller really is, at it’s core, is a viewScoped bean that’s specific to the XPage.  This bean could be created manually by adding it to faces-config – like I did in show 182.  But that probably isn’t the best way as you don’t want to make a faces-config entry for each bean if you have a ton of pages.  So as an alternative you can use Jesse Gallagher’s frostillicus framework – which is lovely – or on the page you can use the Object Data to create the controller Object right on the page.

<xp:this.data>
<xe:objectData var="controller"
createObject="#{javascript:return new controller.demos();}"></xe:objectData>
</xp:this.data>

So in that instance if I have a java class called “controller.demos” the Object data code will create the object and give it a variable called “controller” and I can now reference it anywhere on the page.  The variable can be anything of course.  Again, all this really seems to be, is a viewScoped managed bean.  By default, this object lives during the life of the page it’s created on.

MODEL: The Model, is the means to actually get to the data itself.  In the JavaCrud app from show 182 I had a java class for “Project” and “Task”.  These classes represent notes documents.  These objects get loaded into the pageController as needed.  Now I admit it seems confusing to have all these similar names.  “project.xsp” for the XPage.  “controller.project” for the page controller and “com.notesIn9.tracker.Project” for the model object.  yuck!  I don’t know a better way really.  There’s a little more flexibility using Object Data but Jesse’s framework requires the pageController to be the exact same name as the XPage itself.  Note that I always try to use lowercase for the controllers and Uppercase for the Model objects.

So why do all this?  as you say “Wow. As dumbed down as this is, this is still a lot.”  And you’re right. It is. But it’s so much better in the long run – though I’ll leave that discussion for a future post or show.  This is long enough now. haha

Hopefully that helps clear things up.  If not let me know.

Dave

 

Categories
Community

What’s your Christmas Movie Play List?

At this time of year we look forward to watching our “standard” selection of Christmas movies.  Here’s our top holiday movies.

#1 has to be Christmas Vacation.  Good fun for all the family.  We’ll usually start the season with this movie and watch it again on or near Christmas Eve.  Just a great movie. Much better then the original Vacation movie.

#2 is probably the best Christmas movie ever in my opinion.  Unfortunately it’s Adults only, but Love Actually is just a wonderful movie. It’s my wife’s favorite movie of all time.  If it didn’t have the adult only parts it would be #1 on the list.

#3 is pure family movie.  It’s pretty rare so you might not know it.  “A Muppet Family Christmas“. This is just a wonderful family movie. If you like the muppets you need to see this.  Sadly this year I somehow misplaced it..  I can’t find my ripped version or the DVD version which I originally got from a cereal box of all places.  But It looks like it’s on YouTube so I highly recommend checking it out.

#4 is Scrooged.  Bill Murray at his best.

#5 of course is Charlie Brown Christmas.

Those are our top 5.  What’s yours?

 

 

Categories
Community

It’s back! Come and play the Tree on a Truck Game!!

It’s the time of year again. Every year my family plays a simple game to get into the holiday spirit.  It’s competitive and borderline cut-throat at times but at the core it’s simple.  We count the number of Christmas Trees that we see on cars and trucks.  By count I mean the first one who sees it and calls it gets a point.  And by calls it I mean the first person who shouts “TREE!” get’s that tree as a point.  It’s actually loads of fun while still stressful haha.

So if you’re interested in playing along sign up and give it a go!

TreeOnATruck.com

P.S. The app is pretty basic and a work in progress – but that’s for a future blog post!

Categories
Community

Community Shoutout – Timothy Briley

 

Just a big Happy Birthday to Tim who, unfortunately is a long way from home this week.

Safe travels home buddy!

 

 

Categories
Community Notes In 9 Uncategorized XPages

XPages.TV is dead. XPages.TV is born again.

For years I’ve known that my XPages.TV site sucked. For years you knew that also. Well finally I’m starting to do something about it.

XPages.TV was meant to be an on line catalog of all the NotesIn9 shows. Since the shows have a longer shelf life then a typical blog/podcast I wanted some way to get to them easier. And I didn’t know a way to do something clever in wordpress itself. So I wrote a little template to try and do some clever things and it was a total failure. So tonight I’ve killed that.

XPages.TV is currently showing the raw data of the NotesIn9 shows. Big thanks to Tim Briley for helping me gather the data. It’s barebones and ugly, but already should be doing a better job then my last attempt.

So if you’re looking for a particular NotesIn9 show, check out XPages.TV for the complete list and you can open links to get to the Youtube video or even the blog post.

Categories
Community XPages

Announcing the XPages Development chat on Slack

If you’ve never heard of Slack, it’s basically a “messaging app for Teams”.  You can access it via the web, desktop application or mobile app. Slack is a persistent chat experience with really good software behind it.  It allows for different “channels” inside the room so we currently have “general”, “beginner”, “advanced” and “random” discussion area.

I little while ago Jesse Gallagher and I setup an XPages Development chat on Slack.  We’ve been playing with it and would now like to make this available to the public.

The goal of the chat is to be a place where people can come together and talk XPages. There’s no good public place to really do this that I know of.  The XPages Forum is a disappointment.  Stack OverFlow wants specific questions and abhors actual “discussions”, and you can’t really start a discussion on someones blog.

So where do you go to just discuss an idea, ask a generic question or even just say hi to like minded individuals? We give you:

XPages.slack.com

Because this is an open invite we do have some rules that are needed to maintain decorum.  Those rules are at the bottom of the post.

How do you join?  Unfortunately email addresses have to be “approved” currently.  There are ways around this but we’ve not really looked into it yet.  So for now just send me an email and I will add you to the group as I FIND THE TIME.  So don’t expect instant access.  🙂

UPDATE: Thanks to Declan Lynch you can now auto join. Please use this link :

http://xpages-slack-invites.herokuapp.com/

Thanks!

Dave

=====

XPages Slack Chat Rules

1. No Bitching at all. We are about Doing.

2. Stay close to the XPages topic.  Off topic is allowed in #random. Bitching is never allowed.

3. All content discussed in the chat should be considered public. Do not share code or ideas that you consider private. Do not discuss NDA material.

This is a community chat of XPages enthusiasts and NOT a support group. While questions may be asked do not expect a solution.  If you get one great.  If not then realize that everyone is busy with their day jobs.

The recommended way to ask a question is to post it on StackOverFlow and then post a link to the question in the chat.

Categories
Community XPages

Ask the XPages Experts Webinar Next Week!

Next week, on Tuesday November 17th from 10:30 AM EST to 12:00 PM EST TLCC and Teamstudio will be hosting an XPages webinar called “Ask the Experts”. For FREE!!!!

I’ll be joining the panel with  3 true experts in the form of Mike McGarel, Jesse Gallagher and Nathan T. Freeman.

We’ll each be bringing a SHORT 5-10 minute XPages topic.  The rest of the time will be dedicated to any question you might have.

So please, if you’re working with XPages.  Come join us next week.  Watch the short demos.  Say Hi. Ask any question you want.  We’re all happy to try and help out.

http://www.tlcc.com/xpages-webinar

Categories
Community

WordPress resolution…

So last week I came to realize my site was hacked.  Not being an expert at WordPress and with a lot going on in work and home life I was a little, shall we say, “distraught” at the prospect of dealing with this.

But luckily I follow my own advice.  You see I’ve been preaching for a long time the benefits of “Joining the community”.  That the benefits of sharing information will give you back rewards ten fold.  I could certainly do better in my own sharing but I’ve still managed to shared a bunch over the years.

What have I gotten back from all that sharing? Let’s see, knowledge, experience, speaking opportunities, a dream job and oh yes….  FRIENDS!

I had several friends help me with getting my site back in order.  A huge thank you to Bruce Elgort, Eric McCormick, Declan Lynch and Marky Roden for technical and even “venting support”.

I ended up adding some plugins to the installation:

iThemes Security

Sucuri Security

Word fence

 

One of them told me the problem files, which I deleted.  I then in place re-installed wordpress.  Then I used the plugins to try and better “harden” the site.

Hopefully that’s the end of that.

P.S.

If you want to get off the bench and start sharing – let me know and I’ll help you.  If you want a no cost blog that looks pretty cool check out this article from Eric:

The right tool for the right job.

 

 

Categories
Community

IBM Champion thoughts – How to thank someone

It’s that time year again where you can nominate someone to be an IBM Champion. I’ve talked about this before on the blog.

You can find out about the program here. And you can go to this page to nominate someone.

Note: The nomination form is a little “daunting” to say the least. Just fill in what you know. You don’t need to fill in everything.

You’re supposed to nominate people based on their contributions for the last 12 months, NOT their “life time” contributions. For this and other reasons I always try to first nominate someone that has never been an IBM Champion. We have such a great community that there always seems to be new blood showing up and every group needs new people.

This year I’ve identified 2 people that, to me, have done some significant contributions over the last year. I believe that both, like me, are simply customers. That’s cool to me. They are:
@szavocki
Steve Zavocki – USA – @szavockihttp://notesspeak.blogspot.com
Johnny Oldenburger – Netherlands – @JOldenburgerhttp://xpagesandmore.blogspot.com

I’m not going to go into why I think they deserve their nominations as I think that’s up to you to decide on your own. I’ll just say that I’ve enjoyed their efforts and want to thank them for their time.

If you’ve benefitted from any community contribution in the last year, please consider nominating that person to be an IBM Champion.

Thanks

P.S. I don’t broadcast it much but I’m currently an IBM Champion as well. I was honored with that when the initial group was announced at conference in Las Vegas. So I’ve had a good run. I’m NOT here asking you to nominate me. NotesIn9 will continue regardless. Please first nominate a few other people before you even consider nominating me.

Categories
Community

MWLug Wrap up and NotesIn9

I just got back from a GREAT MWLug conference in Atlanta. I’ve been to several MWLug’s and they just keep getting better. It was an amazing conference full of friends, fun, food, drink and information.  I learned a lot from the many sessions and came home with ideas of things I definitely want to try. This conference had so many great sessions I had to make some very painful decisions on which ones I attended.  I think they’re going to have to start doing repeats soon if this keeps up.

Regarding NotesIn9, I was just blown away this year.  Of course it was great to see all my friends and co-conspirators.  🙂  But this year I met just a TON of new people which was awesome.  Some I’ve only ever talked to via the email / internet, and some were just brand new all together.  Simply brilliant!  I think more people came up to me this year to talk about NotesIn9 then the last three conferences that I’ve been to combined.  It was great to get feedback and hear that the show has been of value to so many people.

I’ve been taking a break from live speaking lately and this was the first time in a while I regretted not attempting to speak myself.  Not that I would have made it with this bunch of speakers but would have been fun to try.

I was also very excited to see many of the speakers were previous NotesIn9 contributors.  That’s always fun for me to see people from the show speak live.

The other big benefit I get from conferences is  just the feeling of clarity.  It’s great to get away for a couple days and think. It feels like it reboots my brain and I come back refreshed and ready to get back to it.

So what about NotesIn9? I’ve certainly been slacking in that department for a while. I think it’s time to reboot that as well. No big announcements or promises.  I’d much rather do then talk about doing.  🙂

I want to give big thanks to all the organizers and sponsors of MWLug.  It’s a super event and I’m already looking forward to that next year in Austin, Texas!