Use of new form flags for STRUS2

Source: Internet
Author: User

STRUTS2 provides us with a lot of cool form flags that simplify the work of our programmers. However, since these are new signs, there are still many questions about their use. This article will be on the friends of the reply, message or email on the questions, respectively, these cool signs to tell. Form flags using Tips

The form flag for Struts 2 uses the concept of a template in the output (render) HTML, adding complexity (since it is not like the Struts 1.x form flag, which is usually an element of a logo corresponding to HTML), you need some tricks when you use it:

The form flag for the UI flag of the Struts 2 defaults to the table layout, and the button is right-aligned. If you don't like this style, you can simply set the "theme" attribute of the <s:form/> flag to "simple" and then use the previous practice to layout the form elements (Note: This method has pros and cons, and the disadvantage is that when you set the "theme" attribute to "simple", Form flags output HTML in the simplest way, so you might lose some of the convenience of default output, such as a friendly error message display, or a client form validation, and so on. Of course, a better approach is to use CSS or custom themes (theme) and then apply to the entire application, so that you get a consistent page style, and enhance the user experience (I will explain this in future articles);

When you add some flags to the page (such as <s:doubleselect/>, etc.), you should access the page by action instead of directly through the *.jsp URL.

I'll tell you about these flags separately:

1, <s:checkboxlist/>

One of the biggest questions about <s:checkboxlist/> may be: "How do I select some of the checkbox by default?" ”

The answer is really simple, just set its "value" attribute to the value you want to select, as shown in the code:

<%@ page language= "java" contenttype= "text/html; charset=utf-8" pageencoding= "Utf-8"%>
<%@ Taglib prefix= "s" uri= "/struts-tags"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ""
<title>struts 2 Cool Tags- ; lt;s:checkboxlist/&gt;</title>
<s:head/>
<body>
<s:form action= "Store"
<s:checkboxlist name= "SKILLS1" "
label=" Skills 1 "
list=" {' Java ', '. Net ', ' RoR ', ' PHP '} '
value= ' {' Java ', '. Net '} '/>
<s:checkboxlist name= "skills2"
label= "Skills 2"
list= "#{1: ' Java ', 2: '. Net ', 3: ' RoR ', 4: ' PHP '} '
listkey= ' key '
listvalue= ' value '
value= ' {1, 2, 3} '/>
</S:FORM>
</body>

Listing 1 webcontent/checkboxlist.jsp

Distribute the application, type: http://localhost:8080/Struts2_CoolTags/checkboxlist.jsp in the browser, and the page appears as shown in the following illustration:

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.