1

Hello I have a school project where we created webmethods using web service with an ordinary .asmx file.

The programs I made in .Net C# have no problem with the return being a List<Project>. However, I try to get the Java to work, and I tried Object[][] = wws.SelectAllProject() and so forth.

Here's the webmethod:

  [WebMethod]//Ska vara collection
    public List<Project> SelectAllProjects()
    {
        Controller contr = new Controller();
        List<Project> project = contr.SelectAllProjects();
        return project;
    }

Here's the Project.cs file:

public class Project
{
public string pId { get; set; }
    public string pName { get; set; }
    public string pDescript { get; set; }

    public Project()
    {
        this.pId = pId;
        this.pName = pName;
        this.pDescript = pDescript;
    }
}

So in Java how shall I call the method? I can call my other methods that are void which are ADD/Remove project...

public void SelectAllProjects () {
    WebService webService = new WebService();
    wws = webService.getWebServiceSoap12();
    //Anropar webservice och får en Collection av Project
    String[] columnNames = {"Project ID:", "Project Name:", "Project Description:"};
    Object[][] = wws.selectAllProjects();
    //Array[]test = wws.selectAllProjects();
}

Now I want to return something from this method (it should not be void) that which I can use to fill out a JTable in my view class (using MVC). The webmethod you see and returns a list of project. How shall I make this in Java? Tried googling, but I don't seem to find anything that is close to my project.

Thanks.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
Thomas S
  • 21
  • 1
  • 1
  • 5

1 Answers1

2

Compose your TableModel with a reference to your List<Project>, and use the model to construct your JTable. For example, your table might display two of the three project attribtes, and your row count would rely on the list's size().

@Override
public int getColumnCount() {
    return 2;
}

@Override
public int getRowCount() {
    return project.size();
}

For reference, this example extends AbstractTableModel and illustrates an implementation of getValueAt() that uses a Map<String, String>. See also How to Use Tables: Creating a Table Model.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • this (linked example) Model is excelent I think – mKorbel Apr 25 '12 at 13:33
  • @mKorbel: Thanks to you, I have seen the virtues of `DefaultTableModel`, but I like the flexibility of choosing the data structure inside the `TableModel`. – trashgod Apr 25 '12 at 15:06