B4J Tutorial [Pen & Paper]: Create a simple 'Contacts' ABMaterial WebApp - Part 1

Hi y'all

For this tutorial you will need
MashPlugIns
Pen & Paper

Related Articles

Creating a simple 'Contacts' ABMaterial WebApp - Part 2
Creating a simple 'Contacts' ABMaterial WebApp - Part 3

Some time ago, I published how one can create a simple 'Hello World' webapp using Pen & Paper for their ABMaterial projects.

This second installment is how one can create a simple Contacts 'addedit' page for their ABMaterial WebApp. In this tutorial of the MVC approach, we will do the first two, the model and the view. Part 2 will deal with the C (controller) in detail. This page will have input controls, a navigation bar, side bar, and later an offset-ted button.

For now this is what you will do by just following easy 'click here', 'type this and that', 'apply', and with the beauty i.e. Pen & Paper, no code writing at all, all done inside Pen & Paper.

Figure 1
Contacts.gif



One of the most basic things I'm trying to achieve here is the simplicity of how you can create ABMaterial WebApps without lots of sweat. I always ask myself, how can I make this easier for me to use and quick?

Based on the subject matter of this topic, you will be dealing with form controls. As you are aware, Pen & Paper is about writing as minimal code as possible as the RAD tool itself tries its best to do everything for you. I label it 'simple' because for complex ABMComponents and other things, you will need to plan and write beautiful code, yourself.

Please note: I will not provide any source code for this tutorial as I would really like to encourage a hands on approach into the ins and outs of Pen & Paper and how it can help you CREATE ABMaterial WebApps easier and also faster.

If you have never used Pen & Paper before to create your ABMaterial WebApps, you can get your free version here. You will also need the MashPlugs Library. For this exercise this will suffice. Ohh, one last thing, you will need the ABMaterial Framework 4.00.

Please follow the instructions as they are for simplicity. In no time you will be able to do this in your sleep, better yet, copy these to word, print out and then run the tutorial instructions.

1. On your marks

Here we create our project, its database, a table with fields (the underlying SQLite database is created automatically by Pen & Paper)

Assumptions: You got ABMaterial 4.00 & MashPlugsIns installed in B4J External Libraries and Pen & Paper saved on your PC. If so...

Start Pen & Paper, once opened.

1.1 Open Project Menu > New > Type in Contacts. A couple of things will happen...:rolleyes:

1.2. On the tree view select and expand Database and click Add Table, a prompt will ask you of the table name, enter Contacts and click Ok.

1.3. Select Database and expand it, then select Table.Contacts (this is the new table you have created)

1.4. In the property bag (right section of the screen), select Fields tab, we need to add some fields to the table. The id field (autoincrement) has already been added by default when you created the table.

1.5. For each field click the + button in the sub property bag (far right of the screen), type in the fieldname FirstName (This should be text and also check Is Indexed), click Check button to save the field. See image below where these are.

Figure 2
AddSaveFields.png


The Contacts table will now have an additional field called FirstName. Add the following fields LastName, Street, StreetNumber, City, Country, ZipCode and Cellphone, all being Text the same way. Now you have a table with some fields in it. For each field, click Add, then specify the details and click Save.

Congratulations, you have created your first Pen & Paper project including its underlying database, a contacts table with fields that you will link to 1. page / 2. container / 3. table. For now we are doing 1. Page.

2. Get Set

Here we create our Contacts page through click and entry methodology. We are not going to write any code for this, yippiee!!!

Now that your database and contacts table are created, its time to link these to the page as they form the model of what we will be doing first, a contacts database. Let's now create the view.

1.6. In the tree view expand Pages and select Add Page, in the prompt type in addeditcontact. The page will be opened for updating its properties.

1.7. Change the Page Title and NavBar Title properties = Contacts, Is Initial Page=True, click the Apply button at the bottom of the property bag. Dont worry about the prompt about Sign Out functionality, click Ok there. The navbar and row components will be added to the tree.

1.8. There is a child item on the tree for this page called addeditcontact.addeditcontact, select it, this is where we will 'define' our view/page.

1.9. In the property bag, on ABMPage tab, set Table Name=Contacts and the Primary Key=id. When done click 'Save' at bottom right of Pen & Paper to save the component.

Figure 3

SaveComponent.png


1.10. Go back to addeditcontact.addeditcontact, in ABMPage tab, select Refresh Fields button, we need to create table linked components for the page. This process refreshes the Field Selector that we will use.

1.11. On the tabs, select Field Selector, this enables us to select the fields to be processed in the database table for this page.

1.12. Here you need to select the fields in sequence of appearance on your page, 1. select id and > to choose it, do the same for 2. firstname, 3. lastname, 4. street, 5. streetnumber, 6. city, 7. country, 8. zipcode and 9. cellnumber. Click Apply at the bottom of the Field Selector. Please note, the information selected with the field selector is temporal and is never saved.

1.13. In the tabs, select ABMComponents, here for each field selected we will indicate what type of field it is and its location on the page. These are all text inputs but for zipcode and cellphone, we need numeric keypads. We also want proper titles for them as the field names are all lowecase and no spaces inbetween.

1.14. As you might have noticed, we have 8 fields in our table besides the 'id' field. We don't want to see the id field and as we will use both s-mall, m-edium and l-arge devices for this page, we can design our page so that for small devices, the components show one after another and for medium and large devices, they show side by side. See the gif above. Now, this is the interesting part.

2.1 Linking each database field to the page

1.15. In the list of fields in the ABMComponents tab, lets do the following, change each property per field necessary. Select the field in the list, change the properties, select check when done to save the properties. The fields are already added by the field selector, so let's select each field, change the property needed and then save. For each fields in this steps change the properties then save it by clicking APPLY.

With the help of the Field Properties tab, you can now for each field update the properties in a Tabular Fashion as depicted below in Figure 5. To have the first first run the Field Selector step and then click Apply on the field selector, that will update the ABMComponents and the Field Properties tabs.

Figure 4

FieldProperties.png


2017-12-23 Update of Figure 4

FieldProperties.png


The component above was created using the XCustomListView.

For each field, change the respective properties to match above, i.e. Title, Component and the rest

R - Row position
C - Cell Position
OS - Offset on Small Devices
SM - Offset on Medium Devices
SL - Offset on Large Devices

Remember: Offset tell how the component should be moved to the right of the page.

SS - Size on Small Devices
SM - Size on Medium Devices
SL - Side on Large Devices

Remember: Size indicate the space that should be taken by the component in a 12 cell row.

PL - Padding Left
PR - Padding Right

These are just the basic properties needed. There are other properties per component that are also found on the Themes e.g. margins and padding that is additional.

E - Enabled
U - Use in Updates
V - Visible

Turning V to off will hide the component on all devices. This we need for the iD.

Remember to click Apply when done updating each field here. Don't change the field name as these are linked to the underlying database table.

1.16. Steps 1.15 above has just helped us both define the elements that will be on our page and their locations and how the page should display in all our devices, 12 in small and 6 for both medium and large. The ABM.GEN_TEL fields are numeric in nature and will show a numeric keypad for the telephone for us to input our numbers.

Now Select ABMRows tabs and ABMCells tabs and these will show you how the definition of the grid statements will be. There is nothing to do on those tabs, so you can leave them out. These have been generated by just specifying each fields/component properties and Pen & Paper will place them at the right locations for you when creating your page/view.

Figure 5.
AutomatedGridCreation.png


Now that you have linked your model to the view, now you need to create the 'actual' controls. This is just another way of saying to Pen & Paper, we exist and for each control you can then change its further properties to whatever you want.

1.17. Click ABMPage on the tabs, and click the 'Create Controls' button. The controls will be created on the tree. Your control definition is saved as part of this page and you can change anything here anytime you want and re-create the controls again.

1.18. We also want our page link to be reflected in the SideBar of the navigation. In Pages, select addeditcontact page and select the NavBar tab.

1.18.1 Set these properties:
Show on Global Side Menu=checked,
Side Bar Title=Add Edit Contact,
Global SideBar Icon - use the icon selector, search for 'user' and select the grouped users, this will be 'fa fa-users'
1.18.2 Show Global Side Menu=checked,

When done, select ABMPage tab and in the property bag set Is Initial Page=checked (THIS IS VERY IMPORTANT), and click Apply to save your page. You are done!!

Congratulations are in order again. You created your model where your Contacts will be stored. The next part was then to create the view i.e the look of your page by specifying where each component will sit, what will be its Title etc and now we need to test everything else.

3. Go

Here we run our Contacts page on the browser. When you have completed all this, its time to compile your project. Remember, you can create as many pages as you want within your app to have components anywhere you define and Pen & Paper will do the magic for you. Remember though gabbage in gabbage out.

1.19 Click Project on the menu > Compile and just follow the prompts. When Pen & Paper has done its intelligence, your default browser will open and also the contacts b4j project opened. Run the contacts b4j project and wait for your browser to heart-beat and update itself. Figure 1 will appear.

Thank you for taking time to read and also go through this exercise. Definately, this provides you the basis on how you can use Pen & Paper to create beautiful ABMaterial WebApps. That is how repititive this will be for your different apps and I wanted to provide exactly some part of elimination of the nature of this process.

The Beauty That Is Pen & Paper.

Enjoy

Related Links:
Pen & Paper
MashPlugIns

PS: The next article on this will via the same process of click here, type this there, link the database table, the page components by creating the underlying source code to glue everything together.

Watch this space!

;););););)
 
Last edited:

swamisantosh

Member
Licensed User
Longtime User
Hi y'all

Some time ago, I published how one can create a simple 'Hello World' webapp using Pen & Paper for their ABMaterial projects.

This second installment is how one can create a simple Contacts 'addedit' page for their ABMaterial WebApp. In this tutorial of the MVC approach, we will do the first two, the model and the view. Part 2 will deal with the C (controller) in detail. This page will have input controls, a navigation bar, side bar, and later an offset-ted button.

For now this is what you will do by just following easy 'click here', 'type this and that', 'apply', and with the beauty i.e. Pen & Paper, no code writing at all, all done inside Pen & Paper.

Figure 1
View attachment 62202


One of the most basic things I'm trying to achieve here is the simplicity of how you can create ABMaterial WebApps without lots of sweat. I always ask myself, how can I make this easier for me to use and quick?

Based on the subject matter of this topic, you will be dealing with form controls. As you are aware, Pen & Paper is about writing as minimal code as possible as the RAD tool itself tries its best to do everything for you. I label it 'simple' because for complex ABMComponents and other things, you will need to plan and write beautiful code, yourself.

Please note: I will not provide any source code for this tutorial as I would really like to encourage a hands on approach into the ins and outs of Pen & Paper and how it can help you CREATE ABMaterial WebApps easier and also faster.

If you have never used Pen & Paper before to create your ABMaterial WebApps, you can get your free version here. You will also need the MashPlugs Library. For this exercise this will suffice. Ohh, one last thing, you will need the ABMaterial Framework 4.00.

Please follow the instructions as they are for simplicity. In no time you will be able to do this in your sleep, better yet, copy these to word, print out and then run the tutorial instructions.

1. On your marks

Here we create our project, its database, a table with fields (the underlying SQLite database is created automatically by Pen & Paper)

Assumptions: You got ABMaterial 4.00 & MashPlugsIns installed in B4J External Libraries and Pen & Paper saved on your PC. If so...

Start Pen & Paper, once opened.

1.1 Open Project Menu > New > Type in Contacts. A couple of things will happen...:rolleyes:

1.2. On the tree view select and expand Database and click Add Table, a prompt will ask you of the table name, enter Contacts and click Ok.

1.3. Select Database and expand it, then select Table.Contacts (this is the new table you have created)

1.4. In the property bag (right section of the screen), select Fields tab, we need to add some fields to the table. The id field (autoincrement) has already been added by default when you created the table.

1.5. For each field click the + button in the sub property bag (far right of the screen), type in the fieldname FirstName (This should be text and also check Is Indexed), click Check button to save the field. See image below where these are.

Figure 2
View attachment 62203

The Contacts table will now have an additional field called FirstName. Add the following fields LastName, Street, StreetNumber, City, Country, ZipCode and Cellphone, all being Text the same way. Now you have a table with some fields in it. For each field, click Add, then specify the details and click Save.

Congratulations, you have created your first Pen & Paper project including its underlying database, a contacts table with fields that you will link to 1. page / 2. container / 3. table. For now we are doing 1. Page.

2. Get Set

Here we create our Contacts page through click and entry methodology. We are not going to write any code for this, yippiee!!!

Now that your database and contacts table are created, its time to link these to the page as they form the model of what we will be doing first, a contacts database. Let's now create the view.

1.6. In the tree view expand Pages and select Add Page, in the prompt type in addeditcontact. The page will be opened for updating its properties.

1.7. Change the Page Title and NavBar Title properties = Contacts, Is Initial Page=True, click the Apply button at the bottom of the property bag. Dont worry about the prompt about Sign Out functionality, click Ok there. The navbar and row components will be added to the tree.

1.8. There is a child item on the tree for this page called addeditcontact.addeditcontact, select it, this is where we will 'define' our view/page.

1.9. In the property bag, on ABMPage tab, set Table Name=Contacts and the Primary Key=id. When done click 'Save' at bottom right of Pen & Paper to save the component.

Figure 3

View attachment 62204

1.10. Go back to addeditcontact.addeditcontact, in ABMPage tab, select Refresh Fields button, we need to create table linked components for the page. This process refreshes the Field Selector that we will use.

1.11. On the tabs, select Field Selector, this enables us to select the fields to be processed in the database table for this page.

1.12. Here you need to select the fields in sequence of appearance on your page, 1. select id and > to choose it, do the same for 2. firstname, 3. lastname, 4. street, 5. streetnumber, 6. city, 7. country, 8. zipcode and 9. cellnumber. Click Apply at the bottom of the Field Selector. Please note, the information selected with the field selector is temporal and is never saved.

1.13. In the tabs, select ABMComponents, here for each field selected we will indicate what type of field it is and its location on the page. These are all text inputs but for zipcode and cellphone, we need numeric keypads. We also want proper titles for them as the field names are all lowecase and no spaces inbetween.

1.14. As you might have noticed, we have 8 fields in our table besides the 'id' field. We don't want to see the id field and as we will use both s-mall, m-edium and l-arge devices for this page, we can design our page so that for small devices, the components show one after another and for medium and large devices, they show side by side. See the gif above. Now, this is the interesting part.

2.1 Linking each database field to the page

1.15. In the list of fields in the ABMComponents tab, lets do the following, change each property per field necessary. Select the field in the list, change the properties, select check when done to save the properties. The fields are already added by the field selector, so let's select each field, change the property needed and then save. For each field in steps 1.15.1 to 1.15.8 first select it on the ListView, then change the properties then save it.

1.15.1 'id' field,
Component Type=ABM.GEN_NONE,
Row ID=1,
Visibility on Form=ABM.VISIBILITY_HIDE_ALL
<Save It>

1.15.2 'firstname',
Header/Label Text=First Name,
Required=check,
Row ID=2,
Size Medium=6,
Size Large=6,
<Save It>

1.15.3 'lastname',
Header/Label Text=Last Name,
Required,
Row ID=2,
Cell Id=2,
Size Medium=6,
Size Large=6,
<Save It>

1.15.4 'street',
Header/Label Text=Street Name,
Required,
Row ID=3,
Size Medium=6, S
ize Large=6,
<Save It>

1.15.5 'streetnumber',
Header/Label Text=Street Number,
Component Type=ABM.GEN_TEL,
Required,
Row ID=3,
Cell Id=2,
Size Medium=6,
Size Large=6,
<Save It>

1.15.5 'city', Header/Label Text=City,
Required,
Row ID=4,
Size Medium=6,
Size Large=6,
<Save It>

1.15.6 'country',
Header/Label Text=Country,
Required,
Row ID=4,
Cell ID=2,
Size Medium=6,
Size Large=6,
<Save It>

1.15.7 'zipcode',
Header/Label Text=Zip Code,
Component Type=ABM.GEN_TEL,
Required,
Row ID=5,
Size Medium=6,
Size Large=6,
<Save It>

1.15.8 'cellphone',
Header/Label Text=Cellphone,
Component Type=ABM.GEN_TEL,
Required,
Row ID=5,
Cell ID=2,
Size Medium=6,
Size Large=6,
<Save It>

Phew!!!!

1.16. Steps 1.15 above has just helped us both define the elements that will be on our page and their locations and how the page should display in all our devices, 12 in small and 6 for both medium and large. The ABM.GEN_TEL fields are numeric in nature and will show a numeric keypad for the telephone for us to input our numbers.

Now Select ABMRows tabs and ABMCells tabs and these will show you how the definition of the grid statements will be. These have been generated by just specifying each fields/component properties and Pen & Paper will place them at the right locations for you when creating your page/view.

Figure 4.
View attachment 62206

Now that you have linked your model to the view, now you need to create the 'actual' controls. This is just another way of saying to Pen & Paper, we exist and for each control you can then change its further properties to whatever you want.

1.17. Click ABMPage on the tabs, and click the 'Create Controls' button. The controls will be created on the tree. Your control definition is saved as part of this page and you can change anything here anytime you want and re-create the controls again.

1.18. We also want our page link to be reflected in the SideBar of the navigation. In Pages, select addeditcontact page and select the NavBar tab.

1.18.1 Set these properties:
Show on Global Side Menu=checked,
Side Bar Title=Add Edit Contact,
Global SideBar Icon - use the icon selector, search for 'user' and select the grouped users, this will be 'fa fa-users'
1.18.2 Show Global Side Menu=checked,

When done, select ABMPage tab and in the property bag set Is Initial Page=checked (THIS IS VERY IMPORTANT), and click Apply to save your page. You are done!!

Congratulations are in order again. You created your model where your Contacts will be stored. The next part was then to create the view i.e the look of your page by specifying where each component will sit, what will be its Title etc and now we need to test everything else.

3. Go

Here we run our Contacts page on the browser. When you have completed all this, its time to compile your project. Remember, you can create as many pages as you want within your app to have components anywhere you define and Pen & Paper will do the magic for you. Remember though gabbage in gabbage out.

1.19 Click Project on the menu > Compile and just follow the prompts. When Pen & Paper has done its intelligence, your default browser will open and also the contacts b4j project opened. Run the contacts b4j project and wait for your browser to heart-beat and update itself. Figure 1 will appear.

Thank you for taking time to read and also go through this exercise. Definately, this provides you the basis on how you can use Pen & Paper to create beautiful ABMaterial WebApps. That is how repititive this will be for your different apps and I wanted to provide exactly some part of elimination of the nature of this process.

The Beauty That Is Pen & Paper.

Enjoy

Related Links:
Pen & Paper
MashPlugIns

PS: The next article on this will via the same process of click here, type this there, link the database table, the page components by creating the underlying source code to glue everything together.

Watch this space!

;););););)
Hi
 

Mashiane

Expert
Licensed User
Longtime User
Closing off Part 1:

NB: Please download the latest version of Pen & Paper and then do a Project > Upgrade first after you open your project so that your project is compatible with Pen & Paper 403 and ABMaterial 4.03. Links on first post.


We need to add a save button to the form. We need to place this at R6C1, it should be placed to the right of the screen and must fill the complete cell. For small devices it should be 12 and medium and large 3.

As you might have noted above Figure 4 above at its bottom, we had a button control. Let's add it.

Figure 6.

SaveButton.png


To do this we need to use the ABMComponents Tab.

After you have updated each field properties here and saved them via apply, adding a button is easy.

1. Select the ABMComponents tab.
2. Click the Add Button (+)
3. Change the Seq Field Name to 10
4. In the Data Field, enter btnSave
5. Change the Header / Label Text to Save
6. Select ABM.GEN_BUTTON Component Type
7. Click the Clickable property to be on.
8. Check the Use Full Width to be on
9. Enter the Row ID = 6
10. Cell ID = 1
11. Offset Medium = 9
12. Offset Large = 9
13. Size Medium = 3
14. Size Large = 3
15. Padding Right=10 (You need to pad it right otherwise it will display outside of the area)
16. Enabled = on
17. Visible = on

You are done, you should have mostly what is Figure 7 and 8 below.

Figure 7

SaveButton.png


Figure 8

btnSave1.png


Select the ABMPage Tab and click "Create Controls"

In the menu, select Project, Compile to recompile your project. You should now be seeing this on the viewer.

Figure 9

Viewer.png
 

liulifeng77

Active Member
Licensed User
Longtime User
wow,It's very nice! I like it.
but how to use "MashCarousel", is it a customcomponent?
I copy the MashPlugIns.jar, MashPlugInsFiles.jar,MashPlugIns.xml to C:\Program Files (x86)\Anywhere Software\B4J\Libraries.
when I compile the project,
IDE shows such message:

B4J Version: 5.90
Parsing code. (0.47s)
Compiling code. (0.56s)
Compiling layouts code. (0.00s)
Organizing libraries. (0.00s)
Compiling generated Java code. Error
Cannot find: C:\Program Files (x86)\Anywhere Software\B4J\libraries\poi-3.16.jar
 
Last edited:

OliverA

Expert
Licensed User
Longtime User

Harris

Expert
Licensed User
Longtime User
the underlying SQLite database is created automatically by Pen & Paper
Is this used just to hold the properties defined by P&P - or is it our actual Contacts db and tables? If the latter, can we use MySQL as well?

Thanks. Great Work! Where the heck do you find the time (and knowledge) to create such magic?
 

Mashiane

Expert
Licensed User
Longtime User
When you create a new project in P&P, two SQLite databases are created, 1 to hold your project definitions, pages and controls, the other database is the actual deployment stuff you upload and run directly on your webserver. I will add support for MySQL soon as for now all development is done using SQLite.

It however should not be difficult to port your app to MySQL, exporting your SQLite to MySQL and then changing the connection string in the generated b4j project.
 

Mashiane

Expert
Licensed User
Longtime User
wow,It's very nice! I like it.
but how to use "MashCarousel", is it a customcomponent?
I copy the MashPlugIns.jar, MashPlugInsFiles.jar,MashPlugIns.xml to C:\Program Files (x86)\Anywhere Software\B4J\Libraries.
when I compile the project,
IDE shows such message:

B4J Version: 5.90
Parsing code. (0.47s)
Compiling code. (0.56s)
Compiling layouts code. (0.00s)
Organizing libraries. (0.00s)
Compiling generated Java code. Error
Cannot find: C:\Program Files (x86)\Anywhere Software\B4J\libraries\poi-3.16.jar
The MashCarousel is available here... https://www.b4x.com/android/forum/threads/abmaterial-mashcarousel.86507/#content
 
Top