« XPages in Pictures - 03 - First XPage | Main| XPages in Pictures - 05 - Adding a Company View »

XPages in Pictures - 04 - Saving an XPage and Misc.

Category XPages
This is my 4th posting in the “XPages in Pictures” series.  This one is a little on the long side.  In this episode we’re going to create a Home page for the application, add a button to create and save a new company, and even go off on a small tangent to discuss creating a unique number.

Creating a Home Page

First, we want to make a new XPage that will act as a main or “home page”.  This new page will hold a button that will allow us to create new companies as well as how a view that will display a list of any companies that we’ve created.

Create a new XPage called “xMain”.

Unlike what you did with the company page, you’re NOT going to bind the page to any data.  There won’t be any direct fields on this page, at least for now.  All this page will have is a “New Company” button and a View Container Control.  The View Container Control will get bound to view data in order to show the list of Companies.    

First, drag a button from the Core Controls section to the page. Under the Button Properties, change the label to be “New Company”.

Now, go to the Events tab for the button.  There are all sorts of Events available.  For each event we have the option of adding JavaScript Code or selecting one of the many Simple Actions.   Don’t discount the Simple Actions!  Since the properties of Simple Actions can be computed these actions can be very handy.

To create a New Company, you want to add a “Simple Action” that will allow you to create a new company document.  Technically it will open the XPage “xCompany” as a New Document. Click “Add Action”. Change the “name of the page to open” to be “xCompany” and the Target document to be “New Document.”



A picture named M2

 
Test this in your browser.  You should now have a method of creating new companies.  Good work!!!

You might notice that the field “unique” has no value.  Ideally we’d like a unique key in this field.  Also, you probably want a way to SAVE the company document.  Lets look at those two issues now.

Close the xMain page and go back to the xCompany Page.  First let’s create a button to save a new company document.

Saving the Company Document

Drag a button onto your page.  I’ve placed mine underneath the table.  Change the label for the button to be “Save”.  Go to the Events tab.  Add a simple action.  The Category should be Basic and the Action should be Save Data Sources.  For the name of the page to open next, select “xMain”.
A picture named M3

Now you can create a company, save it, and send the user back to the main page.  Now we’re starting to cook with Gas as they say!

Unique Numbers

But what about the Unique field? In the original Notes form, we set it to “computed when composed” with the formula @unique.  This implies that we want to have a unique, unchanging number for future functionality.  Typically the result looks something like this: DLEY-7R4HNY

I’ve found 2 ways to get a unique value in Xpages.  The first is to use the built-in Javascript translation of @unique.  The syntax is @Unique().  To do this, click on the edit box control for “unique”.  Then in the Data Properties, click the little diamond next to Default Value.

A picture named M4


Select Compute Value to get to the script editor.  Enter your formula into the code window.  You can also use the Dropdown under libraries to switch to @Functions to see other @Functions that are available. We’ll be using some of these later.
A picture named M5


Now if you save this page and preview it in your web browser you’re going to get a unique value.  I think!

A picture named M6

What is this value?  I have NO idea.  I’m not sure why it’s not using the format of the traditional @Unique.  I’m not even sure if it can be considered “Unique”.

Ok, so we either don’t like this format or don’t trust it yet.  Let’s populate this field with the normal looking @Unique value.

First, remove the formula for the default value of the unique field.  We won’t be using it after all.

Since we have the formula we want on the Traditional Notes Form.  We can use it by telling the XPage to “computeWithForm”.  

First click somewhere on the XPage itself.  We do not want the focus to be on a control or label.   Then go to the Properties and All Properties section.  You’re looking for data.  Underneath data is another data, and then you should see a dominoDocument.  dominoDocument contains a computeWithForm property.  Click next to it and choose “onload”.  

A picture named M7

This will compute the fields of the XPage against the computed formulas that are embedded in the form.  This is a method of keeping some business logic in the form itself if you’d like.

Save your form and try creating a company.

You should see the normal format for @unique.

A picture named M8

But this field is editble.  Not what you would want for this kind of field.  

Click on the field “unique” and find the properties for Edit Box.  Put a check next to Read-Only to prevent this from being edited.

Well done!  We’re finished working with the Company XPage for the time being.  

I don’t really know if we’re going to need this unique number in the future, but I wanted to have it for the demonstration.

Auto Launching an XPage

Let’s flesh out the application a little more.  We want to set the xMain page to Auto Launch when a user opens up the database on the web.

Click on “Application Properties” in your database.  Remember these are double clicks!

A picture named M9

The second tab is called “Launch”.  In the section for Web Browser Launch, set it to “Open Designated Launch Page” and set the XPage to be “xMain”. Make sure you save the changes.

A picture named M10



Congratulations.  You now have the start of a little application that’s all XPages.  Opening this database in a browser should give you a page with a new company button.  Clicking this button allows you to create a company document.  A uneditable unique number will be automatically assigned and you can fill in the name and address fields and save the company.  By clicking Save you are returned to the main page.  In the next article we’ll create a view on the Main page to display the companies.

Comments

Gravatar Image1 - Tim Tripcony has a great post on using @Unique in XPages. Look for it here:
{ Link }

Gravatar Image2 - David,
Just found this as I was trying to do something in xpages, thanks for posting it.

Gravatar Image3 - Looking for Xpages...just found this...

Gravatar Image4 - Thanks for a nice post you have given to us with such an large collection of information. Great work you have done by sharing them to all.

Gravatar Image5 -
Thanks for informative post. I am pleased sure this post has helped me save many hours of browsing other similar posts just to find what I was looking for. I bookmarked this blog a while ago because of the useful content and I am never being disappointed. Keep up the good work Just I want to say: Thank you!

Gravatar Image6 - I think a nice blog <a href="{ Link }

Gravatar Image7 -
Perhaps this is one of the most interesting blogs that I have ever seen. Interesting article, Funny comment. Keep it up!

Gravatar Image8 -
Perhaps this is one of the most interesting blogs that I have ever seen. Interesting article, Funny comment. Keep it up!

Post A Comment

:-D:-o:-p:-x:-(:-):-\:angry::cool::cry::emb::grin::huh::laugh::lips::rolleyes:;-)

Powered By:

Domino BlogSphere
Version 3.0.2