Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As far as I know it is not possible to change the uibinder template during runtime (since it is compiled into javascript at compiletime and not accessible anymore at runtime).</p> <p>You will probably have to manually change the colors in your gwt code (= in java files, not in .xml files).</p> <p><strong>Straight forward:</strong></p> <ol> <li>create database-structure for storing your color information</li> <li>create server code to get colors from database</li> <li>implement gwt-service (and async interface and servlet implementation class) to deliver color information to the client</li> <li><p>implement gwt client code, which asks for the color information and then sets the colors for your gwt-components. You can do it like this (use camel case as descriped at <a href="http://www.francoismaillet.com/blog/?p=68" rel="nofollow">http://www.francoismaillet.com/blog/?p=68</a> ):</p> <p>widget.getElement().getStyle().setProperty("background", colorValueFromDatabase);</p></li> </ol> <p>Of course this solution is pretty unhandy when a lot of widgets have to be changed.</p> <p><strong>Alternative 1:</strong></p> <p>Implement a plain old Java Servlet (without gwt), which can provide a css file (a standard servlet, that loads color data from database and returns that colors as css definitions to the browser). Use a link to that Servlet in your gwt-html starting page.</p> <pre><code>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 { // you somehow have to get your user's information out of the session User user = (User) request.getSession().getAttribute("loggedInUser"); PrintWriter writer = response.getWriter(); // use saved color values and generate css writer.append(".header {"); writer.append(" background: " + getHeaderColorForUser(user) + ";"); writer.append(" padding: 6px 6px;"); writer.append(" }"); writer.append(" .anothercssclass {"); writer.append(" background: " + getAnotherCssClassColorForUser(user) + ";"); writer.append(" padding: 6px 6px;"); writer.append(" }"); // finish request writer.close(); response.setStatus(HttpServletResponse.SC_OK); } private String getAnotherCssClassColorForUser(User user) { // TODO Auto-generated method stub return null; } private String getHeaderColorForUser(User user) { // TODO Auto-generated method stub return null; } } </code></pre> <p>Problem with this alternative is, that you cannot instantly refresh the color information. The user has to reload the page to see changes in his color styles.</p> <p><strong>Alternative 2:</strong></p> <p>Use javascript (native code) to dynamically change your css configurations.</p> <pre><code>// in java code: changeCssStyle("header", "background", colorFromDatabase); </code></pre> <p>and </p> <pre><code>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); } } } }-*/ ; </code></pre> <p><strong>Conclusion</strong></p> <p>Three workarounds for your problem, non of them is really a solution - but hopefully it helps you implementing your code. Good luck!</p> <p>PS: my code is untested...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload