Loading style sheet(xhtml file), dynamically - java

I am trying to reload a style sheet (written in xhtml), dynamically.
To describe the scenario:
The application can be accessed by the user in multiple languages; First time when the application loads, a default file master-styles.xhtml is loaded, and now the user from some control screen can modify the language in which user wants to view the screen. Now at this point I want to load a different stylesheet for that specific language, scrapping the currently used stylesheet (master-styles.xhtml);
I am using JSF, richfaces for the UI components:
<html>
<head>
<sf:includeStyles />
<ui:insert name="globalStyles">
<ui:include src="/WEB-INF/flows/ui/core/resources/styles/master-styles.xhtml"/>
</ui:insert>
</head>
Is there a way to discard this file and load another file as part of my CSS; or is there an alternate way by which i can counter this problem?
Thanks.

If I understood your problem correctly, you need to dynamically load the page which is right now /master-styles.xhtml ,
You can set the page name in bean and then using this code you can dynamically load the style page needed
<ui:insert name="globalStyles">
<ui:include src="/WEB-INF/flows/ui/core/resources/styles/#{ThemeBean.stylePage}.xhtml"/>
</ui:insert>

There is indeed an alternate way to tackle this type of problem. Richfaces features skins, which allow you to change the appearance of all components at once. It also supports switching skins at runtime (e.g. so that a user can choose his/her own theme). More info on this feature is available on the Richfaces wiki, and the switching is covered in section 5.11.7, Changing skin in runtime

Related

JMesa style disappears when is child of <s:form>

I have an extrange case with JMesa..
When I'm doing tests without a form element as parent (to apply filters and pages) JMesa table is rendered.
But when I put the Jmesa element as form's child, the style disappears and is rendered as a basic table without colors or borders ._.
<fieldset>
<s:form action="listUsers">
<jmesa:tableModel id="test" items="${users}" var="bean">
<jmesa:htmlTable caption="${pageScope.caption}" width="100%">
<jmesa:htmlRow>
... Rows ....
</jmesa:htmlRow>
</jmesa:htmlTable>
</jmesa:tableModel>
</s:form>
</fieldset>
On head tags I have the css refered and jmesa/jquery.jmesa ..
Since the table renders with correct styles when not wrapped in a form tag but renders with no styling when it is inserted into the body of a form tag, my first thought is that there is a style somewhere at the form tag level that is causing the table styles to be lost or overridden. Another possibility is that if your CSS Selectors are configured with very specific parent/child relationships, the introduction of another tag could conceivably prevent styles from being applied.
Without more information as to what styles are present, the best suggestion I can offer is to use a tool that allows you to interactively assess your styles. Internet Explorer 8 has the Developer Tools feature. Conveniently, you can use a feature to click on an item on your Web page and it will load that element along with its styles. You can then analyze the styles or dynamically tweak styles to immediately see results.
I'd recommend loading the page that works and screen capturing the styles for the table when it looks good. Then you can do the same for when the styles are not being applied to the table and compare the two as a starting point to determining what's causing the difference.

How to avoid generating more HTML elements in Struts

When Struts(2)' UI tags are used, more HTML elements are generated automatically.For example, when defining <s:form ... > it includes form within a table(even though such table is not declared by us). So, if any CSS is used(lets say, a div tag is only used and located input elements according to the CSS), all elements are not viewed as expected because of auto generated elements and their postions. Even if the struts is allowed to generate such elements and we add CSS to them, then another weight must be bored to add css to design auto generated html elements because more elements are generated in various positions and sizes. Also as I feel, more html codes may effect the browser page loading time.
So is there a way to avoid generating such elements when struts UI tags are used
OR ELSE
is there a convenient way to work with CSS in Struts UI tags ? (I read a question in Stackoverflow and it had said for an answer that, to add css finally which the struts generated. But it is not that much easy when compare to normal jsp html designing level..)
In short Struts2 work on the concept of themes and it provides certain theme out of the box. Based on the theme selected it will generate some HTML code for the used tags when rendering the view.
Themes are really a very nice and beautiful concept of Struts2 and it even provides you the way to create a custom themes are per your requirement.
coming to your Question by default Struts2 use xhtml theme which means it will generate some HTML (which includes tables as name suggested) while rendering the HTML for the used tags.
you can control the HTML generation by specifying simple theme either in struts.properties file or in struts.xml file
Struts Properties file
struts.ui.theme=simple
Struts.xml file
<constant name="struts.ui.theme" value="simple" />
Other theme being provided by S2 out of the box are
css_xhtml: generate div based HTML
ajax: for ajax tags
Note that simple theme will not generate any extra HTML but only tags equivalent HTML code and you have full control to customize ur view by providing your own CSS and any other properties.
Above settings in properties file as well in struts.xml will be applicable to entire application which means each and every tag will generate same HTML for whole appllication.beside that if you want to control per tag HTML generation each S2 tag as a property namely theme, provide value to this property like simple,css_xhtml etc to control per tag HTML generation.
There is one more way to control the theme per request basis by using the following code
<s:set name="theme" value="'simple'" scope="page" />
or
<s:set name="theme" value="%{myTheme}" scope="page" />
Choice is all yours which way you want to go
Add theme="simple" to the Tag.
Sample Code:
<s:select id="..." list="..." theme="simple">

JQuery combo box and JSP

I am trying to use this plugin from JQuery, however how do I populate the options of the selection of the combo box? I am pretty new to JQuery so some help would be appreciated
So say I have a html code as follows:
<select name = "test">
<option>1</option>
<option>2</option>
</select>
what should I do to make it so I have the interface above?
Checkout the example on this page.
You still create an html select element with child options. Then you turn it into a jquery combobox with either a really simple $('#comboboxid').combobox(). If you want, I can help you with the more advanced options.
This jQuery plugin only enhances the look'n'feel of a HTML <select> element with customizeable CSS styles. It doesn't require any changes to standard HTML/JSP/whatever code you're using to populate the options. You can just write down the dropdown options the usual way in JSP as you would do without this jQuery plugin.
By the way, that plugin is pretty old and its name is fairly misleading. A combobox is in essence an editable dropdown. But this plugin does nothing about that at all. What's actually your functional requirement? Aren't you looking at the wrong plugin?
Update: as to how to use it, just include the required JS files in <head> and call $(selector).combobox() during document load. There's even a complete example here (note that you need to click the "click to view/hide" link to see the HTML).

The default look of Icefaces and how to customize it

I have a question about styling Icefaces. I have a minimal application that can use Icefaces components, but when I use them and view the page, the components are not styled (for example the buttons have the default look and tabs have no look at all, no images, nothing). I was wondering why that is and what I should do so I would get the default Icefaces look to work.
Next thing I don't get is how do I customize the look by changing some default css style classes that get applied to the components automatically, so every component I use gets the changed style.
Thank you for your answers!
I suggest that you take one of the existing style-sheets, which are included within the ICEfaces package (check the resources folder of the downloaded ICEfaces-1.8.1-bin.zip):
rime
royale
xp
You can preview them in the ICEfaces showcase
Include it within your *.xhtml file via the <ice:outputStyle> tag:
(portlet)
<ice:outputStyle href="/xmlhttp/css/rime/rime-portlet.css"/>
(servlet)
<ice:outputStyle href="./css/demo_template.css"/>
Starting from here, feel free to either manipulate the chosen stylesheets or - which I favor - include your own stylesheets after ICEfaces' ones and overwrite the needed styles.
Regarding your second question:
Basically every ICEfaces component has its own style class. Just browse around the showcase and inspect the components with Firebug. I've not found many classes, which have been reused between different components. Therefore, you'll have to customize each and every component on your own - or apply your own common style class to every component you use via the styleClass property.
<ice:panelGrid styleClass="myCommonStyleClass">
<ice:inputField styleClass="myCommonStyleClass">
There are three predefined ICEfaces style sheets included:
(1) xp.css
(2) royale.css
(3) rime.css
Developers may also create their own custom style sheet based on a predefined ICEfaces style sheet. If the style class names match those defined in the ICEfaces style sheets, the ICEfaces components will use the specified styles by default, without the need to specify the style class names explicitly on each component.
(1) Where to find CSS class names ?
IMPORTANT : The default CSS class names associated with each component are listed in the component's TLD (taglib) description.
(2) How To use a predefined style :
<link rel="stylesheet" type="text/css" href="./xmlhttp/css/xp/xp.css" />
OR
<ice:outputStyle href="./xmlhttp/css/xp/xp.css" rel="stylesheet" type="text/css" />
(3) Is there any Advantages of using ICEFaces OutputStyle ?
The ice:outputStyle component has the following advantages over the HTML link tag:
- Automatically includes browser-specific variants of the main style sheet in the page to adapt the theme styling to account for differences in each browsers' CSS support. See the TLD (taglib) documentation for the ice:outputStyle component for details.
- Provides the ability to dynamically change the theme style sheet at runtime via a value binding on the component's `href` attribute.
(4) What is meant by xmlhttp ?
The xmlhttp->css->xp path is automatically resolved by ICEfaces and all needed resources are loaded from the ICEfaces.jar
Hope this helps..!! :)

View GWT HTML source?

Is there a way to VIEW the HTML source code that GWT produces? Currently I just give my flex table the DIV id and that DIV is all HTML I can see in ViewSource.
Is there a way to structure my table in HTML (say using div's and lists) and than create a something like FlexTable around that?
To answer the original question, you can view the HTML GWT has rendered via 'Inspect Element' in Firefox, with Firebug is installed. Alternatively the Web Inspector in Safari/Chrome will do the trick, as will the Developer tools in both IE8 and Opera.
Well well it seems the answer is in the documentation.
In particular Organizing Projects outlines how we can bind different widgets to different id's on the page.
So I can effectively do something like:
# html
<div id="id_table"></div>
<div id="id_next_button"></div>
# java
t = new FlexTable()
RootPanel.get("id_table").add(t);
nextbtn = new Button("next");
RootPanel.get("id_next_button").add(nextbtn);
Wohoo!
Regarding the second part of your quetion. It is possible to create a HTML component in GWT. The recomended way to do this is extending ComplexPanel and create the elements using Document.get().createXXXElement(). But it is a little laborius.
Check out this dicussion and I am sure there are other articles about this around the internet. You can also study the code of other components the extend ComplexPanel.

Categories