Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
Search Coderanch
Advance search
Google search
Register / Login
Win a copy of
A Functional Approach to Java: Augmenting Object-Oriented Java Code with Functional Principles
this week in the
Functional programming
forum!
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Liutauras Vilda
Ron McLeod
Jeanne Boyarsky
Paul Clapham
Sheriffs:
Junilu Lacar
Tim Cooke
Saloon Keepers:
Carey Brown
Stephan van Hulst
Tim Holloway
Peter Rooke
Himai Minh
Bartenders:
Piet Souris
Mikalai Zaikin
Forum:
Java in General
Get the data for UI
S Roberts
Ranch Hand
Posts: 66
posted 8 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
i try to populate dropdownlist on gwt ui with data from tables in oracle database, and i have created following interfaces such a DataService
@RemoteServiceRelativePath("getData") public interface DataService extends RemoteService { String [] getGroupData(); }
and
public interface DataServiceAsync { void getChartGroupData(AsyncCallback<String[]> callback); }
and within DataServiceImpl class i implement this method for getting an array of data from db table:
public class DataServiceImpl extends RemoteServiceServlet implements GetDataService { @Override public String[] getChartGroupData() { // load application settings from file String config = "loader.properties"; Properties settings = new Properties(); InputStream configFile = DataServiceImpl.class.getClassLoader() .getResourceAsStream(config); if (configFile != null) { try { settings.load(configFile); } catch (IOException e) { e.printStackTrace(); System.exit(1); } } // connect to db DB connector = new DB(); Connection connection = null; try { connection = connector.connect( settings.getProperty("db.type"), settings.getProperty("db.connectURL"), settings.getProperty("db.user"), settings.getProperty("db.password")); } catch (ClassNotFoundException e) { e.printStackTrace(); System.exit(1); } catch (SQLException e) { e.printStackTrace(); System.exit(1); } String name = null; String[] nameArray = new String[] { name }; String query = "SELECT g.group_name " + "FROM " + Meta.GROUP_TABLE + " g "; PreparedStatement stmt = null; ResultSet rs = null; try { stmt = connection.prepareStatement(query); rs = stmt.executeQuery(); while (rs.next()) { Group group = new Group(); group.setName(rs.getString("GROUP_NAME")); name = group.toString(); } } catch (SQLException e) { e.printStackTrace(); } finally { try { rs.close(); stmt.close(); } catch (SQLException e) { e.printStackTrace(); } } return nameArray; }
in my gwt.xml file i wrote:
<servlet class="com.db.server.DataServiceImpl" path="/DataServiceImpl"/>
and in the web.xml
<servlet> <servlet-name>DataServiceImpl</servlet-name> <servlet-class>com.db.server.DataServiceImpl</servlet-class> </servlet> <servlet-mapping> <servlet-name>DataServiceImpl</servlet-name> <url-pattern>/app/DataServiceImpl</url-pattern> </servlet-mapping>
and then i write on the client side the asynccallback, to get all data from table in db in an array and then fill with it an dropdownlist on ui:
public class Application implements EntryPoint { private DataServiceAsync rpc; private ArrayList<String> list= new ArrayList<String>(); public void onModuleLoad() { UI ui = new UI(); RootLayoutPanel.get().add(ui); rpc = (DataServiceAsync) GWT.create(DataService.class); ServiceDefTarget target = (ServiceDefTarget) rpc; target.setServiceEntryPoint(com.google.gwt.core.client.GWT .getModuleBaseURL() + "getData"); AsyncCallback<String[]> callback = new AsyncCallback<String[]>() { public void onFailure(Throwable caught) { GWT.log("RPC error", caught); } @Override public void onSuccess(String[] result) { for(int i=0;i<result.length;i++) { UI.listBoxGroups.addItem(result[i]); } GWT.log("RPC success", null); } }; rpc.getGroupData(callback); } }
the data doesn't seem to be loaded, i can't get anything on my gwt gui on the dropdownlist. Any suggestions please, what i do wrong here?
Vijitha Kumara
Bartender
Posts: 4109
72
I like...
posted 8 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
In general this kind of issues best solved via narrowing down the issue at each layer, DB call, call to onSuccess() etc... Find out where you miss the data in first place, then
you should
be able to solve it easily.
SCJP 5 | SCWCD 5
[
How to ask questions
] [
Twitter
]
S Roberts
Ranch Hand
Posts: 66
posted 8 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
thank you for answering, but i can't understand what did you ment
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
GWT and Struts
Trying to correct methods to create paths using a database
getting Nulpointer in xml file parsing
Tomcat Server Running Status
element name and cdata
More...