Showing the JSF Error Messages - css

I am using JSF Myfaces Impl 1.2 without tomahawk and other libs :
I am using different styles + images to show JSF Error messages, find below a sample.
<h:panelGroup rendered="${adminBean.showErrorIcon==2}">
<table width="375" align="center" class="InfoMsg" border="1"
cellspacing="0" cellpadding="0">
<tr>
<td>
<table width="375" align="center" class="InfoMsg" border="0">
<tr>
<td width="50"><img src="static/images/info_icon.gif"
width="40" height="40" border="0" /></td>
<td width="325" align="left"><h:messages layout="table"
errorClass="InfoMsg" /></td>
</tr>
</table>
</td>
</tr>
</table>
Based on the int variable of the Backing Bean , I am displaying a diff image and the corresponding FacesMessage(s) in the screen - only 2 cases - error or an information.
I am using the below code to set the variable of the Backing Bean
//Checking if there are messages!
log.debug("Checking if there are messages to be shown ]");
if(getShowErrorIcon()==99){//Set only if the value is still the default :
log.debug("getShowErrorIcon was DEFAULT - Changing it ]");
Iterator<FacesMessage> messages = FacesContext.getCurrentInstance().getMessages();
if(messages != null && getShowErrorIcon()==99){//Set Error/Info for messages that are not added here :
while(messages.hasNext()){
log.debug("There are ***messages***");
FacesMessage aMessage =(FacesMessage) messages.next();
if(aMessage.getSeverity().compareTo(FacesMessage.SEVERITY_ERROR)==0){
setShowErrorIcon(1);
break;//just once is enough
}
if(aMessage.getSeverity().compareTo(FacesMessage.SEVERITY_INFO)==0){
setShowErrorIcon(2);
break;
}
}
}
}//if it is not default, then something has been set already, why again?
Now the problem I have is , There are FacesMessage(s) that are added by the MyFacesImpl - like the required=true and the custom validator messages which are added during PROCESS_VALIDATION Phase, These are not shown in the screen since my integer variable of the Backing Bean is not set , and since the INVOKE_APPLICATION Phase was not called (and that means the above code was not called!!!)
How do I resolve this? Or Whats the best way / Where's the best place to place the above checking code ?
Appreciate your help.Thanks!

I'm not sure, but this all look like unnecessarily overcomplicated. To change icons/styles based on the message severity, just make use of the CSS powers. You can specify different CSS classes based on message severity using infoClass and errorClass attributes of the <h:messages> and you can specify the icons as CSS background image.
JSF:
<h:messages id="messages" layout="table" infoClass="info" errorClass="error" />
CSS:
#messages .info td {
background: url('info.gif') no-repeat left center;
padding-left: 15px;
}
#messages .error td {
background: url('error.gif') no-repeat left center;
padding-left: 15px;
}
The <h:messages layout="table"> itself already renders a HTML <table>. I think the whole table around it is unnecessary as well. Just apply styles accordingly the usual CSS way.
#messages {
width: 375px;
margin: 0 auto;
border: 1px black solid;
border-collapse: collapse;
}
See also:
W3schools CSS tutorial/reference
CSStutorial.net CSS tutorial
Update: as per the comments, you're looking for something like this:
<h:messages layout="table" styleClass="messages info" infoClass="info" errorClass="error" />
<h:messages layout="table" styleClass="messages error" infoClass="info" errorClass="error" />
with CSS:
.messages {
width: 375px;
margin: 0 auto;
border-collapse: collapse;
border: 1px black solid;
}
.messages.info {
background: url('info.gif') no-repeat left center;
}
.messages.error {
background: url('error.gif') no-repeat left center;
}
.messages.info tr.error, .messages.error tr.info {
display: none;
}
.messages td {
padding-left: 15px;
}
This shows two separate message tables, one for info and other for error messages, each with a single icon on the left center.

Related

Tooltips, CSS only, Show text tooltip on mouseover using a class to define the text

I'm fairly new to CSS, but have what seems to be an unique question.
I have a TL;DR if you want to skip to it.
I've seen MANY tutorials on how to display tooltips, but none answer this exact scenario, so it may not be possible.
Backstory:
I've been playing around with tables to show a calendar and have made it so I can simply change the class of a td cell to change the background colour.
This allows me to very easily edit my HTML, changing a single class on each line to change a date from available to booked. For instance:
HTML: <td class="b">1</td>
CSS: .b { color: #FFFFFF; background-color: #CC0033; font-size: 12px; text-align: center}
in my CSS, I have the "b" set to turn the background red, indicating this date is no longer available.
HTML: <td class="a">1</td>
CSS: .a { font-size: 12px; text-align: center}
The above would have no background colour and would indicate the date is available.
Now, I have been able to get a tooltip to show based on what class the cell is set to, but it seems I have to set every cell with the text, like this:
<td class="a">1<span class="tooltiptext">Tooltip text here</span></td>
which I guess is a way to do it, but it takes more time to edit, and I want it so I can display 2-3 different messages depending on which class I select in the td class.
So the question:
Is there a way I can set it up so,
If the td class = "a", a tooltip will show up saying "Available"
OR If the td class = "b", a tooltip will show up saying "Booked"
OR If the td class = "r", a tooltip will show up saying "Reserved"
when I mouseover the cell, without having to set those responses over and over again in every td cell.
IE: Without doing something like this:
<td class="a">1<span class="tooltiptext">Available</span></td>
<td class="b">2<span class="tooltiptext">Booked</span></td>
<td class="r">3<span class="tooltiptext">Reserved</span></td>
<td class="b">4<span class="tooltiptext">Booked</span></td>
<td class="b">5<span class="tooltiptext">Booked</span></td>
<td class="b">6<span class="tooltiptext">Booked</span></td>
<td class="a">7<span class="tooltiptext">Available</span></td>
<td class="b">8<span class="tooltiptext">Booked</span></td>
<td class="b">9<span class="tooltiptext">Booked</span></td>
I'd rather it was simply like this:
<td class="a">1</td>
<td class="b">2</td>
<td class="r">3</td>
<td class="b">4</td>
<td class="b">5</td>
<td class="b">6</td>
<td class="a">7</td>
<td class="b">8</td>
<td class="b">9</td>
and the tooltip text set elsewhere, but displayed on mouseover depending on which td class was set.
I feel I'm explaining this really badly.
Here is a snippet of my CSS using "t" as a test class, just in case you need it. Please don't worry about the formatting or positioning of the tooltip yet, I can fix that easily enough if I can get it working how I want:
.t { color: #FFFFFF; background-color: #FFA500; font-size: 12px; text-align: center; title:"Example";}
.t:hover .tooltiptext{ visibility: visible; }
.t .tooltiptext {visibility: hidden; width: 120px; background-color: black; color: #fff; text-align: center; border-radius: 6px; padding: 5px 0; position: absolute; z-index: 1; }
and the relevant piece of HTML:
<tr>
<td class="t">1<span class="tooltiptext">Test Message</span></td>
<td class="b">2</td>
<td class="b">3</td>
<td class="b">4</td>
<td class="b">5</td>
<td class="b">6</td>
<td class="a">7</td>
</tr>
So, in the above, can I relocate the span somewhere else so it only appears once, and is referenced depending on which td class is defined, and have 2 other spans with different messages, which are defined by the td class "a" and "b"?
An ideal solution to this would be something I can do in the CSS like this:
.t .tooltiptext {custom-text: "This text will display on hover";
visibility: hidden;
width: 120px;
Etc...
}
TL;DR Is there a 'CSS only' way of making the tooltip text display different text by only changing the td class?
Unfortunately in pure CSS you can't
relocate the span somewhere else (only in Javascript, Jquery, etc etc)
But if each td with a specific class has a span element you can display different text in this way:
span {
display:none;
/*Etc etc*/
}
td:hover span {
display:inherit;
}
.a span:after {
content: 'something about class A';
}
.b span:after {
content: 'something about class B';
}
<table>
<tr>
<td class="a">1<span></span></td>
</tr>
<tr>
<td class="b">2<span></span></td>
</tr>
<tr>
<td class="a">3<span></span></td>
</tr>
</table>

min-width isn't preferred strongly enough when child is a table

My previous question got an answer using min-width to set the width of a containing block but allow it to grow when its children are too big.
This worked fine with some kinds of children (simple divs with their own min-width and max-width specified explicitly). Now I'm looking at a more complex variation in which the children are tables. (Legitimate tables with semantically meaningful rows and columns, not page-layout tables.)
There is no manually-specified min-width or max-width on these tables, but tables have an inherent maximum and minimum width, corresponding to the width that the table would have if rendered with no line breaks in any of the cells (maximum) and the width that it would have with line breaks inserted insertion of all possible line breaks (minimum).
In the existing page layout which I'm trying to replace, the outermost container is a table (the bad kind of table) with a single cell in a single row, and a CSS width (not min-width) set to the preferred width. When the children are tables, they try really hard to fit into the container's width. A wide table will be rendered with line breaks to make it fit, and the container will expand only if the child still doesn't fit after all line breaks are inserted.
In other words, the parent's width property is treated as a minimum, but it is also a strongly preferred width, which has a higher priority than the child's preferred (i.e. maximum) width.
By contrast, when the parent is a plain div with display:inline-block and a specified min-width, the parent's min-width is not strongly preferred. The child prefers to be wider, so the parent expands, even if the child is capable of being rendered with a smaller width.
Here's a snippet, much like the one in the previous question, which demonstrates all of this. The goal is to make the second container act like the first one in some way that is more "proper" than using display:table for layout.
(Note: the table widths at the heart of this question are very sensitive to choice of font. I hope the Courier New comes through and everybody sees the same widths in the snippet.)
var containers = document.querySelectorAll(".container");
for(var i = 0; i < containers.length; ++i) {
(function() {
var c = containers[i],
b = c.nextElementSibling;
b.addEventListener("click", function(ev) {
big = c.querySelector(".bigchild");
medium = c.querySelector(".mediumchild");
small = c.querySelector(".smallchild");
if(big.style.display != "block" &&
medium.style.display != "block" &&
small.style.display != "block") {
big.style.display = "block";
} else if(big.style.display == "block") {
big.style.display = "none";
medium.style.display = "block";
} else if(medium.style.display == "block") {
medium.style.display = "none";
small.style.display = "block";
} else {
small.style.display = "none";
}
});
})();
}
body {
background-color: #ccc;
text-align: center;
font-size: 14px;
font-family: "Courier New";
}
table {
border-collapse: collapse;
}
td {
border: 1px solid black;
padding: 5px;
}
.container {
background-color: white;
min-height: 250px;
margin-left: auto;
margin-right: auto;
}
.bigchild, .mediumchild, .smallchild {
display: none;
}
button {
display: block;
margin: 10px auto 20px;
}
#container1 {
display: table;
width: 400px;
}
#container2 {
display: inline-block;
min-width: 400px;
}
<div class="container" id="container1">
<table class="bigchild">
<tr>
<td>Lots of</td>
<td>columns</td>
<td>make this</td>
<td>a very</td>
<td>wide</td>
<td>table</td>
<td>that won't</td>
<td>fit</td>
<td>even with</td>
<td>added</td>
<td>line breaks</td>
</tr>
</table>
<table class="mediumchild">
<tr>
<td>This table</td>
<td>is smaller</td>
<td>and</td>
<td>it fits</td>
<td>but</td>
<td>only with</td>
<td>added</td>
<td>line breaks</td>
</tr>
</table>
<table class="smallchild">
<tr>
<td>very</td>
<td>small</td>
</tr>
</table>
</div>
<button>Next</button>
<div class="container" id="container2">
<table class="bigchild">
<tr>
<td>Lots of</td>
<td>columns</td>
<td>make this</td>
<td>a very</td>
<td>wide</td>
<td>table</td>
<td>that won't</td>
<td>fit</td>
<td>even with</td>
<td>added</td>
<td>line breaks</td>
</tr>
</table>
<table class="mediumchild">
<tr>
<td>This table</td>
<td>is smaller</td>
<td>and</td>
<td>it fits</td>
<td>but</td>
<td>only with</td>
<td>added</td>
<td>line breaks</td>
</tr>
</table>
<table class="smallchild">
<tr>
<td>very</td>
<td>small</td>
</tr>
</table>
</div>
<button>Next</button>
I think .container {min-width: 400px;width: min-content;}, modulo vendor prefixes, is what you want.

Conditional Styles in Oracle APEX 4.2

I'm using APEX 4.2 to build a Training Calendar for the organization I support at work. I am by no means an DBA or any kind of programming expert. I've been learning a lot through trial and error.
My calendar is built, but what I am trying to do is change how items display based on a column in my table. For instance, I have two project types: Project A and Project B. I would like these to have a different border color on my calendar display. Currently, I am using the below CSS code but this applies to all events:
<style>
.Day a, .NonDay a, .Today a, .WeekendDay a {
font: normal 10px/12px Arial,sans-serif !important;
padding: 2px !important;
border-radius: 4px;
-moz-border-radius: 4px;
background-color: #E5E5E5;
border: 1px solid #FF1414;
}
.Day a:hover, .NonDay a:hover, .Today a:hover, .WeekendDay a:hover {
background-color: #A3A3A3;
border: 1px solid #FF1414;
text-decoration: none !important;
}
</style>
I want to be able to alter this so that when PROJECT = A a certain style like above is applied, and when PROJECT = B a variation of the above style is applied.
Does anyone have any guidance on how I can do this? I'm open to suggestions.
Thanks you,
Christina
I don't know APEX, but what you need is to extend html elements (whatever it is, could be a <li/>, a <td/> or something else) with project-specific css classes. You did not show your HTML code, so I just guess the calendar is build with a table. If so, this could look like:
<table>
<tr>
<td class="NonDay">27</td>
<td class="NonDay">28</td>
<td class="NonDay">29</td>
<td class="NonDay">30</td>
<td class="NonDay">31</td>
<td class="Day WeekendDay">1</td>
<td class="Day WeekendDay">2</td>
</tr>
<tr>
<td class="Day">3</td>
<td class="Day">4</td>
<td class="Day ProjectA">5</td> <!-- see the class -->
<td class="Day ProjectB">6</td> <!-- see the class -->
<td class="Day">7</td>
<td class="Day WeekendDay Today">8</td>
<td class="Day WeekendDay">9</td>
</tr>
</table>
With this, you can style this classes like you did for the other classes:
.ProjectA a {
border-color: blue;
}
.ProjectB a {
border-color: red;
}
The question I can't answer is how to add css classes in APEX, but this question would better fit to oracles support forums or maybe to https://superuser.com/ because it's not a programming related question.
I have a table that assigns colors to the different projects, so when I pull the event from the calendar table, I join it to the project table and grab the color.
SELECT e.ID, ''||DESCRIPTION||'' DESCRIPTION, event_date FROM EVENTS e, project a
where e.project_id=a.project_id;
If you want to style the individual calendar entries you could apply a class in the SELECT statement like this:
select ...,
'<div class=project"' || project || '>' || description || '</div>'
as description
from ...
This would result in HTML for the entries like:
<div class="projectA">This is project A</div>
In SQL code add column PROJECT_TYPE returning type of your project.
In calendar properties change "Display Type" to "Custom".
in "Column Format" input something like
<span class="#PROJECT_TYPE#">#COLUMN_VALUE#</span>
Then define ProjectA style.

Different FieldHeaderStyle DetailsView for edit vs readonly mode

I'm using an ASP DetailsView and would like the item header to be different depending on what mode the DetailsView is in.
I have two images - each one is 500px wide and 30px high. The right 300px is white whereas the left 200px is green or gray, depending on what mode the form will be in (gray for read-only, green for edit). I want the colored area to be the background of the field headings and the white part of the image to be behind the actual bound data.
Using a skin and some simple CSS, this works perfectly for Firefox (version 21.0):
<asp:DetailsView SkinID="DetailsViewSkin" runat="server" CssClass="DetailsView"
RowStyle-CssClass="DetailsViewRow"
EditRowStyle-CssClass="DetailsViewRowEdit"
FieldHeaderStyle-CssClass="DetailsViewHeader"/>
.DetailsView
{
width: 500px;
}
.DetailsViewRow
{
background: url('../Images/KL/tableRowGrayjpg') no-repeat #fff;
}
.DetailsViewHeader
{
width: 200px;
height:30px;
}
.DetailsViewRowEdit
{
background: url('../Images/tableRowGreen.jpg') no-repeat #fff;
}
The colored area appears behind the headings and the rest overlays the white part of the image. However, for IE (version 10) and Chrome (version 26.0.1410.64), the background image is appearing in both the <td> for the heading and the <td> for the values.
Anyone know if this is possible or some cross-browser trick? Thanks!
EDIT
Here is the html code that is being generated (for a little more clarity).
<table id="dvPerson" class="DetailsView" cellspacing="0" border="1" style="border-collapse:collapse;" rules="all">
<tbody>
<tr class="DetailsViewRow"> <!-- DetailsViewRowEdit, when in edit mode -->
<td class="DetailsViewHeader"></td>
<td> … </td>
</tr>
</tbody>
</table>
Firefox only applies DetailsViewRow (the css with the image) to the <tr> element so the <td>'s are left as is, but Chrome and IE apply it to each individual <td> element, so that each column has the background image.
I think you can solve this differentiating the header row <th> and <td> for the data rows.
tr.DetailsViewRow
{
background: url('../Images/KL/tableRowGrayjpg') no-repeat #fff;
}
tr.DetailsViewRowEdit
{
background: url('../Images/tableRowGreen.jpg') no-repeat #fff;
}
td.DetailsViewHeader
{
width: 200px;
height:30px;
background: none;
}
Got it! #Leniel helped me get in the right direction. Based on the html that was being generated (seen below, for brevity), I had to do a little more manual css work:
Generated code:
<table id="dvPerson" class="DetailsView" cellspacing="0" border="1" rules="all">
<tbody>
<tr class="DetailsViewRow"> <!-- DetailsViewRowEdit, when in edit mode -->
<td class="DetailsViewHeader"></td>
<td> … </td>
</tr>
</tbody>
</table>
resulting css (works on Firefix, Chrome, and IE)
.DetailsView
{
width: 500px;
}
.DetailsViewHeader
{
width: 170px;
height:25px;
}
tr.DetailsViewRow td.DetailsViewHeader
{
background: url('../Images/KL/tableRowGray.jpg') no-repeat #fff;
}
tr.DetailsViewRowEdit td.DetailsViewHeader
{
background: url('../Images/KL/tableRowGreen.jpg') no-repeat #fff;
}

Arranging elements within generated table

The selectOneRadio element in JSF is translated to a table, where the radio button and its label are put within the same <td> in a table.
<!-- JSF Element -->
<h:selectOneRadio id="types" label="Type"
value="#{bean.selectedType}"
layout="pageDirection">
<f:selectItems value="#{bean.types}"/>
</h:selectOneRadio>
<!-- Generated HTML -->
<table id="j_id_i:types">
<tbody>
<tr>
<td>
<input id="j_id_i:types:0" type="radio" value="VALUE1"
name="j_id_i:types"/>
<label for="j_id_i:types:0"> Value #1</label>
</td>
</tr>
<tr>...</tr>
...
</tbody>
</table>
Before I was using Bootstrap, the elements within the <td> would appear side by side, but now look under each other.
The processed CSS for the element is the following, as given by Firebug.
table {
border-collapse: collapse;
border-spacing: 0;
}
body {
color: #333333;
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
font-size: 14px;
line-height: 20px;
}
html {
font-size: 100%;
}
I have no clue what may be producing such behaviour. It's not a concern of width, as this is the single element within the <div>, and without bootstrap it is rendering side by side.
That's because the <label> has due to the Bootstrap CSS become a HTML block element which starts naturally at a new line.
You need to make it a HTML inline element again. So, you need to override the Bootstrap CSS accordingly. Perhaps you want to apply this for labels in table cells only. E.g.
td label {
display: inline;
}

Resources