Best Practices for Developing GWT and CSS

How can we effectively develop an application with the involvement of an external CSS developer in designing the site's look and feel?

Our goal is to seamlessly integrate CSS files created by the external developer into our site over multiple iterations without requiring the development team to manipulate the files directly. The GWT documentation presents four potential approaches:

  1. Using a tag in the host HTML page.
  2. Utilizing the element in the module XML file.
  3. Incorporating a CssResource within a ClientBundle.
  4. Using an inline element in a UiBinder template.

While the documentation recommends approaches 3 and 4 for modern applications, we find them to be somewhat intrusive to the development process. We are considering approach 2, where we hand code the CSS classes to easily update CSS files without developer intervention. Although this approach may sacrifice obfuscation and require some management of CSS name changes, it seems like the most practical option for us. Are there any other factors we should consider?

What is the best practice for developing GWT applications with external CSS designers involved?

Answer №1

One potential challenge arises when you are working with a team that lacks proficiency in both HTML/CSS/JS and GWT/Java. Ideally, you should aim for a team of experts. In that scenario, you can benefit from the CSS GWT advantages, such as:

  • Avoiding string literal class name references
  • Preventing CSS namespace conflicts/pollution
  • Minimizing CSS classes (by compressing selectors and properties)
  • Optimizing CSS rules through compiler optimization (combining similar rules, excluding unused ones)
  • Performing compiler time checks for CSS validity and missing classes
  • Avoiding a heap of external CSS files
  • Avoiding issues when running DevMode in remote mode (preventing the browser from fetching remote CSS instead of the new CSS being worked on)

In my opinion, the most effective approach to achieve these benefits is by using UiBinder along with the corresponding Java class, both consolidated in one place. Refer to the example below. This method, in my experience, results in a robust, compressed, efficient, reliable application without adding extra files.

Consolidation in one place facilitates:

  • Defining CSS within UiBinder where it is utilized
  • Defining CSS interfaces in the Java file where they are used

Widget

class MyClass extends Widget {
    ... // Java UI binder class

    public interface MyStyle extends CSSBundle {
        String someClassName();
    }

    @UiField
    MyStyle style;

    ...
    something.setClassName(style.someClassName());
    ...
}

UiBinder

<!-- UiBinder File -->
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'>

    <ui:style type='com.my.app.MyFoo.MyStyle'>
        .someClassName { background-color:pink; }
    </ui:style>

    <div class='{style.someClassName}'>Sample text.</div>

</ui:UiBinder>

If you're interested, I have previously addressed a similar question here.

Answer №2

Finding the ideal approach can be quite challenging as each of the four different methods have their strengths in various scenarios. Your usage of GWT will ultimately dictate which option is the most suitable.

If your team consists of individuals proficient in A) Java and B) CSS/HTML exclusively, options 1 or 2 would be a good fit. However, if there is a UX expert who grasps the connection between GWT and CSS/HTML/XML (i.e. UiBinder), they may know how to optimize UiBinder setup to enhance the capabilities available to the Java specialists.

The combination of UiBinder and ClientBundle introduces an added layer of complexity to the project. While this brings about numerous benefits, if your team is not well-aligned, it could potentially lead to more harm than good.

A "Best Practice" might involve structuring a primary CSS file (utilized through ClientBundle or options 1 or 2) in a manner that ensures consistency across the entire application, alongside incorporating specific styling in UiBinders for localized elements.

For comprehensive utilization, focusing on leveraging UiBinder and CssResource/ClientBundle to the fullest extent can be beneficial (including utilizing external CssResource/ClientBundle assets and granting programmatic access to UiBinder styles).

External resources can be utilized for increased reusability and enhanced consistency.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Sending a list of custom objects including images via AJAX to a REST API in a Spring Boot application

Encountering a problem with an Ajax call when passing a List of custom objects with images to a REST API in Spring Boot. Below is a snippet of my code. Controller @PostMapping(value = { "/test/saveUser" }, consumes = { "multipart/form-data& ...

What's the process for browsers to render the 'span' element?

<p> <span>cancel</span><span>confirm</span> </p> <hr> <p> <span>cancel</span> <span>confirm</span> </p> Both should display the same result. However, in the ...

What is the most effective approach to seamlessly conceal and reveal a button with the assistance

I have two buttons, one for play and one for pause. <td> <?php if($service['ue_status'] == "RUNNING"){ $hideMe = 'd-none'; } ?> <a href="#" class="btn btn-warning ...

Implement CSS Hover functionality even when the element is concealed through JavaScript

My website features a menu with headings and submenus. The issue arises when users hover over the headings - the submenus fail to show up. Additionally, after clicking on an item in the submenu, the submenu should be hidden using Javascript. However, the h ...

I am having difficulty retrieving all the cssRules for certain pages

Attempting to retrieve all CSS rules using JavaScript has yielded varying results. For instance, on StackOverflow, the code used is: console.log( document.styleSheets[1].href,'rules', document.styleSheets[1].cssRules,'Should be css rules, ...

The Distinction between withArray and putArray in Jackson JSON

While making updates to the JSON using JACKSON databind, I came across two methods - "withArray" and "putArray", but I can't seem to find any difference between them. Can someone please explain the distinction between these two methods? ((ObjectNode) ...

Adjusting the size of tables in raw JavaScript without altering their positioning

I am attempting to adjust the size of a th element without impacting the position of the next th in the row. Specifically, I want the width of the th to influence the width of the next th accordingly, rather than pushing it to the left. Below is the code ...

Determine the difference between a CSS selector string and an XPath string

Developing a compact querying module (using js) for html is my current project, and I aim to create a versatile query(selector) function that can handle both css selectors and XPath selectors in string form. My dilemma lies in determining whether a given ...

Utilize CSS to style Hover effects

Can someone please assist me with this issue? I am having trouble getting the CSS to work for my hover effect. I suspect that there might be a problem with my syntax. Here is the HTML code: <div id="horizontalmenu"> <ul> <li><a h ...

Creating a responsive HTML5 webpage that adjusts seamlessly to all screen sizes without the need for scrolling

I have developed an HTML5 application for mobile devices. Currently, I have managed to address width-height issues by using a simple scroll feature when necessary. However, I have encountered a challenge with a particular page that contains a lot of conten ...

Using the max-width property with Semantic UI Dropdown in ReactJS

I'm struggling to determine how to adjust the max-width of the Dropdown element in ReactJS. I attempted the following: .Menu Dropdown { max-width: 5rem !important; } Unfortunately, this did not work as expected. The dropdowns are taking up too m ...

Exploring the world of sass with compound mathematical statements

There's a slight issue that I'd like to circumvent. $var: 30px; font: 25px/25px font,font,font; //Works font: ($var - 5)/($var - 5) font, font, font; //Works not font: ($var - 5px)/($var - 5px) font, font, font; //Works no ...

Is there a way to move the bootstrap carousel item captions outside of the image without having to set a specific height for the carousel manually?

<div id="carouselExampleIndicators" className="carousel slide" data-bs-ride="true"> <div className="carousel-indicators"> <button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="0" className="active" ...

Encasing words within a cell of a table

My goal is to ensure that the table width remains fixed and unaffected by long text strings. Even though I have PHP code in place to limit characters at 100 per cell, I want to guarantee that a lengthy text string will never expand the table beyond its set ...

The wrapper is failing to extend the full height of the entire page

Initially, I thought setting the height of my wrapping div to 100% would be a quick task that I could complete in five minutes. However, it ended up taking me hours, so now I'm here hoping someone can assist me with this commonly asked question. The ...

Issue with fixed positioning not behaving as intended while scrolling downwards

I am facing an issue with an element that has the .it class and I want to keep it fixed on the screen using the position: fixed CSS property. However, as I scroll down the page, the element moves along with the screen instead of staying in place. Below is ...

Is there a way to customize Firefox's default styles similar to Chrome's?

Can you change the default styles of Firefox to match those of Chrome? ...

Interacting with an image icon using Selenium WebDriver

I'm facing a dilemma at this juncture, where I need to click on a specific image icon to expand the selection. Here's the HTML code for that: <table role=“presentation” class=“x-grid3-row-table” border=“0” cellspacing=“0 ...

Is there a way to deactivate specific options within the "Select" component on Material-UI, similar to how it is done in the "Autocomplete" feature?

Is it possible to restrict certain options in the Select component similar to how it is done in the Autocomplete component? PS: The options are present in an array. <FormControl variant="outlined"> <InputLabel>States</Inp ...

Is there a way to prevent Mac users from using the back and refresh buttons on their browser?

There seems to be a common trend of disabling the back button or refresh button on Windows using JS or Jquery to prevent F5 from working. Can this same method be applied to CMD+R on Mac computers? ...