Non-form tag of UI tag in Struts2

Source: Internet
Author: User

Non-form tag of UI tag in Struts2

1. Non-form tags are mainly used to generate some non-form visualization elements on the page, such as Tab pages and output the tree structure of HTML pages. Of course, non-form tags also contain information encapsulated in the Action displayed on the page. The following are the main types of non-form tags:

A: generate a hyperlink ).

Actionerror: If the getActionError () method of the Action instance does not return null, the tag outputs series errors returned by the method.

Actionmessage: If the getActionMessage () method of the Action instance does not return null, the tag outputs the series of messages returned by the method.

Component: this label can be used to generate a custom component.

Div: This tag generates a div fragment.

Fielderror: if the Action instance has a form field type conversion error, validation error, this label is responsible for outputting the prompt information.

TabbedPanel: generate the Tab page of the HTML page.

Tree: generate a tree structure.

Treenode: A node that generates a tree structure.

 

 

2. below, use the preceding list of commonly used non-form tags:

(1 ). actionerror and actionmessage labels: These two labels have the same usage and function almost identical. They are all responsible for outputting the encapsulated information in the Action instance. The difference is that the actionerror tag outputs the getActionError () of the Action instance () the actionmessage label outputs the return value of the getActionMessage () method of the Action instance. These two tags do not have their proprietary attributes, so they are easy to use.

 

Next, attach an example to the actionerror and actionmessage labels. First, create a Struts2 project named MessageTest and create a MessageAction class. The Code is as follows:

Package com. gk. action; import com. opensymphony. xwork2.ActionSupport; public class MessageAction extends ActionSupport {public String execute () throws Exception {addActionMessage (the first action is a general message); addActionMessage (the second action is a general message ); addActionError (First action error message); addActionError (Second action error message); addFieldError (field1, first field error message); addFieldError (field2, second field error message ); return SUCCESS ;}}

 

Open the struts. xml file and configure the Action. The Code is as follows:

 

 
 
  
  
  
   
    /message.jsp
   
  
 

 

Create a message. jsp page with the following code:

<%@ page language=java import=java.util.* pageEncoding=utf-8%><%@ taglib uri=/struts-tags  prefix=s%><%String path = request.getContextPath();String basePath = request.getScheme()+://+request.getServerName()+:+request.getServerPort()+path+/;%>
> Output the general message of Action:
Output Action error message:
Output field error message:


Then deploy the project to the Tomcat server, enable the Tomcat server, and enter the corresponding address. The effect is as follows:

 

 

(2 ). component label: This label is used to use your own custom components. This is a very flexible usage. If you often need to use a certain effect segment, you can define this effect segment as a custom component, and then use the component label on the page to use this custom component.

 

Because custom components are managed based on themes and templates, you must specify the following three attributes when using the component tag:

~ Theme: The topic used by the custom component. If this attribute is not specified, the xhtml topic is used by default.

~ TemplateDir: Specifies the topic directory of the custom component. If this parameter is not specified, the system's topic directory, that is, the template directory, is used by default.

~ Template: Specifies the template used by the custom component.

Note: In addition, you can use the param sub-tag in the cmponent tag. The sub-tag indicates that additional parameters are input to the tag template. If you want to obtain this parameter in the template, it will always take the following form:

$ Parameters. paramname, or $ parameters ['paramname'].

Tip: Custom template files can be written using FreeMarker, JSP, and Velocity.

 

??

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.