Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand ajax struts2 drop-down box assignment

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces you how to understand ajax struts2 drop-down box assignment, the content is very detailed, interested friends can refer to, hope to be helpful to you.

1. This code is suitable for all drop-down list values

two。 All the drop-down lists for a project need only this common method

Step 1: create an entity bean

The code is as follows:

Public class DictionaryBean {

Id of private String value_Id;// drop-down box option

The value of private String value;// drop-down box option

Private String flag;// corresponds to the value type of the drop-down box, such as flag=1, the drop-down list is provincial information, flag=2 is municipal information, and so on.

Public String getValue_Id () {

Return value_Id

}

Public void setValue_Id (String valueId) {

Value_Id = valueId

}

Public String getValue () {

Return value

}

Public void setValue (String value) {

This.value = value

}

Public String getFlag () {

Return flag

}

Public void setFlag (String flag) {

This.flag = flag

}

}

Step 2 write the following method to get listbean in your action. Listbean encapsulates bean.valueId and bean.value.

The code is as follows:

/ * *

*

* @ author ZhuangZi

* @ class com.hzdracom.action.DictionaryAction

* @ method listDictionary

* @ Directions Common method for getting drop-down list information

* @ date 2013-3-21 10:08:39 void

, /

Public void listDictionary () {

String json= ""

Try {

ListDictionary = dictionaryService.handleListDictionary (bean)

Json=JSON.toJSONString (listDictionary); / / convert to json string

HttpServletResponse response=ServletActionContext.getResponse ()

Response.setContentType ("text/html")

Response.setCharacterEncoding ("utf-8")

PrintWriter out

Out = response.getWriter ()

Out.println (json)

Out.flush ()

Out.close ()

} catch (Exception e) {

E.printStackTrace ()

}

}

Sturts.xml configuration Information

The copy code is as follows:

Step 3 encapsulates the common js code js file name dictionary.js

The code is as follows:

/ * *

* ↓

* author: ZhuangZi

* Class name: public method initialization

* function: public method initialization

* details: public method initialization

* version: 1.0

* date: 2013-03-22

* description:

* ↑

, /

$(function () {)

/ * 1. The drop-down box takes a value of ↓↓↓ * /

SelectBox ([

The code is as follows:

{id_: "# down_type", id: "# downtype", flag: "2"}

{id_: "# kuai_flag", id: "# kuaiflag", flag: "3"}])

/ / selectBox {[{id_: "ID of the selected value of your drop-down box", id: "ID of the drop-down box", flag: "Type of the drop-down box value"]}

The code is as follows:

/ / there is a {id_: "# kuai_flag", id: "# kuaiflag", flag: "3"} such an object has a drop-down box information

});

/ * *

* ↓

* author: ZhuangZi

* Class name: common method to get drop-down box value

* function: value of drop-down list

* details: load drop-down list

* version: 1.0

* date: 2013-03-22

* Note: if you add a new drop-down box, you need to add an object to the array list

* Parameter: id_: drop-down box ID;id of the selected value: drop-down box ID;flag: type of drop-down box value, that is, display content type

* ↑

, /

Function selectBox (list) {

For (var I = 0Llen = list.length; I < len; iTunes +) {

(function (bean) {

Var pageId=$ (bean.id_) .val ()

$.ajax ({

Type:'post'

Url:'../dictionary/listDictionary.do'

Data:'bean.flag='+bean.flag

DataType:'json'

Success:function (json) {

For (var iTuno; I < json.length;i++) {

$(bean.id) .append (""

+ json [I] .value + "")

If (pageIdbath = null & & pageIdbath = "" & & pageId== json [I] .value _ Id) {

$(bean.id) .find ("option") .attr ("selected", true)

}

}

}

Error:function () {

Alert ('error')

}

});

}) (list [I])

}

}

Step 4: hide the domain information under the page information, that is, the value that will be selected after you select a query

Introduction of js

The code is as follows:

The copy code is as follows:

Download type identification:

-all

Step 5 additional information the flag used by the following method in dao is the value passed by flag in js

The code is as follows:

Public List handleListDictionary (DictionaryBean bean) throws DataAccessException,Exception {

List list = new ArrayList ()

Try {

String sql= ""

/ * get the page drop-down list * /

If (bean.getFlag () .equals ("1")) {

Sql = "SELECT PAGE_FLAG VALUE_ID,PAGE_NAME VALUE FROM YHAO_PORTALS_PAGE"

}

/ * get the download type ID drop-down list * /

If (bean.getFlag () .equals ("2")) {

Sql = "SELECT DOWNTYPE_FLAG VALUE_ID,DOWNTYPE_NAME VALUE FROM YHAO_PORTALS_DOWNTYPE"

}

/ * get the drop-down list of block identities * /

If (bean.getFlag () .equals ("3")) {

Sql = "SELECT KUAI_FLAG VALUE_ID,KUAI_NAME VALUE FROM YHAO_PORTALS_KUAI"

}

List = this.query (sql,new DictionaryList ())

} catch (Exception e) {

E.printStackTrace ()

}

Return list

}

On how to understand the ajax struts2 drop-down box assignment to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

  • How to judge browsers by conditional comments

    This article focuses on "how to use conditional comments to judge browsers". Interested friends may wish to take a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how to use conditional comments to judge browsers!

    © 2024 shulou.com SLNews company. All rights reserved.

    12
    Report