开发者

Country name with space not accepted in BlackBerry ObjectChoiceField

I am developing a registration page in BlackBerry app. I am sending all the fields entered to the local server.Country is one of the form fields and is in a ObjectChoiceField. Whenever user selects a country having more than one word for ex: United States of America, it says sign up failed. When user selects country with single name, registration is always successful.Can anybody guide开发者_运维问答 me how can I make the ObjectChoiceField accept the spaces or remove the spaces in the country?


There is no problem in ObjectChoiceField. For example if you want to send the Value like "Black Berry" you must send it to the web service like "Black%20Berry". Because %20 takes the space character. So after you are taking the value form ObjectChoiceField means......

ar[obchfield.getSelectedIndex()];// this is your value say for example:"Black Berry".

Take this below code in seperate Classname Utility.java:

public class Utility {
public static String escapeHTML(String s){
    StringBuffer sb = new StringBuffer();
    int n = s.length();
       for (int i = 0; i < n; i++) {
          char c = s.charAt(i);
          switch (c) {
             case ' ': sb.append("%20"); break;
             default:  sb.append(c); break;
        }
    }
    return sb.toString();
}}

Then do like this:

Utility.escapeHTML(ar[obchfield.getSelectedIndex()]);//converts the "Black Berry" to "Black%20Berry".

then it returns a String like: "Black%20Berry" and send it to server. Enough. Your problem is solved.

If you have any doubt come on StackOverFlow chat room name "Life for Blackberry" to clarify Your and our doubts.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜