Results 1 to 2 of 2
  1. #1
    nel636 is offline Member
    Join Date
    Nov 2008
    Rep Power

    Default Adding recieved items to Server repository.

    Hi guys,

    My first post here.

    Was hoping someone could give me advice on some coding im trying to do for uni.

    To give you an overall view: im trying to create a little inventory program where there is a server interface and a client interface. Now on the client interface it displays a menu with several options and the server interface displays whats in the repository. Upon choosing one of those options it sends the appropriate method request to the server handler. What im trying to do is add a function where i can dynamically add items to the repository. This is already in place from the code i have from uni using the server.put class and method. however i cant seem to add them to it

    I have botched together this method which *i think* will add new items to the repository:

    Java Code:
    public String addItem(){
        String serialNo = (String) receive();
        String description = (String) receive();
        Integer stock = (Integer) receive();
        String location = (String) receive();
        //String dateTime = (String) receive();
        //creates new stockitem from stockitem class
        StockItem item = new StockItem(serialNo, description, stock, location) ;
        // creates new serial number
        serialNo = new Integer(server.getReposSize() + 1).toString();
        //Must make item code unique to this client
        serialNo = serialNo + this.hashCode();
        while (server.exists(serialNo)){
        serialNo = new Integer(server.getReposSize() + 1).toString();
    server.put(serialNo, item);
    return "Item added";
    Now on the client side i have added code to send the serialno, description,stock and location. Shown below:

    Java Code:
    // This adds new item
          if (choice.equals("n")){
            //Add new Item
            send("addItem"); // remote method
            //Send Serial Number
            System.out.println("Item Serial no.\t");
            String serialNo = getString();
            send (new Integer(serialNo));
            // send description
            System.out.println("Item Description\t");
            String description = getString();
            send(new String(description));
            //Send No. of STock
            System.out.println("No. Of Stock\t");
            String stock = getString();
            send (new Integer(stock));
            // send Item Location
            System.out.println("Item Location\t");
            String location = getString();
            send(new String(location));
            send(getDateTime());         //Time of transaction
            System.out.println(receive());      //Find out the status of our command

    So by my understanding that should send the values input by the user.

    But my problem is how do i insert the data sent by the user into the server repository?

    As you can see from the first "additem" method there is a "server.put" which relates to a method in the server class which adds things to the repository. ive looked in the server class and noticed the put method has only two objects. Originally i was trying to fit the 4 objects (serial description,location and stock) in there but as you can see from my first method i have tried inserting just two of these and they still dont show in the server interface.

    Any idea's on this? SOrry if im vague im not too familar with the correct terminology im still getting the hang of it all!


  2. #2
    nel636 is offline Member
    Join Date
    Nov 2008
    Rep Power


    ANyone at all? im pretty stumped with this thats all? is there anything im doing wrong?

    Here is the code for the put method from the server class too:

    Java Code:
         * Adds an item to the repository.
         * @param key   a unique key that identifies this object
         * @param item  item to add to the repository
      public synchronized void put(Object key,Object item){
    Thanks guys.

Similar Threads

  1. Creating a SWT table with 1,000,000 items
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-11-2008, 05:31 PM
  2. Display items in the JCombo Box
    By eddy001 in forum AWT / Swing
    Replies: 1
    Last Post: 01-21-2008, 01:27 AM
  3. Replies: 0
    Last Post: 01-04-2008, 10:34 AM
  4. Adding items to a jComboBox
    By tronovan in forum New To Java
    Replies: 0
    Last Post: 08-08-2007, 09:48 AM
  5. hyperlinks from menu items?
    By asterope118 in forum New To Java
    Replies: 1
    Last Post: 07-16-2007, 02:49 PM

Posting Permissions

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