how to override p:selectOneRadio default icons - css

I have the following p:selectOneRadio :
<p:outputPanel id="customPanel">
<p:selectOneRadio id="customRadio" value="#{dyna.selecetedlist}" layout="grid" columns="1">
<c:forEach var="list" items="#{dyna.userlist}" varStatus="loop">
<f:selectItem itemEscaped="true" itemLabel="#{list.id.tbCode}" itemValue="#{list.id.tbCode}" />
</c:forEach>
<p:ajax update=":form1:tabexam,:form1:msg,:form1:colser" listener="#{dyna.updatecolumns}"/>
</p:selectOneRadio>
</p:outputPanel>
which generate this :
What i want is to override the default icons and layout of p:selectOneRadio.
and render it like below:

To customize the icon, override the .ui-radiobutton-icon on your page (there is a cleaner option of including a properly packaged css file):
<style type="text/css">
.ui-radiobutton-icon{
background: url(imgs/icon.png) no-repeat; !important;
}
</style>
EDIT: Override the
.ui-state-hover class to override the default hover style for the component
.ui-state-active clasas to override the default selected style for the component
Note overriding both classes as listed above will affect all the components on that page. Be sure to use a custom namespace when overriding. Take for example
.my-custom-ns .ui-state-hover{
//css
}
And then in your component definition:
<p:selectOneRadio id="customRadio" value="#{dyna.selecetedlist}" styleClass="my-custom-ns" layout="grid" columns="1">
<c:forEach var="list" items="#{dyna.userlist}" varStatus="loop">
<f:selectItem itemEscaped="true" itemLabel="#{list.id.tbCode}" itemValue="#{list.id.tbCode}" />
</c:forEach>
<p:ajax update=":form1:tabexam,:form1:msg,:form1:colser" listener="#{dyna.updatecolumns}"/>
</p:selectOneRadio>

Related

Primefaces tab header style

Could someone help me hide tab headers with css?
I'm using primefaces controls and there is one general tabview on page. And there's one tabview(ribbon) on each tab of general tabview.
I need hide all tabs headers of child tabview, but show tabs headers of general tabview.
I've try to make it by using
.ui-tabs.ui-tabs-top > .ui-tabs-nav {
display: none!important;
}
But this code hides all headers.
My code:
<ui:composition template="./../WEB-INF/pagesTemplate.xhtml">
<ui:define name="content">
<h:form id="centralTable">
<p:tabView id="tabview"
value="#{tabView.tabList}"
widgetVar="wtabview"
style="height: 100%"
dynamic="true">
<p:ajax event="tabChange" listener="#{tabView.onTabChange}"/>
<c:forEach items="#{tabView.tabList}" var="pageUrl">
<p:tab title= "#{msg[tabView.getCommonTitleByPage(pageUrl)]}">
<ui:include src="#{pageUrl}" />
</p:tab>
</c:forEach>
</p:tabView>
</h:form>
</ui:define>
</ui:composition>
Example tab of general tabview:
<p:tab title="#{msg['header.Main.Model']}">
<p:ribbon id="ribbonPannelModel">
<p:tab title="Model" id="tabModel" >
<p:ribbonGroup label="#{msg['header.Common.Editing']}" id="rgModelEdit">
...
</p:ribbonGroup>
</p:tab>
</p:ribbon>
<p:dataTable id="dtModel" widgetVar="wdtModel">
...
</p:dataTable>
</p:tab>
And I need to hide <p:tab title="Model" id="tabModel" > - this header
You must use an id for the tabs that you aim and then apply the style to it
#myTabId .ui-tabs.ui-tabs-top > .ui-tabs-nav {
display: none!important;
}
I am not sure about the space between the #myTabId and .ui-tabs try to use and delete it and see the result
Just add the styleClass "hideTabHeader" to p:tabView styleClass.
<p:tabView id="idXYZTabView" styleClass="hideTabHeader" ..
And the following to your CSS file:
.hideTabHeader > .ui-tabs-nav
{
display: none !important;
}
Easy and reusable for other TabView's.

How can I set the height in layoutUnit of primefaces?

I'm using primefaces 5.0. Below is my page where I like to set the height fix to 200px of the layoutunit west and center. Is there any possibility to do this? The current height will be ignored.
<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui" template="/templates/template.xhtml">
<ui:define name="header_title">
<h:outputText value="Titel" align="center" />
</ui:define>
<ui:define name="content">
<h:form id="labelForm" style="height:100%">
<p:growl id="growl" showDetail="true" />
<p:layout style="height:100%" fullPage="false" >
<p:layoutUnit position="west" header="west" resizable="false" closable="false" collapsible="false" style="height:200px">
<p:tieredMenu id="type" model="#{dynamicLabelMenu.menu}" trigger="itemSelect" />
</p:layoutUnit>
<p:layoutUnit position="center" resizable="false" closable="false" collapsible="false" header="center" style="height:200px">
<!-- datatable -->
</p:layoutUnit>
<p:layoutUnit position="south" size="100" header="Bottom" resizable="false" closable="false" collapsible="false">
<br/>
<br/>
<!-- datatable -->
</p:layoutUnit>
</p:layout>
</h:form>
</ui:define>
</ui:composition>
The height should be consistent with the other units... meaning if you would like to fix the height of one unit the others have to be also fixed...
The reason behind this is that PrimeFaces embeds the css rules into the style attribute and totally ignores your style.
You have two options to solve this:
If you are okay keeping the consistent between the units, then this might help. Currently your layout has a height of 100% that means the units should fit into the content, but to fix it you might take this approach
<p:layout style="min-height:200px;">
This way you have a minimum height of 200px and it could expand with the content, or just use height:200px.
The other option is to define a CSS class with !important option, although using !important is ugly and not recommended, but in this particular case PrimeFaces is injecting the css into the style attribute making it hard to cascade the height option.
<style>
.westUnit {
height: 200px !important;
}
</style>
<p:layoutUnit position="west" styleClass="westUnit">
Have a look at the CSS priority rules:
http://www.standardista.com/css3/css-specificity/
You can simply overwrite the primefaces CSS rules by adding more specific CSS selectors.
Example :
Primefaces:
.ui-dialog .ui-dialog-title {
text-align : center;
}
Your CSS:
#content .ui-dialog .ui-dialog-title {
text-align : right;
}
You can use the browser debugging tools (F12 in most browsers) to find out witch primefaces css is used for your components. Overwrite them with more specific CSS selectors from your own css code.

Apply styleClass to parent panelGrid element and not to children

I'm trying to apply a styleClass to a h:panelGrid without applying it to its children:
<h:panelGrid id="mainPanelGrid" columns="2" width="100%" styleClass="topAligned" >
<p:fieldset id="fs1" legend="fs1" style="width: max-content">
<h:panelGrid columns="3">
<p:outputLabel for="id1" value="#{messages.label_application}" />
<p:selectOneMenu id="id1" required="true" value="som">
<f:selectItem itemLabel="#{messages.label_select}" noSelectionOption="true" />
<f:selectItems value="#{bean.availableItems}" />
</p:selectOneMenu>
<p:message for="id1" />
</h:panelGrid>
</p:fieldset>
<p:fieldset id="fs2" legend="fs2" style="width: max-content">
<h:panelGrid columns="3">
<!--more fields-->
</h:panelGrid>
</p:fieldset>
</h:panelGrid>
My topAligned css:
.topAligned td{
vertical-align: top !important;
}
The problem is that I need to top align the two fieldset and that works well with the styleClass I apply, but it also applies this styleClass to all the children. Therefore, all the fields (outputLabel, selectOneMenu, etc...) of the two fieldset get top aligned too...
I tried all the different ways to specify the top alignment from this question but without success... I also tried to look at the html source but it gets a bit confusing with all the jsf and primefaces stuff...
If you know a trick that will work...
With
.topAligned td{
vertical-align: top !important;
}
and the JSF-generated HTML output
<table class="topAligned">
...
</table>
you're basically applying the style on every single <td> element of the <table>, also those of the nested <table>s.
If you want to apply the style on only the immediate <td> elements of the parent <table>, then you should be using columnClasses attribute instead:
<h:panelGrid ... columnClasses="topAligned,topAligned">
with
.topAligned {
vertical-align: top;
}
This will end up in the generated HTML output as follows:
<table>
<tbody>
<tr>
<td class="topAligned">...</td>
<td class="topAligned">...</td>
</tr>
</tbody>
</table>
and not be applied on the <td>s of the nested <table>s.
Note that I also removed the nonsensicial !important workaround. It's supposed to be used only when you want to override a hardcoded style by an external CSS style.
Also note that this problem is not specifically related to JSF. JSF is in the context of this question merely a HTML code generator. You'd have had exactly the same problem when dealing with "plain vanilla" HTML/CSS. The problem is more in the lack of familiarity with basic HTML and CSS. On http://htmldog.com you can find decent HTML/CSS tutorials.

css margin not not applied in jsf

I have the jsf code and css code below. I'm having trouble getting the css margin attributes to take effect. All the other attributes work fine except margin. What am I doing wrong?
Notice the .contentDialog css class is applied to p:dialog. What I expect is a 100px margin around h:outputText enclosed in f:facet name="header". But it's not happening.
I've tested on IE 7, IE 8, FireFox 7.0.1 and Chrome 16.0.912.63 m. Same problem on all browsers. Also, I'm using PrimeFaces.
JSF CODE
<h:form id="newContentForm">
<p:dialog header="New Menu Item Type..." widgetVar="newWidget"
resizable="false" showEffect="explode" hideEffect="explode" modal="true" closable="false"
styleClass="contentDialog" width="440">
<h:panelGrid id="newPopUpWindow" column="1">
<!-- Grid Header -->
<f:facet name="header">
<h:outputText value="New information"/>
</f:facet>
<!-- Grid Body -->
<h:outputText value="Description:"/>
<p:inputText id="newDescriptionInText" value="#{menuItemTypeContent.selectedContent.menuItemTypeDescr}">
<p:ajax process="#this"/>
</p:inputText>
<!-- Grid Footer -->
<f:facet name="footer">
<!-- Dialog command bottons -->
<h:panelGroup>
<!-- Submit -->
<p:commandButton value="Submit" image="ui-icon ui-icon-check"
actionListener="#{menuItemTypeContent.save}"
oncomplete="handleNewRequest(xhr, status, args)"/>
<!-- Cancel -->
<p:commandButton value="Cancel" image="ui-icon ui-icon-close"
actionListener="#{menuItemTypeContent.clearContent}"
onclick="newWidget.hide()" type="reset"/>
</h:panelGroup>
</f:facet>
</h:panelGrid>
<!-- Submit javascript handler -->
<h:outputScript>
function handleNewRequest(xhr, status, args) {
if (args.duplicateSaveError) {
duplicateError.show();
}else if (args.illegalStatusError) {
deleteError.show();
}else if (args.validationFailed) {
newContentError.show();
}else {
// Hide new content dialog box if add happened without exceptions
newWidget.hide();
}
}
</h:outputScript>
</p:dialog>
</h:form>
CSS CODE
.contentDialog {
font-size:13px;
border:2px solid #2D65B0;
}
.contentDialog table {
border:1px solid #8DB1E2;
width:100%;
}
.contentDialog th {
background-color:#2D65B0;
width:100%;
text-align:left;
color:red;
margin:100px;
}
This is not related to JSF but rather to CSS and html. You cannot use margins to style table cells. What you can use is cellspacing attribute for the entire table or padding for individual cells. You can find more information under this question.

font-size style doesn't work for jsf selectOneRadio

I can't modify the font size of the itemLabel in selectOneRadio in jsf, I can change color but not the size.
here is my code:
<h:selectOneRadio style="color:red; font-size:7pt;"
value="#{myBean.choice}">
<f:selectItem itemLabel="one" itemValue="1" />
<f:selectItem itemLabel="two" itemValue="2" />
<f:selectItem itemLabel="three" itemValue="3" />
</h:selectOneRadio>
is their any idea to resolve that?
thank you for your help.
My config: jsf 2 and tomcat 7
It should work fine. Please check the generated HTML with help of among others Firebug. The <h:selectOneRadio> generates a HTML <table> element with the labels in <td> elements. Apparently you've in some CSS stylesheet a declaration something like
td {
font-size: 10pt;
}
which get precedence over the inline font-size:7pt; declaration on the <table> element. You'd need to finetune the CSS. This is best to be done by supplying a normal CSS style class (using inline CSS is a bad practice anyway):
<h:selectOneRadio styleClass="choices">
with
.choices td {
color: red;
font-size: 7pt;
}

Resources