As far as I know, changing the uibinder pattern at run time is not possible (since it compiles into javascript at compiletime and is no longer available at run time).
You will probably have to manually change the colors in your gwt code (= in java files, not in .xml files).
Straight ahead:
- create a database structure for storing color information.
- create server code to get colors from the database
- implement gwt-service (both the asynchronous interface and the servlet implementation class) to deliver color information to the client
implements a gwt client code that requests color information and then sets colors for your gwt components. You can do it like this (use the camel case as described at http://www.francoismaillet.com/blog/?p=68 ):
widget.getElement (). getStyle (). setProperty ("background", colorValueFromDatabase);
Of course, this solution is rather inconvenient when you need to change many widgets.
Alternative 1:
Deploy a simple old servlet (without gwt) that can provide a css file (a standard servlet that loads color data from the database and returns those colors as CSS definitions to the browser). Use the link to this servlet on the gwt-html start page.
import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class CssServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
The problem with this alternative is that you cannot instantly update color information. The user must reload the page to see the changes in his color styles.
Alternative 2:
Use javascript (native code) to dynamically change css settings.
// in java code: changeCssStyle("header", "background", colorFromDatabase);
and
private native void changeCssStyle(String cssClass, String cssName, String cssValue) /*-{ var children = document.getElementsByTagName('*') || document.all; var elements = new Array(); // iterate over ALL elements for (i in children) { var child = children[i]; var classNames = child.className.split(' '); for (c in classNames) { // does this element use our css class? if (classNames[c] == '.' + cssClass) { // now modify this element: set the attribute with name "cssName" to the value "cssValue" child.style.setAttribute(cssName, cssValue); } } } }-*/ ;
Conclusion
Three workarounds for your problem, but they are not a solution - but hopefully this will help you implement your code. Good luck
PS: my code is not verified ...
slartidan
source share