It has been six months since struts was used for development projects. Due to poor memory, I often refer to the previous Code during the development process. Now I have sorted out several items
The labels are summarized as follows:
1. Use of the <s: Radio/> label:
<S: Radio name = "comicimage. highquality" id = "highquality" theme = "simple"
List = "# {0: gettext ('comicimage. highquality. true'), 1: gettext ('comicimage. highquality. false ')}"
Listkey = "key" onclick = "selectall ();" listvalue = "value" value = "1"> </S: Radio>
In this case, the second one in a single queue group is selected by default. Besides setting the "value" value to be the same as the list key, you can also set the "name" property value to be the same as the key,
Of course, both name and value can be parameters that have been assigned values in action, so that radio can be selected by default.
2. <display: Table> to obtain the current number of rows:
<%
Int roww = 0;
%>
<Display: Table name = "comicimages" cellspacing = "0" cellpadding = "0" id = "comicimage" class = "table" Export = "false">
<% Roww ++; %>
<Display: column escapexml = "false" sortable = "false" titlekey = "comicimage. imageid"
Style = "width: 8%">
$ {Comicimage_rownum}
</Display: column>
</Display: Table>
Comicimages is the list object set obtained by action. As shown above, there are two ways to get the current number of rows, define a variable, and increase the value of a row in each loop by 1;
$ {Comicimage_rownum} can also get the current row number;
3. <s: Select> on the normal form page
<S: Select label = "% {gettext ('comicimage. sroucetype ')}"
List = "# {'0': gettext ('series. srouce.0 '), '1': gettext ('series. srouce.1 '), '2': gettext ('image. srouce.2 ')}"
Listkey = "key" listvalue = "value"
Name = "comicimage. sroucetype" value = "% {comicimage. sroucetype}"/>
At this time, the values of name and value are the values passed by the form object. You can also write only one of the attributes to achieve the default selection in the drop-down box;
4. <s: Select> within the <display: Table> label:
If <s: Select> is embedded in the <display: Table> label, the above "3" method cannot be selected by default. The name and value Attributes cannot be obtained based on the above methods;
<S: select
List = "# {'0': gettext ('image. sroucetype.0 '), '1': gettext ('image. sroucetype.1 '), '2': gettext ('image. sroucetype.2 ')}"
Listkey = "key" listvalue = "value"
Name = "# ATTR. comicimage. sroucetype" theme = "simple"
Onchange = "javascript: upcateortype ('% {# ATTR. comicimage. imageid}', this. Options [This. Options. selectedindex]. Value, false);"/>
5. <s: bean> call the Java class to obtain the category drop-down box.
(1) bean code:
Public class categorydata {
Private Static hashmap <Boolean, linkedhashmap <integer, string> categorysbyisseris =
New hashmap <Boolean, linkedhashmap <integer, string> ();
Private Static linkedhashmap <integer, string> categorysall = new linkedhashmap <integer, string> ();
Private Static list <comiccategory> categorylist = new arraylist <comiccategory> ();
Static {
Linkedhashmap <integer, string> categorys = new linkedhashmap <integer, string> ();
Linkedhashmap <integer, string> categorysisseris = new linkedhashmap <integer, string> ();
Comiccategorydao = (comiccategorydao) springbeanutils. getinstance (). getbean ("comiccategorydao ");
List <comiccategory> listisseris = comiccategorydao. getlistbyisseries (true );
List <comiccategory> List = comiccategorydao. getlistbyisseries (false );
For (comiccategory comic: listisseris ){
Categorysisseris. Put (comic. getcategoryid (), comic. getname ());
Categorylist. Add (comic );
}
For (comiccategory comic: List ){
Categorys. Put (comic. getcategoryid (), comic. getname ());
Categorylist. Add (comic );
}
Categorysall. putall (categorysisseris );
Categorysall. putall (categorys );
Categorysbyisseris. Put (false, categorys );
Categorysbyisseris. Put (true, categorysisseris );
}
Public static string getcategorynamebyid (INT cate_id ){
String name = categorysall. Get (cate_id );
Return null = Name? "": Name;
}
// Get category 'id by index and isseris
Public static integer getcateval (INT which, Boolean isseris ){
If (which <0)
Return 0;
Return (integer) getcategorymap (isseris). keyset (). toarray () [which];
}
// Get category 'id by index
Public static integer getcateval (INT which ){
If (which <0)
Return 0;
Return (integer) categorysall. keyset (). toarray () [which];
}
// Get category 'name by index and isseris
Public static string getcatename (INT which, Boolean isseris ){
String name = getcategorymap (isseris). Get (getcateval (which, isseris ));
Return (null! = Name )? Name :"";
}
// Get the category 'name of all the category
Public static string getcatename (INT which ){
String name = categorysall. Get (getcateval (which ));
Return (null! = Name )? Name :"";
}
// Get category by isseris
Public static linkedhashmap <integer, string> getcategorymap (Boolean isseris ){
Return categorysbyisseris. Get (isseris );
}
// Get category not by isseris
Public static linkedhashmap <integer, string> getcategorymap (){
Return categorysall;
}
// Get size by isseris
Public static int getsize (Boolean isseris ){
Return getcategorymap (isseris). Size ();
}
// Get size not by isseris
Public static int getsize (){
Return categorysall. Size ();
}
Public static list <comiccategory> getcategorylist (){
Return categorylist;
}
Public static linkedhashmap <integer, string> getseriescategorymap (){
Return categorysbyisseris. Get (true );
}
Public static linkedhashmap <integer, string> getimagecategorymap (){
Return categorysbyisseris. Get (false );
}
}
(2) Use the <s: bean> label in <display: Table>:
<S: bean name = "com. Zongheng. Comic. Op. webapp. util. categorydata" id = "categorydata"/>
<S: select list = "# categorydata. imagecategorymap"
Listkey = "key" listvalue = "value"
Name = "# ATTR. comicimage. categoryid" theme = "simple"
Onchange = "javascript: upcateortype ('% {# ATTR. comicimage. imageid }',
This. Options [This. Options. selectedindex]. Value, true); "/>
(3) Use Java code to implement the drop-down box:
<Select name = "cateevent" id = "cateevent" onchange = "javascript: upcateortype ($ {comicimage. imageid}, this. options [this. options. selectedindex]. value, true); "class =" select ">
<%
Int currcate = (list <comicimage>) request. getattribute ("comicimages"). Get (roww-1). getcategoryid ();
For (INT I = 0; I <categorydata. getsize (false); I ++ ){
%>
<Option value = "<% = categorydata. getcateval (I, false) %>" <%
If (categorydata. getcateval (I, false) = currcate)
Out. Print ("selected ");
% >>>< % = Categorydata. getcatename (I, false). substring () %>
</Option>
<%
}
%>
</SELECT>