Hey everyone, I’m exploring how to use a Google Sheets document as a makeshift database for my GWT project. I’ve noticed that while there is a Java library for Google APIs, it doesn’t seem to work with GWT because it relies on components that are unavailable on the client side.
Could someone explain whether I need to implement JSNI and use the JavaScript client, or if there’s a different method to connect GWT with Google Sheets? I’m planning on storing key-value pairs in the spreadsheet, but I’m also open to other suggestions or techniques that might work better.
Below is a sample of what I have in mind:
public class SheetManager {
private final String SHEET_CODE = "abc123";
public void addEntry(String key, String value) {
// Code to add data to the Google Sheet
}
public String fetchEntry(String key) {
// Code to get data from the Google Sheet
return "placeholder value";
}
}
I’ve worked on a similar project and found that handling sheets interactions from the client side can be problematic. Instead, I created a server-side component using Google App Engine. The server acted as an intermediary between the GWT client and Google Sheets, managing all API calls. This design allowed for easier error handling, improved security, and better management of API quotas. By shifting the heavy lifting to the server, the client could focus on a clean interaction pattern using simple AJAX calls, which resulted in a more maintainable and scalable solution.
yo john, using google sheets as a db for gwt is tricky. you’re right about the java lib not working client-side. jsni with the js client could work, but it’s a pain. have u considered using a backend service instead? it’d handle the sheets api calls and gwt could just hit that service. might be easier in the long run
Connecting GWT to Google Sheets directly isn’t straightforward. You’re correct about the Java library limitations. While JSNI with the JavaScript client is possible, it’s not ideal for maintainability. Consider implementing a server-side proxy using servlets or RESTful services. This approach allows you to handle API authentication securely and abstract the complexities of interacting with Google Sheets from your GWT client code. You could then use GWT-RPC or RequestFactory to communicate between your GWT frontend and the server-side proxy. This method provides better separation of concerns and allows for easier debugging and future scalability.