Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 3663

White spaces are getting ignored from AngularJS application to Restful Java Service

$
0
0

In this question (why white space are getting ignored in AngularJS application) I found the way to not trim the strings from a input in Angularjs, to keep the white spaces in the text.

However, when the string is sent by attributte to a restful service in JAVA, the white spaces are gone.

How can I prevent this...?

This is the input on the view:

<md-input-container><label>Description</label><input type="text" md-auto-focus show-focus="true"            ng-model="$ctrl.search.description" capitalize           ng-trim="false"           ng-keyup="$event.keyCode == 13 ? $ctrl.searchText() : false"></md-input-container>

The searchText() function in the controller:

vm.searchText = function () {    var search = vm.search;            ItemSvc.search(search).then(function (result) {                    if (!result.state) {            return false;        }        return true;    });}       

The ItemSVC file:

    searchText: function (item) {        var deferred = $q.defer();        var result = $http.get('http://localhost:8080/wsTestify/api/searchText', {headers: item}).then(function (result) {            return result.data.result;        }).catch(function (error) {            console.log(error);            return {state: false, message: 'Service error'};        });        deferred.resolve(result);        return deferred.promise;    },

And lastly, the resful service in JAVA:

@Path("/item")public class ItemService {@Path("/searchText")@GET@Produces(MediaType.APPLICATION_JSON)public Response SearchText(@HeaderParam("description") String description) {    try {        // Here the text loses the white spaces at the end        // example if I type "HELLO ", here becomes "HELLO"        String text = description;

Thanks in advance.


Viewing all articles
Browse latest Browse all 3663

Trending Articles