jumbled css identifier while formatting in UiBinder

I am facing an issue with my GWT application where I am trying to display the selected row in a FlexTable. To achieve this, I have added a style to the specific row using the following code:

@UiField FlexTable productTable;
int row;
[...]
/* select row */
productTable.getRowFormatter().addStyleName(row, "row-selected");

However, when I add the corresponding style in my ui.xml file as shown below, it does not work properly:

ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui"
xmlns:u="urn:import:myapplication.client.ui">
<ui:style>
    tr.row-selected {
        background: #92C1F0;
    }
</ui:style>
<g:VerticalPanel>
    <g:ScrollPanel>
        <g:FlexTable ui:field="productTable" width="100%" height="100%">
        </g:FlexTable>
    </g:ScrollPanel>
</g:VerticalPanel>
</ui:UiBinder> 

Upon inspecting the styles using FireBug, I noticed that the name tr.row-selected is being transformed into something like: tr.GB1HWLGEI. This is causing the style to not be applied correctly.

I would like to know why this issue is happening and how it can be resolved effectively.

Answer №1

UiBinder utilizes the use of ClientBundle for styling with ui:style, so the guidelines and features of CssResource come into play.

As a result, your CSS class names will be encrypted (ensuring uniqueness to avoid conflicts with similarly named classes from other CssResources or external stylesheets).

In this scenario, you have the option to define a CssResource interface, declare the ui:style to extend that interface, and inject the instance into a @UiField; allowing you to utilize the obfuscated style within your addStyleName method; as demonstrated in http://code.google.com/webtoolkit/doc/latest/DevGuideUiBinder.html#Programmatic_access
Alternatively, you can incorporate @external within your ui:style to disable obfuscation for the CSS class; refer to http://code.google.com/webtoolkit/doc/latest/DevGuideClientBundle.html#External_and_legacy_scopes.

Answer №2

Encoded text is a great way to enhance security and optimize performance in the browser. It also adds an extra layer of protection against reverse engineering. Plus, you won't have to stress about conflicts with CSS namespaces.

To disable encoding during development, simply add the following line to your ModuleName.gwt.xml file:

<set-configuration-property name="CssResource.style" value="pretty" />

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

Automatically switch/animate CSS classes at defined intervals using jQuery

In the PHP code snippet below, three list items are generated and a CSS class "active" is added/removed on mouseover/mouseout. The JavaScript provided toggles the "active" class for all list items at once when moused over, but the requirement is to anima ...

What is the best way to set up my css in order to ensure that the height of a span aligns with the height of a nearby input field (specifically

Can someone help me fix this issue? https://i.sstatic.net/RyGML.png The span with the percent symbol is stretching to fit the input margin. How can I stop this from happening? I've already tried various CSS attributes but nothing seems to work in se ...

Enhancing React components with ellipsis and tooltips for text longer than two lines

Can a React component be developed to automatically add an ellipsis after two lines and display a tooltip only when the text is wrapped? I attempted to customize the Material UI's Typography component with the "noWrap" property and additional CSS, bu ...

Stop text from wrapping around the amazing fonts image

I am facing an issue with displaying an image using awesomefont character with text next to it. The problem is that I want the text to be right-justified beside the image instead of appearing below it. Despite trying different alignment codes and container ...

Give a radio button some class

<input id="radio1" type="radio" name="rgroup" value="1" > <label for="radio1"><span><span></span></span>1</label> <input id="radio2" type="radio" name="rgroup" value="2" > <label for="radio2"><span ...

Ensure that the mask implemented in the form input only shows two decimal places, while simultaneously retaining the original value

Is there a way to format a number in a form input so that it displays only two decimals while still retaining the original value? This is necessary to avoid incorrect values down the line and meets the customer's requirement of showing no more than tw ...

Toggle the visibility of a hidden div by clicking a button

After spending several days working on this project, just when I thought it was perfect, I had to completely restructure the entire page. Now I'm feeling stuck and in need of some help. The issue is that I have three images with buttons underneath eac ...

Positioning the modal toward the bottom across all screen sizes

In my current project, I am utilizing react-bootstrap modal. My goal is to position the modal at the bottom of all screen resolutions. While I have successfully achieved this by adjusting the CSS bottom property to -74% for 1080x1920 resolutions, the same ...

Positioning the CSS footer at the bottom of the webpage

I'm trying to keep a footer at the bottom of the page by setting a DIV with min-height:100% and another DIV for animating ajax content loads. Here is how I set it up in HTML: <div class="main"> <div class="header navi>…</div> ...

Col-*-Bootstrap does not function in the presence of col-*-*, even though it is expected to be the primary choice

UPDATE: The latest version of Bootstrap seems to be working fine for me. I'm currently developing a website using Bootstrap 4. I've noticed that col-xs-* has been deprecated in 4.0 and the default from 0px up is now col-*. I have specified "col ...

Adding a CSS style to specific sections of a string that is quoted in a Razor ASP.NET file

Is it possible to format a specific part of a string? I'm trying to only stylize the word within quotation marks. This is my cshtml code: { <div class="h-44 overflow-auto text-left mx-4 mb-4"> <p ...

Changing Tailwind CSS variables for customization

Using Variables in index.css : :root { --property: 1; } A Different Approach to Changing it with CSS on Hover: img{ transform: scale(var(--property));; } .another-element:has(:hover, :focus) { --property: 1.1; } There's a way to inclu ...

iPhone Bootstrap 4 navigation seamlessly overlays body content

This is the code I use for my website's navigation: <nav class="navbar navbar-expand-md navbar-light bg-light fixed-top" role="navigation"> <div class="container"> <a class="navbar-brand" href="/"> <img w ...

Centering Image and Media Body in Bootstrap's Media Object

Welcome to my first post on stackoverflow, hoping everything goes smoothly. I am struggling with aligning the content centrally and placing the images to the left and right of the center in 3 media objects. I have provided images of the current layout and ...

Moving from CSS to SCSS: Incorporating CSS files from npm packages - A Step-by-Step Guide

I am new to SASS and currently in the process of converting my existing project's CSS files to SCSS. I know that simply changing the extension to .scss will work for my custom files, but I'm not sure how to handle the dependency style files. I ty ...

Turn off Highlighting on a Website

I conducted an experiment similar to this: <div onclick="clickfunc(this)"> highlightME </div> <div> ooo blablabla highlightME ooo highlightME ooo highlightME ooo</div> <script language=javascript> function clickfunc(obj ...

When the height of a sibling element restricts the inner content and scroll bar due to the parent element's height being defined in vh

I'm currently working on creating a sidebar that occupies a fixed percentage of the viewport. Inside this sidebar, I want to have an element that remains fixed at the top while allowing the rest of the content to scroll if it exceeds the height of the ...

Instructions on implementing a floating label on a select2 dropdown menu

I am currently utilizing the select2 plugin for my select dropdowns on a webpage. I have multiple select dropdown boxes and I need to implement a floating label specifically for the selected dropdown. Despite my efforts and searches, I have not been able ...

What is causing the height:auto property to not function on these two elements?

I am facing an issue where the main-div and footer-div are not growing with the content as expected. While setting the height to auto works fine for the footer, it messes up the page for the main content. Specifically, the footer ends up taking over the en ...

modification of the tooltip's background shade on Google Maps

Currently, I am using Google Chart to display data for different countries. When hovering over these countries, a tooltip is displayed which fetches data from the backend. However, I would like to customize the background color of this tooltip as it is cur ...