A routine mode of extjs + struts2

Source: Internet
Author: User
In fact, in the combination of struts2 and extjs, We can summarize some excellent routine modes, such as in struts2.

How to display the returned data in extjs on the front end can be sorted in the following way:

For example, a struts2 action returns a list of photos in the album, such

<Action name = "getphotos"

Class = "getphotosaction">

<Result name = "success">/WEB-INF/photos. jsp

</Result>

</Action>

In photos. jsp, you can do this:

<% @ Page Language = "Java" contenttype = "text/html; charset = UTF-8"

Pageencoding = "UTF-8" %>

<% @ Taglib prefix = "S" uri = "/Struts-tags" %>

[

<S: iterator id = "photo" value = "Photos" status = "status">

{ID: '<s: property value = "# photo. ID "/> ', name:' <s: property value =" # photo. filename "/> ', filename:' <s: Property

Value = "# photo. filename "/> ', userid:' <s: property value =" # photo. userid "/> ', albumid:' <s: property value =" # photo. albumid "/> '}

<S: If test = "# status. Last = false">

,

</S: If>

</S: iterator>

]

It is used for struts2 + extjs nesting. It will actually generate:

[{ID:..., name:, },{ ID: 333,... Name: XXXX}] JSON format data

In ext JS components, you can use the following:

Function getimagedataview ()

{

Imagedataview = new Ext. dataview (

{

Itemselector: 'div. Thumb-wrap ',

Style: 'overflow: auto ',

Multiselect: True,

ID: 'imagedataview ',

Store: getphotosjsonstore (),

TPL: New Ext. xtemplate (

'<TPL for = "."> ',

'<Div class = "Thumb-wrap" id = "{name}"> ',

'<Div class = "Thumb"> </div> ',

'<Span> </div>', '</TPL> ')

});

Store: getphotosjsonstore (),

This is the thing:

Function getphotosjsonstore ()

{

Return new Ext. Data. jsonstore ({

URL: 'getphotos. Action? Albumid = '+ albumid,

Autoload: True,

ID: 'name ',

Fields: ['id', 'name', 'filename', 'albumid']

})

}

You can see the JSON format returned by the server. In Ext, {filename} can be nested into extjs.

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.