Duration: 15 minutes
Summary: In this tutorial, we will study 2 transactions inside our application. First, a Debit Transaction, that will serve as an opposite transaction to the Credit. After this we will create a statement transaction, and set all the persistence inside the app. In this course, we’re going to learn the Java Struts 2 Technology, presenting a Tomcat Web solution and exploring how a Finance Management Software can be designed using these resources.
Technology Used: Java, Apache Struts 2, Eclipse, Tomcat
Keyword: Java, Eclipse, Struts 2, Tomcat, apache, mvc
Hello everybody and welcome. Let's continue our Struts Java course. Right
now we're going to create another transaction, to complete our application
map. As we have a credit action, we're going to create a debit action
that will give an opposite effect to the credit operation. We're just
going to change credits to debits and change this. After this we're just
going to copy and past the credits.jsp file and we'll call it debits.jsp.
We're going to name this action debit, it's the same transaction, but with
an opposite effect. And after that you have made the debit .jsp file we
have to duplicate the credit action file, and set the name as deb action as
you have here That too, will change the name of this [class] to deb action
automatically. Now you have two transactions, debit and credit, and you
cant test both inside your Struts.xml, you have the debit declaration and
the credit declaration.
After this we'll create our third action and name it statement. You will
use this statement transaction to see all of your operation inside the
application. We're going have a statement transaction, to serve as a guide
line and help us to see our transactions that we make inside the
application. So we're going to cut this code, and we're going to set the
statement. I will have to create the statement action, right here.
After doing this declaration inside the Struts .xml you have to create your
transaction jsp file, your web jsp file. So let's do it, we're going to
copy and paste this deb file and call this statement.jsp. Once you have
this file, set it. You'll type as the title Statement, and we're going to
set a bunch of tags to give a shape to our document inside the body of the
text, you have to set a balance, label.
Here we're going to use a property tag. Property tags work using a value,
and this value will be recorded, and sent by your action. Once you have
the balance tag, that we will use it to give a number and presume numbers
once, entered on application, after this we're going to list all
movements, credits and debits that we made inside the finance application.
We're going to call it] movements. We're going to set the [red] line, and
you're going to insert an html table, normal, and set a bar there. Inside
the table text we're going to use a [redder] tag. The [redder] tag has two
sets that we can call value, and were going to call Var. Value will be
used as our object that will act. If a collection and a var is the
variable, use it inside of every loop pass. Inside data reader tag we're
going to create some properties.
Those properties that we're going to use inside this loop operation. We're
going to call this value Transactions, representing all transactions used,
and the TRM variable, representing a single transaction. So you have the
collection, and you have the single transaction. Then next step, we have
to create this object, name it transactions, and we have to create a
transaction object. We're going to have two objects. One for a single
transaction, and a set of transactions named transactions.
So let's create the transaction class, we're going to call it transaction.
Once we create this transaction we're going to fill this class with
properties. First of all let's create an ID for identification. Let's
create a date that's going to be part of this library. After this we're
going to create a property named nature. Because we can have debit or
credit operations, and a log variable called amount.
You see underlines on yellow and you have to create and settle for all
these properties nature amount. Also you can create a constrictor for
this class public transaction. I have an empty constrictor, and you can
create a constrictor to help you view all the fields inside. Just filling
with all the attributes that I have inside this class. So you fill all the
attributes with the values passed inside the method, nature amount.
OK. Here you've got the class that we represent, values for class that you
use inside all your applications. But after this, we must think how we are
going to persist these values inside the application. In this tutorial
we're going to start a simple way to persist those values. We're going to
use the web session format, and I have a well done made class to use to
So let's create a class and named transactions. Inside this class we're
going to persist all values. I have already made a code to do this job for
me so I'm just copying the values to this class. It's very useful. Until
that thing's working here, you have to copy this xword-core
inside your reference libraries. Ince you have this done, you have to open
the properties, then you go to Java root path,you have to make a new
reference the library and call it xword-core, made it you have
xword-core you have to know the thing's working here. So let's see how this object
works. You have a map inside the session object, that will get this on
your action contexts with the method name get session, and get the session
of the TomCat, and help us to persist in information that we want. So I
have a list here of transactional objects and I have three methods.
One to get all these transactions. One to set all, when I set the object
inside my session. And an add, one I will add a single transaction to
this object. It's a simple code, but I will not lose time explaining it
line-by-line of my code. This code, we have to set our focus inside the
Struts. Once you have this, we have to set how the statement will work
inside the application. We will work on this in our next class. See you,
thank you very much.