user2444474
user2444474

Reputation: 573

How to set the values to form bean?

I'm getting values from jsp page(struts) and form bean has getters and setters methods.I'm making ajax call, so that time i'm not getting any session values.So i would like to add those values when setting values to bean.Please look into below code , you will understand.

 private SearchFilters filters;

public SearchFilters getFilters() {
    return (SearchFilters) getSession().get("Filters");
}

public void setFilters(SearchFilters filters) {
      getSession().put("Filters",filters);
}

SearchFilters is class which have getters and setters for form fields.After getting session values from session and setting to for bean.Now , i need to add some of the values to bean here.

How to add those values here ?

jquery:

jQuery.ajax({
     type : 'GET',
     url : 'url',
     data : {"prodnbr" : $("#productsTextArea1").val()},
     dataType : 'json'

How to use with this ajax code ?

Upvotes: 0

Views: 1258

Answers (1)

Septem
Septem

Reputation: 3622

Assuming you're using jQuery, you can make ajax call as bellow to bind values to your SearchFilters

$.post('/url', {
        'filters.field1': 'value1',
        'filters.field2': 'value2'
    },     
    function(data){
        alert(data);
    }
);

--updated

another way for ajax call:

jQuery.ajax({
    type : 'GET',
    url : '/url',
    data : {
        'filters.field1': 'value1',
        'filters.field2': 'value2'
    }
);

Upvotes: 2

Related Questions