What is FORMBEAN?

xiaoxiao2021-03-06  41

What is FORMBEAN?

In Struts Framework, we must configure a FORMBEAN when configuring config, I believe that some people will have the same confusion with me. This Formbean plays a role in the entire framework, what role is there. With these doubts, let's track this FORMBEAN what is going on in Framework? What to do?

We found struts-config.xml this XML configuration file in a web-in inf directory of the web module. From the following directory we can see the struts-config.xml configuration file can be divided into many, so that the configuration file is managed, A module corresponds to a configuration file, very clear. We open a config configuration file (such as a red box file)

We see that the tag is defined here is what this module needs to be shown as shown below. Here = "Butone.hr.rcyw.ldht.Object.ldhtvo" refers to the Formbean package The path, the name is name = "ldhtvo", we can see an action corresponding to a FORMBEAN in the tab, thereby understanding the action and the FORMBEAN is one or one.

We open the LDHTAction this file to see, we can see the code according to the cmdflag passed in the file: SELECT ":

LDHTPageInfovo AldhtpageInfovo = New LDHTPAGEINFOVO ();

AldhtpageInfovo.querycommcondition = selectcondition.toString ();

Vector result = AldhtService.selectLDHTLIST (AldhtPageInfovo);

Request.setttribute ("PageResult", Result;

From this code, we can't see LDHTVO. We found only LDHTPageInfovo, let's take a look at this vo, something is something:

Public class ldhtpageInfovo extends pageinfovo {

Public ldhtpageInfovo () {

ORDERNAME = ldhtconstant.default_order_name;

Ordertype = ldhtconstant.default_order_type;

RowsPalpage = ldhtconstant.rows_per_page;

TableName = ldhtconstant.view_name;

ListNames = ldhtconstant.select_cols;

}

}

It turns out that only one pageinfovo is inherited, and there is also a page information.

We continue to track this paragraph Vector result = AldHTService.selectLDHTLIST (AldhtpageInfovo);

Open LDHTService This class finds SelectLDHTLIST method

Public Vector SelectLDHTLIST (PageInfovo ApageInfovo) Throws Exception {

Return Aldhtlocal.SelectLDHTLIST (ApageInfovo);

}

This method only one sentence, calling a sessionBean method LDHTHTHANDLE, open this sessionbean We can find this method as follows: Public Vector SelectLDHTLIST (PageInfovo ApageInfovo) Throws Exception {

LDHTVO ALDHTVO = New LDHTVO ();

LDHTDBACCESS Adbaccess = New LDHTDBACCESS ();

Return Adbaccess.SelectPage (ApageInfovo, Aldhtvo);

}

Haha, I finally appeared LDHTVO. This method invokes the SelectPage method in the LDHTDBACcess class and passed the two parameters one of them is paging information, the other is LDHTVO. VO.

We continue to track what the SELECTPAGE does this method do? Open LDHTDBACCESS This class finds SelectPage method:

Public Class LDHTDBACCESS Extends dbpagebean {

/ **

* DESCRIPTION: Delete a record

* @Param String ID

* @Return Void

* @Throw Exception

* /

Public void deleteone (String id) throws exception {

StringBuffer SQL = New StringBuffer ();

SQL.Append ("delete from");

SQL.Append (ldhtconstant.table_name);

SQL.Append ("where");

SQL.Append (ldhtconstant.key_name);

SQL.Append ("= '");

SQL.Append (ID);

SQL.Append ("'");

EXECTUESQL (SQL.TOString ());

}

/ **

* @Method Isillegal determines whether the object is in line with, modify the numbering principle -

* @Param bo

* @return returns true, returning false without legal

* /

Public Boolean Isillegal (LDHTBO BO) {

Return True;

}

} // end.

We have found that in addition to these two classes, there is no other way, but it inherits the dbpagebean parent class. This parent class is in the frame. This is difficult to we find the FoundationV2.jar of the frame. Compilation and see,

Public Vector Selectpage (PageInfovo ApageInfovo, Basevo Abasevo)

Throws Exception

{

Return Readpage (ApageInfovo, ABASEVO);

}

Use a readpage method,

Public Vector Readpage (PageInfovo PageInfovo, Basebo Abasebo)

{

ResultSet Pagers = NULL;

Connection conn = NULL;

PreparedStatement PSTMT = NULL;

Try

{

Vector avector = new vector ();

Int acurpage = pageinfovo.curbage;

Comm.log (1, "The current page bean starts performing page page operation: retrieving the" Acurpage "page"); TRY

{

Calmaxrowcount (PageInfovo);

Calmaxpage (PageInfovo);

PageInfovo.querysql = CREATEQUERYSQL (PageInfovo);

Comm.log (1, "Query SQL =" PageInfovo.QuerySQL);

Calmaxpage (PageInfovo);

IF (Acurpage> PageInfovo.maxpage)

Acurpage = pageInfovo.maxpage;

SetCurpage (Acurpage, PageInfovo);

CONN = getConn ();

PSTMT = getpStmt (conn, pageinfovo.querysql);

Pagers = PSTMTQUERY (PSTMT);

IF (Pagers! = NULL)

{

Comm.log (1, "Current page number of lines Isolated:" PageInfovo.maxRowcount);

Comm.log (1, "Current page number of pages in the page:" PageInfovo.maxpage);

}

CalcurmaxRows (PageInfovo);

}

Catch (Exception EX)

{

Pagers = NULL;

EX.PrintStackTrace ();

}

Basevo abasevos [] = (Basevo []) NULL;

IF (pageInfowvo.rowsperpage! = -1)

Abasevos = new basevo [pageInfovo.curmaxrow];

Else

Abasevos = new basevo [pageInfovo.maxrowcount];

INT i = 0;

IF (pageinfovo.curpage> 1 && pageinfovo.rowsperpage! = -1)

PageInfovo.RowsPage * (PageInfovo.curbage - 1));

Comm.log (1, "The result set of the current page bean is rolling =" PageInfovo.RowsPerpage * (PageInfovo.curbage - 1));

While (Pagers.Next ())

{

Avector.Add (Parseres, ABasebo, PageInfovo.listNames);

i ;

}

IF (pageInfovo.maxrowcount == 0)

PageInfovo.curbage = 0;

Avector.Add (PageInfovo);

Comm.log (1, "Vector: Length =" Avector.Size ());

Vector.

Return vector;

}

Catch (Exception EX)

{

EX.PrintStackTrace ();

}

Finally

{

FreeConn (Pagers, PSTMT, CONN);

}

Return NULL;

}

In fact, in this method is to save each multi-piece data to a LDHTVO and then save it to a vector, return.

To this time we can see the returnful vector in action is actually a series of LDHTVOs. Retraction to the JSP page We can see Vector LDHTVOS = (Vector) Request.getaTribute ("PageResult");

IF (ldhtvos! = null) {

For (int I = 0; i

LDHTVO ALDHTVO = (LDHTVO) LDHTVOS.GET (i);

%>

" Class = "RyxxWindow"> <% = AldHtvo.getRyBH ()%>

<% = AldHtvo.getxm ()%>

<% = AldHtvo.getxb ()%>

<% = aldhtvo.getnl ()%>

<% = aldhtvo.getgl ()%>

<% = Aldhtvo.getJgmc ()%>

<% = aldhtvo.getBmmc ()%>

<% = Aldhtvo.getYGLB ()%>

<% = aldhtvo.get ()%>

<% = Aldhtvo.gettdqrq ()%>

<% = AldHtvo.gettzzrq ()%>

<%}}%>

Such a code is actually taken out of the VO in the vector, and then take the data in the Vo.

In fact, we haven't seen what is going on this FORMBEAN. Let's take a look at the Edit operation, which is to modify a data on the page, then save it to the database,

We first open the JSP page to see the following code

We discovered the name of the INPUT form and the name in Vo, then we went to the action} else if (cmdflag.equals ("save")) {

LDHTVO AVO = (LDHTVO) Form;

LDHTBO ABO = (LDHTBO) Convertvotobo (AVO, AUSERBEAN);

Try {

AldHTService.saveldht (ABO);

Avo.dirtyflag = Abo.dirtyflag;

} catch (exception e) {

E.PrintStackTrace ();

IF (abo.isnew ()) {

Avo.setLDHTID ("");

}

Request.setttribute ("alertmsg", "save record error, error reason:" BTDBHELPER.GETMESSAGE (E));

}

Request.setttribute ("Detail_LDHTVO", AVO);

Return (Mapping.Findforward ("LDHTEDIT"));

}

We can see that FORM is actually Vo to formbean, so that we have submitted a lot of books, save a lot of code.

The FORMBEAN is all parsed.

Author: Anders xiao

转载请注明原文地址:https://www.9cbs.com/read-86258.html

New Post(0)