Results 1 to 8 of 8
  1. #1
    mario_tim is offline Member
    Join Date
    Mar 2011
    Posts
    8
    Rep Power
    0

    Default Suggestions return all

    Hi,

    I have RPC SuggestBox, but unfortunately it return me all data from server side instead of required. And also I wanted to convert returned result into array and fetch into labels inside ScrollPanel, what's problem?

  2. #2
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    we don't know the problem without looking at your code for the suggestbox.

    as for converting returned result into an array, that also depends on the return Type of the suggestbox.

    fetching into labels is easy,
    myLabel.setText(returnResultArray[index]);

  3. #3
    mario_tim is offline Member
    Join Date
    Mar 2011
    Posts
    8
    Rep Power
    0

    Default

    Java Code:
    public class ItemSuggestionOracle extends SuggestOracle {
        public static final RPCSuggestAsync rpcService = RPCSuggest.App.getInstance();
        public boolean isDisplayStringHTML() {
               return true;
           }
    
           public void requestSuggestions(SuggestOracle.Request req,SuggestOracle.Callback callback) {
               rpcService.getQuote(req, new ItemSuggestCallback(req, callback));
           }
    
           class ItemSuggestCallback implements AsyncCallback {
    
               private SuggestOracle.Request req;
               private SuggestOracle.Callback callback;
    
               public ItemSuggestCallback(SuggestOracle.Request _req,
                       SuggestOracle.Callback _callback) {
                   req = _req;
                   callback = _callback;
               }
    
               public void onFailure(Throwable error) {
                   callback.onSuggestionsReady(req, new SuggestOracle.Response());
               }
    
               public void onSuccess(Object retValue) {
                   callback.onSuggestionsReady(req,
                           (SuggestOracle.Response) retValue);
               }
           }
    }
    Java Code:
    public class ItemSuggestion implements IsSerializable, SuggestOracle.Suggestion {
    
          private String s;
          // Required for IsSerializable to work
          public ItemSuggestion() {
          }
    
          // Convenience method for creation of a suggestion
          public ItemSuggestion(String s) {
             this.s = s;
          }
    
          public String getDisplayString() {
              return s;
          }
    
          public String getReplacementString() {
              return s;
          }
       } // end inner class ItemSuggestion
    Java Code:
    public interface RPCSuggest extends RemoteService {
        SuggestOracle.Response getQuote(SuggestOracle.Request req);
    and server side...
    Java Code:
    public class RPCSuggestImpl extends RemoteServiceServlet implements RPCSuggest {
         public SuggestOracle.Response getQuote(SuggestOracle.Request req) {
            SuggestOracle.Response resp = new SuggestOracle.Response();
            List<ItemSuggestion> suggestions=new ArrayList<ItemSuggestion>();
            for (int i=0;i<1000;i++)
            {
                Integer j=i;
                suggestions.add(new ItemSuggestion(j.toString()));
            }
    
            resp.setSuggestions(suggestions);
            return resp;
        }
    }

  4. #4
    mario_tim is offline Member
    Join Date
    Mar 2011
    Posts
    8
    Rep Power
    0

    Default

    Quote Originally Posted by ozzyman View Post
    we don't know the problem without looking at your code for the suggestbox.

    as for converting returned result into an array, that also depends on the return Type of the suggestbox.

    fetching into labels is easy,
    myLabel.setText(returnResultArray[index]);
    here I posted my code, so could you help me?

  5. #5
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    i'm surprised that you can't see why this would give you ALL data instead of the required data:

    Java Code:
            List<ItemSuggestion> suggestions=new ArrayList<ItemSuggestion>();
            for (int i=0;i<1000;i++)
            {
                Integer j=i;
                suggestions.add(new ItemSuggestion(j.toString()));
            }

    on the positive side, you're almost there. this is what your code says in English:

    Java Code:
    Make a new List to store our results //thats fine
    Loop 1000 items {
        add new ItemSuggestion to our List //adding items unconditionally not good
    }

    But this is what it should say in English:

    Java Code:
    Make a new List to store our results
    Loop 1000 items {
        if we find 'the right suggestion' or 'a match' {
            add it to our List
        }
    }

  6. #6
    mario_tim is offline Member
    Join Date
    Mar 2011
    Posts
    8
    Rep Power
    0

    Default

    Quote Originally Posted by ozzyman View Post
    i'm surprised that you can't see why this would give you ALL data instead of the required data:

    Java Code:
            List<ItemSuggestion> suggestions=new ArrayList<ItemSuggestion>();
            for (int i=0;i<1000;i++)
            {
                Integer j=i;
                suggestions.add(new ItemSuggestion(j.toString()));
            }

    on the positive side, you're almost there. this is what your code says in English:

    Java Code:
    Make a new List to store our results //thats fine
    Loop 1000 items {
        add new ItemSuggestion to our List //adding items unconditionally not good
    }

    But this is what it should say in English:

    Java Code:
    Make a new List to store our results
    Loop 1000 items {
        if we find 'the right suggestion' or 'a match' {
            add it to our List
        }
    }
    ok, I got advice very very useful, but sorry if my English not so correct, caused that is not my native, but what about parsing gettin results to arraylist, I know how use data from array list and paste it in labels, but there is problem for getting List<ItemSuggestions> instead of SuggestOracle.Response in server side

  7. #7
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    I am not so sure what you mean...

    but there is problem for getting List<ItemSuggestions> instead of SuggestOracle.Response in server side

    what do you want to do?

  8. #8
    mario_tim is offline Member
    Join Date
    Mar 2011
    Posts
    8
    Rep Power
    0

    Default

    I want to get array list, for further paste information from it to label
    but I get SuggestionList, which cannot be parsed, or I don't know how.

Similar Threads

  1. [suggestions] minesweeper
    By temyong in forum New To Java
    Replies: 7
    Last Post: 12-30-2010, 04:10 AM
  2. looks good looking for suggestions..
    By search4survival in forum New To Java
    Replies: 10
    Last Post: 11-30-2010, 01:59 PM
  3. Looking for suggestions
    By tonino in forum New To Java
    Replies: 5
    Last Post: 09-26-2010, 08:17 PM
  4. Book suggestions
    By Lil_Aziz1 in forum Java Applets
    Replies: 3
    Last Post: 01-04-2010, 03:38 AM
  5. any suggestions?
    By PureAwesomeness in forum New To Java
    Replies: 4
    Last Post: 01-19-2009, 08:34 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •