Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

RESTful table javabean->json conversion doesnt work

Arthur
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 15, 2013

Hi,

I'm trying to get the aui-restful table working for my gadget plugin, to have a nice ui.

Unfortunately I found out that my @POST-annotated create() methods provided Javabean parameter is always empty.

This is my ajs.restfulTable part of config.js where the AUI table is set up:

new AJS.RestfulTable({
        autoFocus: true,
        el: jQuery("#config-fields-table"),
        allowReorder: true,
        resources: {
            all: baseUrl +"/rest/otrs-config/1.0/alltickets",
            self: baseUrl +"/rest/otrs-config/1.0/ticketfield"
        },
        columns: [
        {
            id: "fieldname",
            header: AJS.I18n.getText("common.words.name")
        },
        {
            id: "colname",
            header: AJS.I18n.getText("common.words.description")
        }
        ]
    });

And here is the Serverside Java Beanclass:

@XmlRootElement
    @XmlAccessorType(XmlAccessType.FIELD)
    public static final class TicketField {

        @XmlElement
        private Integer id = 0;
        @XmlElement
        private String fieldname = "";
        @XmlElement
        private String colname = "";

        public String getColname() {
            return colname;
        }

        public void setColname(String colname) {
            this.colname = colname;
        }

        public String getFieldname() {
            return fieldname;
        }

        public void setFieldname(String fieldname) {
            this.fieldname = fieldname;
        }

        public Integer getId() {
            return id;
        }

        public void setId(Integer id) {
            this.id = id;
        }
        
        @Override
        public String toString(){
            return "id: "+id+" fieldname: "+fieldname+" colname: "+colname ;
        }
    }

...and finally the create() Method:

@POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    public Response create(final TicketField bean) {

        logger.error("created ticketfield:"+bean);

        return Response.ok(transactionTemplate.execute(new TransactionCallback() {

            @Override
            public Object doInTransaction() {
                PluginSettings settings = pluginSettingsFactory.createGlobalSettings();
                List<TicketField> fields = findAllTicketFields();

                bean.setId(createTicketFieldID());
                if (fields.contains(bean) == false) {
                    fields.add(bean);
                }

                settings.put(fieldsListKey, fields);
                return bean;

            }
        })).build();
    }

Does anyone see what am I doing wrong??

Thanks in advance

4 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Arthur
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 26, 2013

I found the answer, and it's disappointing: The post request is empty!! https://answers.atlassian.com/questions/173421/restful-table-post-request-is-empty

0 votes
Arthur
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 15, 2013

Maybe I should show you the response of a GET /ticket/id Request:

Instead of something like '[{"id": 1, "colname": "age", "fieldname": "Age"}]'

I get something like '["de.package.path.to.resource.class.TicketResource@TicketField_345234sdf"]'

0 votes
codelab expert
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 15, 2013

Try to change

public static final class TicketField

to

public class TicketField

Arthur
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 15, 2013

why should I change this? I have many other REST classes that are marked as final, and it works with them. And in the official Documentation, the classes are also marked as final. see https://developer.atlassian.com/display/AUI/RESTful+Table

0 votes
Arthur
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 15, 2013

Forgot to mention the output of the log-statement:

" /rest/otrs-config/1.0/ticketfield [acocon.jira.otrs.rest.TicketFieldsResource] created ticketfield:id: 0 fieldname: colname: "

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events