Today, I encountered a problem that has not been solved successfully yet. Is it because struts is not perfect in the tag library. For example, if a Courseware list is displayed on the page, you can operate the data in the last column, as shown below:
Code |
Name |
Author |
OP |
10000001 |
Wind tunnel model Courseware |
Liu jindong |
View edit Delete |
10000002 |
Karman vortex Courseware |
Ji Mingyi |
View edit Delete |
10000003 |
Complex Function Courseware |
Qin Jiang |
View edit Delete |
10000004 |
Audio Courseware |
Guo changkai |
View edit Delete |
Now, if you want to press delete, a confirmation box is displayed, prompting "are you sure you want to delete the wind tunnel model courseware". You can choose to confirm or cancel the courseware. "Whether to delete" is defined in the resource file (prompt. confirm. delete = Are you sure you want to delete {0}). "Wind Tunnel model courseware" is the courseware name and the courseware bean name is "ware ". If it is written as HTML, it is:
< A href = " " Onclick = " Return confirm ('Confirm to delete the wind tunnel model courseware ') " > Delete </ A >
However, because the information is dynamic, there is a problem. Because the onclick = "... "," <% "must be followed by the first single quotation mark before it can be correctly parsed, that is, it cannot be written as onclick =" Return confirm ('<% = STR %> ')". Therefore, there are two ways to implement the required functions:
1. Use the <A> tag of HTML directly without <HTML: link>:
< BEAN: Define ID = " Todel " Name = " Ware " Property = " Name " Type = " String " />
< A href = " Delete. do? Code = <Bean: write name = " Ware " Property = " Code " /> "
Onclick = " Return confirm ('<Bean: Message key = " Prompt. Confirm. Delete " Bundle = " Root " Arg0 = " <% = Todel %> " /> '); " >
< BEAN: Message key = " Course. List. Op. Delete " />
</ A >
2. Use <HTML: link> to define a script function with only one parameter in advance,CodeAs follows:
< Script Language = " Javascript " >
<! --
Function Confirmdelete (STR ){
Return Confirm (' < BEAN: Message key = " Prompt. Confirm. Delete " Bundle = " Root " Arg0 = " '+ STR +' " /> ');
}
-->
</ Script >
Then, write the following code at the place where the link is deleted:
< BEAN: Define ID = " Todel " Name = " Ware " Property = " Name " Type = " String " />
< HTML: link action = " /Delete " Paramid = " Code " Paramname = " Ware " Paramproperty = " Code " Onclick = " <% = " Return Confirmdelete ( ' "+ Todel +" ' ); " %> " >
< BEAN: Message key = " Course. List. Op. Delete " />
</ HTML: Link >
Both methods can achieve the goal. I have used 2nd types of usage for the moment. After allProgramDirectly use the <A> tag in JSP. After reading the struts document, it seems that only the <Bean: Message> tag can convert {0} in the resource to the actual content. In fact, if there is a way to make <Bean: message> it is easy to put the obtained content into a bean .......
In addition, I have not studied the El tag library and do not know if it will help.