My Dear Friends,
In the continuation of my previous blog on XQuerrail Framework, Today we are going to discuss about about MVC in XQuerrail framework for development of Model, View and Controller for application development.
I hope you remember my previous post on this (XQuerrail) thread but if you missed then please go over it here
In previous post we learned about installation of prerequisites and configuration of application to run on XQuerrail framework in Mark Logic. Now let’s extend the same application to implement model, view and controller as per MVC framework in Xquerrail.
MVC in XQuerrail is similar to MVC pattern in any other language/framework
View - It is implementation of presentation layer which actually appears as UI for user interaction. XHTML is mostly used markup to design layout of view wile creating for XQuerrail framework based application.
Controller - It is responsible to handle requests from view and respond according to specific request for specific action. Controllers are written in XQuery for Xquerrail framework.
Model - It is responsible for data/table structure definition to store or share data in specific structure with specific number of fields/properties etc. It is also responsible for any operation to be performed on data as saved in database in specified model structure.
In XQuerrail framework model is implemented in domain using domain.xml which is facilitated by base model and controller layer of framework to support common operation like create, edit, delete, get, list etc.
So in case of normal operation we don’t need to write any code in model layer and basic operation requests are handled by framework model but if in any case if we need any custom implementation of any existing or new operation/action than we can achieve that by writing associated model layer which is responsible to get, create and manipulate data in database.
Now let’s come to the practical directly.
To create any model you need to navigate to “/app/domain/application-domain.xml” where you can observe already available some the model definition. Now create your own model for “Person” by copying below code in application-domain.xml withing “domain” block.
Below are the purpose of each element as specified in above definition of model
Name - It is the name of model which should be unique for identification of model.
Persistence - This property indicates about how the model will persist in database. Below are some of the possible values for this.
Abstract - if a model is created with “abstract”persistence that means model is not going to save but will be used as class to inherit common properties
Document - If a model is created with document” persistence that means the model is going to be converted in a xml with associated data to be saved in database where xml will be containing multiple records of specified model definition.
Directory - If a model is created with “directory” persistence that means the model is going to convert in xml with associated data where each xml will be containing single record of specified model definition.
Key - This property specifies unique key for each record belonging to specified model definition.
KeyLabel - It defines label to be displayed for unique key field
Extends - This property used to provide reference of another abstract model to inherit common properties.
Directory - this element specifies the location of directory in mark logic database which is used to preserve/save xml for each record of specified model
Navigation - This element is used to enable/disable basic operations of model as provided by framework by default additionally with custom operation (if any). Below are some of them as provided by framework.
Newable - Set this property to true/false if you want/don’t want to allow creation of record for specified model
Editable - Set this property to true/false if you want/don’t want to allow editing of record for specified model
Removable - Set this property to true/false if you want/don’t want to allow deletion of record for specified model
Listable - Set this property to true/false if you want/don’t want to allow listing of records for specified model
Element - This element is used to define data points to be saved in document. It also contains type of information with their label to be appear on UI.
So for example as shown in code snippet , we have defined a person model with associated information to save in Mark Logic.
Now lets define controller for this model to respond requests. Add below code in application-domain.xml at last within domain tag.
Now lets try some modifications to model definition in navigation element to to enable/disable common operation which are going to be handled by framework by default where we don’t need to write any code for CRUD (CReate, Update,, Delete) operations
As of now as you can see there is option to add new person record, edit and delete on index.html page. Now suppose we don’t need to provide editing and removing feature for person model. In that case just set following properties to false and you will observe that feature of editing and removal of person record is dis-allowed from the UI.
Isn’t it quite simple and cool...
Well, So far we saw about the normal CRUD operation and learned about how we can configure and achieve that in XQuerrail framework through model creation and configuration without writing any line of code for controller. I hope you observed that we have not written any view as well to display desired UI with data.
We have just created model definition and rest of implementation of controller with default operations and view is automatically created by XQuerrail framework.
But there are many condition where default controller or view implementation by framework is not sufficient and we need additional methods or UI modifications to achieve desired feature and functionality of application. So that’s the point where the custom model, controller and/or view may need to create as per specification of requirement.
As of now enough for today and just explore and try creation of screens with various possible options/configurations. We will meet soon with next part of this article where we would learn to create custom model, controller and view as per specific requirement.
Till the time keep enjoy learning and exploring.
In the continuation of my previous blog on XQuerrail Framework, Today we are going to discuss about about MVC in XQuerrail framework for development of Model, View and Controller for application development.
I hope you remember my previous post on this (XQuerrail) thread but if you missed then please go over it here
In previous post we learned about installation of prerequisites and configuration of application to run on XQuerrail framework in Mark Logic. Now let’s extend the same application to implement model, view and controller as per MVC framework in Xquerrail.
MVC in XQuerrail is similar to MVC pattern in any other language/framework
View - It is implementation of presentation layer which actually appears as UI for user interaction. XHTML is mostly used markup to design layout of view wile creating for XQuerrail framework based application.
Controller - It is responsible to handle requests from view and respond according to specific request for specific action. Controllers are written in XQuery for Xquerrail framework.
Model - It is responsible for data/table structure definition to store or share data in specific structure with specific number of fields/properties etc. It is also responsible for any operation to be performed on data as saved in database in specified model structure.
In XQuerrail framework model is implemented in domain using domain.xml which is facilitated by base model and controller layer of framework to support common operation like create, edit, delete, get, list etc.
So in case of normal operation we don’t need to write any code in model layer and basic operation requests are handled by framework model but if in any case if we need any custom implementation of any existing or new operation/action than we can achieve that by writing associated model layer which is responsible to get, create and manipulate data in database.
Now let’s come to the practical directly.
To create any model you need to navigate to “/app/domain/application-domain.xml” where you can observe already available some the model definition. Now create your own model for “Person” by copying below code in application-domain.xml withing “domain” block.
<model name="person" persistence="directory" key="uuid" keyLabel="uuid" extends="base" >
<directory>/data-sources/persons/</directory>
<navigation newable="true" listable="true" editable="true" removable="true" />
<element name="name" type="string" label="Name" />
<element name="email" type="string" label="Email" />
<element name="address" type="string" label="Address" />
<element name="dob" type="string" label="Date Of Birth" />
<element name="age" type="string" label="Age" />
</model>
Below are the purpose of each element as specified in above definition of model
Name - It is the name of model which should be unique for identification of model.
Persistence - This property indicates about how the model will persist in database. Below are some of the possible values for this.
Abstract - if a model is created with “abstract”persistence that means model is not going to save but will be used as class to inherit common properties
Document - If a model is created with document” persistence that means the model is going to be converted in a xml with associated data to be saved in database where xml will be containing multiple records of specified model definition.
Directory - If a model is created with “directory” persistence that means the model is going to convert in xml with associated data where each xml will be containing single record of specified model definition.
Key - This property specifies unique key for each record belonging to specified model definition.
KeyLabel - It defines label to be displayed for unique key field
Extends - This property used to provide reference of another abstract model to inherit common properties.
Directory - this element specifies the location of directory in mark logic database which is used to preserve/save xml for each record of specified model
Navigation - This element is used to enable/disable basic operations of model as provided by framework by default additionally with custom operation (if any). Below are some of them as provided by framework.
Newable - Set this property to true/false if you want/don’t want to allow creation of record for specified model
Editable - Set this property to true/false if you want/don’t want to allow editing of record for specified model
Removable - Set this property to true/false if you want/don’t want to allow deletion of record for specified model
Listable - Set this property to true/false if you want/don’t want to allow listing of records for specified model
Element - This element is used to define data points to be saved in document. It also contains type of information with their label to be appear on UI.
So for example as shown in code snippet , we have defined a person model with associated information to save in Mark Logic.
Now lets define controller for this model to respond requests. Add below code in application-domain.xml at last within domain tag.
<controller name="persons" model="person" label="Persons" class="base" />
Here we have provided required information to framework for controller. Controller name is “persons”and related mode “person” display label as “Persons” if shown in UI and class belongs to base that means default controller operations are going to be handled by base framework, whether we write additional controller and model or not.
Now initialize the application by navigating to initialization url of your configured application.
For ex. http://localhost:port/initialize.xqy
Now initialize the application by navigating to initialization url of your configured application.
For ex. http://localhost:port/initialize.xqy
So as we have already added model and controller configuration for person class we can navigate to below URL to view default index page implementation from framework.
Now lets try some modifications to model definition in navigation element to to enable/disable common operation which are going to be handled by framework by default where we don’t need to write any code for CRUD (CReate, Update,, Delete) operations
As of now as you can see there is option to add new person record, edit and delete on index.html page. Now suppose we don’t need to provide editing and removing feature for person model. In that case just set following properties to false and you will observe that feature of editing and removal of person record is dis-allowed from the UI.
<navigation newable="true" listable="true" editable="false" removable="false" />
Isn’t it quite simple and cool...
Well, So far we saw about the normal CRUD operation and learned about how we can configure and achieve that in XQuerrail framework through model creation and configuration without writing any line of code for controller. I hope you observed that we have not written any view as well to display desired UI with data.
We have just created model definition and rest of implementation of controller with default operations and view is automatically created by XQuerrail framework.
But there are many condition where default controller or view implementation by framework is not sufficient and we need additional methods or UI modifications to achieve desired feature and functionality of application. So that’s the point where the custom model, controller and/or view may need to create as per specification of requirement.
As of now enough for today and just explore and try creation of screens with various possible options/configurations. We will meet soon with next part of this article where we would learn to create custom model, controller and view as per specific requirement.
Till the time keep enjoy learning and exploring.
It's Awesome!
ReplyDelete