Country name with space not accepted in BlackBerry ObjectChoiceField

僤鯓⒐⒋嵵緔 提交于 2019-12-02 06:54:18

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/7538998/country-name-with-space-not-accepted-in-blackberry-objectchoicefield

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!