Primefaces p:tabMenu align p:menuitem to right - css

I'm using Java EE with JDK 1.8, Maven and Primefaces. Regarding the tabMenu of Primefaces I have the following question:
How can I align the last menuitem to the right?
Please see my code below:
<p:tabMenu activeIndex="#{param.i}">
<p:menuitem value="Login" outcome="/Person/PersonLogin.xhtml"
icon="fa fa-sign-in"
rendered="#{!personModel.personLoggedIn()}">
<f:param name="i" value="#{(!personModel.personLoggedIn())?0:99}"/>
</p:menuitem>
<p:menuitem value="Register" outcome="/Person/PersonRegistration.xhtml"
icon="fa fa-user-plus"
rendered="#{!personModel.personLoggedIn()}">
<f:param name="i" value="#{(!personModel.personLoggedIn())?3:95}"/>
</p:menuitem>
<p:menuitem value="#{personModel.usedAccount.balanceFormatted}"
outcome="/Overviews/TransactionOverview.xhtml"
style="float:right; margin-right: 30px; #{personModel.usedAccount.balance >=0 ? 'color:green;' : 'color:red;'}"
rendered="#{personModel.personLoggedIn()}">
<f:param name="i" value="#{(personModel.personLoggedIn())?123:94}"/>
</p:menuitem>
</p:tabMenu>
This code snippet style="float:right; margin-right: 30px; #{personModel.usedAccount.balance >=0 ? 'color:green;' : 'color:red;'}" in the last menuitem still doesn't align it on the right side:
Currently the output is the following:
while it should look like this:

I have just checked the css that primefaces used. And I see that your css code is used for <a> element instead of outer <li> element. When I manually add your css to outer <li> element, it is working as you want. You need to find a way to add your css to outer <li>
Or, you may use
<p:panelGrid columns="2" layout="grid" columnClasses="ui-grid-col-10,ui-grid-col-2>
first element your <p:tabMenu> element without last <p:menuitem>
and second one can be a <p:commandLink> element
<p:panelGrid columns="2" layout="grid" columnClasses="ui-grid-col-10 tabMenucssclass,ui-grid-col-2 commandlinkcssclass>
<p:tabMenu></p:tabMenu>
<p:commandLink></p:commandLink>
</p:panelGrid>
Check out primefaces panelGrid element
UPDATE - This is not for score, just for answer you should accept #Kukeltje answer
.flo .ui-tabmenuitem:last-child{float: right;}
<p:tabMenu class="flo"></p:tabMenu>

For me the following works (tested in the PF showcase on 6.0.x)
.ui-tabmenuitem:last-child {
float: right !important;
}
Although it is better to not use !important and see if adding a styleClass to the menuItem or the tabMenu and use that in your selector works to (no time to try, sorry).
Update:
As #mismanc and OP found out, styleClass or related is not supported on the tabMenu but a class is. So if you do not want this on every tabmenu
<p:tabMenu class="flo">
...
</p:tabMenu>
and use the class in the selector
.flo .ui-tabmenuitem:last-child {
float: right;
}

Related

JSF Primefaces ConfirmDialog

I am working on improving/polishing my primefaces ConfirmDialog but I cant seem to put some nice image on it or improve some of its looks. Also I cant seem to find some documentation on how to use its attributes, I have downloaded the primefaces user manual, but it seem to be missing some things.
Here is my code.
<p:confirmDialog header="Confirm" severity="alert" closeOnEscape="true" widgetVar="confirmationDialog" showEffect="fold" >
<f:facet name="message">
<h:outputText value="Are you sure all details
are correct and proceed in creating the Account?" />
</f:facet>
<p:commandButton value="Yes" actionListener="#{marketingPersonController.create}"
oncomplete="confirmationDialog.hide()" icon="ui-icon-check"
update="propertyPanel accountPanel marketingPersonPanel">
<f:ajax rendered="propertyPanel accountPanel marketingPersonPanel"/>
</p:commandButton>
<p:commandButton value="No" onclick="confirmationDialog.hide()" type="button"
icon="ui-icon-close"/>
</p:confirmDialog>
Here is a screenshot
I cant seem to remove the small ! icon there, if I put severity none, it still shows up a wierd "^" image. I want to completely change the icon and somehow modify some of its look.
Also, I tried having this css. Still its not working.
.ui-dialog-content p span {
background-image: url('path to image here')
no-repeat !important;
}
Am I doing something wrong? And if you have a complete primefaces documentation, that would also help. Thanks
You have 2 possibilities :
You can directly replace the icon overriding the Primefaces CSS like this :
CSS
.ui-icon.ui-confirm-dialog-severity {
background-position: 0 0 !important;
background-image: url('PATH TO IMAGE HERE') !important;
}
or you could do it like this : Inside the component which trigger the dialog :
XHTML
<p:confirm header="HEADER" message="MESSAGE" icon="ui-icon-alert" />
Example Here : http://www.primefaces.org/showcase/ui/confirmDialog.jsf
CSS
.ui-icon.ui-confirm-dialog-severity.ui-icon-alert {
background-position: 0 0 !important;
background-image: url('PATH TO IMAGE HERE') !important;
}

CSS input[class*="span"]

I noticed this css on a web page and wondered how it worked!
What does this mean? input[class*="span"]
input[class*="span"], select[class*="span"], textarea[class*="span"] {
float: none;
margin-left: 0;
}
What it means it will select any input which has a class which includes the string "span" ANYWHERE in the class name. Such as:
<input class="span" type="text" value="span" />
<input class="span-3" type="text" value="span-3" />
<input class="span-six" type="text" value="span-six" />
<input class="myspan" type="text" value="myspan" />
Codepen EXample
'*' is an attribute wildcard selector. That CSS selector looks for any element of those types that has a class that contains 'span' in the class name.
From w3schools.com:
Example:
a[src*="w3schools"]
Selects every element whose src attribute value contains the substring "w3schools"
http://www.w3schools.com/cssref/css_selectors.asp
But in your example it looks kind of useless. Since the select probably has a class of "span", you could select it with:
input.span, select.span, textarea.span {
float: none;
margin-left: 0;
}
Then again, calling your class after an HTML element, isn't exactly smart..
Could you post the HTML to which it is referring?
With this kind of selector you are saying that if the provided string appears anywhere in the value, the CSS rule will be applied.
Here you have a more extended explanation: http://css-tricks.com/multiple-attribute-values/
Hope this helps.
input[class*="span"] has no differece usage with input.span. input[class*="span"] means that input tag that have class="span"
It basically means "Selects every element of type (like input fields) which contains class of span.
Take a look at: W3S Schools

PrimeFaces p:selectOneMenu width

I want p:selectOneMenu width to be auto regarding to the parent cell not regarding to the values it has.
<p:panelGrid>
<p:row>
<p:column><p:outputLabel value="Value01" for="idInput01"/></p:column>
<p:column><p:inputText value="#{bean.input01}" id="idInput01" /></p:column>
<p:column><p:outputLabel value="Value02" for="idSelect" /></p:column>
<p:column>
<p:selectOneMenu value="#{bean.selectedObject}" id="idSelect" converter="objectConverter">
<f:selectItems value="#{bean.objectsList}" var="varObject" itemLabel="#{varObject.label}" itemValue="#{varObject}" />
</p:selectOneMenu>
</p:column>
</p:row>
</p:panelGrid>
What I've got :
What I'm expecting :
Note: I don't want to specify a fixed width.
My solution: autoWidth="false"
i overrode .ui-selectonemenu, .ui-selectonemenu-label to:
.ui-selectonemenu{
width: 100% !important;
}
.ui-selectonemenu-label{
width: 100% !important;
}
The only way I found is to use jQuery to initialize width at load time.
You can create simply a CSS class like this (just to be used as a futur selector) :
.full-width
{
}
And add it to your component :
<p:selectOneMenu value="#{bean.selectedObject}" id="idSelect" converter="objectConverter" styleClass="full-width">
<f:selectItems value="#{bean.objectsList}" var="varObject" itemLabel="{varObject.label}" itemValue="#{varObject}" />
</p:selectOneMenu>
Since you will need jQuery, you should add this inside your h:head if you are not already using PrimeFaces components that use it.
<h:outputScript library="primefaces" name="jquery/jquery.js" />
Here is the small script that initialize all p:selectOneMenu in the selector :
<script>
$(document).ready(
function()
{
$("div.ui-selectonemenu.full-width").each(
function()
{
$(this).css("width",$(this).parent().width());
}
);
}
);
</script>
you can add the value of width directly in the component to modify it, to avoid impacting other p: selectOneMenu existing in the page.
<p:selectOneMenu style="width: 100% !important">
...
</p:selectOneMenu>
I now have a proper fix for this.
Primefaces 6.0 now has a new field called autoWidth that by default is set to true, and you can set to false.
IF you do as some of the above responses say and set it to false, all you are doing is playing roulette with you app css.
By setting it to false, primefaces will leave it up to you to manage the width.
You can either have the width set on the selectOneMeny expliclitly by style attribute, or some css class in your application.
But this is not what this issue is about, this issue is about the fact that the default behaivor of not specifying any width to a drop down makes leads our drop downs to normally be way too small for the labels in there.
So what we actually want is for the autoWidth to work proplerly.
FInally, I looked at the component and at the renderer, and it is obvious the auto-width mechanism does not work in the backend side.
The backend side only builds some JSON like data that the primefaces javascript builder can use to properly tune on the browser the behavior of the widget.
If you loook at primefaces 6.0 source code, the bug is in META-INF\resources\primefaces\forms
Search for the code that says the following:
PrimeFaces SelectOneMenu Widget
In this javascript function hunt for the code chunk that says:
_render: function() {
if(this.cfg.autoWidth) {
In this section of code your bug is the following line:
this.jq.css('min-width', this.input.outerWidth());
Here, I applied the following patch that hopefully should work in geting the drop down box to be as fat as the largest label:
_render: function() {
if(this.cfg.autoWidth) {
// BEGIN: PATCHING
// ORIGINAL CODE:
// this.jq.css('min-width', this.input.outerWidth());
// BUGFIX:
// (a) compute the original min-with primefaces 6.0 would put on the root div
var primefacesBugWidth = this.input.outerWidth();
// (b) compute the length of the hidden select element with all the labels inside of it
var widthOfHiddenDivWithSelectLabels = this.jq.find('div select').width();
var widthOfTheDropDownTriangle = this.jq.find('.ui-selectonemenu-trigger.ui-state-default.ui-corner-right').width();
var widthOfLabelPlusTraingle = widthOfHiddenDivWithSelectLabels + widthOfTheDropDownTriangle;
// (c) we will use whichever length is longer
// in bug-fixed primefaces version the outerWidth should be computed correctly
// but this seems not to be the case
var maxWidthOfTwoPossibleOptions = primefacesBugWidth > widthOfLabelPlusTraingle ? primefacesBugWidth : widthOfLabelPlusTraingle;
this.jq.css('min-width', maxWidthOfTwoPossibleOptions);
// END: PATCHING
}
}
The idea of the code above is:
(a) look at the hidden div with all labels and get the width of that div
(b) add to that length the width needed for the primefaces triangle facing down
(c) compare the width we have computed to that that is suggested by primefaces and that seems to be way too small
NOTE:
To install the patch you have to copy all of the Primaces code for the SelectOneWidget.
Add it to a javascript file under your control.
Make sure you only run the compilation of your javascript file after the primefaces javascript file has been loaded.
Normally primefaces is being rendered at the HEAD.
So if you have you jasvacript as the last ement in the body you should be fine.
The patching is working fine for me.
THis is code I do not like to maintain however.
You can ID the element and change the style width through CSS. Make it 100% of its container.
If your p:selectOneMenu is in a DIV with an assigned width, I find setting style="width:100%;" on the p:selectOneMenu seems to work in my case.
The problem might be min-width, which is set in the rendered HTML. If that is your case, use a CSS selector fixed-width like this:
<p:selectOneMenu styleClass="fixed-width" ...
then define CSS
.fixed-width { min-width: 100% !important; }
That sets the width of the selectOneMenu widget to the width of the parent element. To have it work, parent elements's width should not be 'auto'.
Those who still got problem with selectonemenu may try this
.ui-selectonemenu {
min-width: 0 !important;
}
Perfectly worked for me.
You can use something like
style="min-width: 12rem"

How to implement JSF button with image and button label

I want to implement JSF button with image and custom label. I tested this code:
<h:commandButton id="savesettings" styleClass="avesettings" value=" Save Settings " action="#{GeneralController.updateDBSettings}" rendered="true" update="growl">
<f:ajax render="#form" execute="#form"></f:ajax>
</h:commandButton>
.avesettings {
background-image: url('../images/small.png');
}
This is the result:
I also tested this second code:
<h:commandButton id="savesettings" image="resources/images/first.png" value=" Save Settings " action="#{GeneralController.updateDBSettings}" rendered="true" update="growl">
<f:ajax render="#form" execute="#form"></f:ajax>
</h:commandButton>
I get this result with no label:
Can you help me to create JSF button with background image and custom label defined as button attribute?
The first method that you have used styleClass="avesettings" i.e., using CSS style is the only possible way to do it since if you specify the image attribute, the input element will become an image.
See also documentation
So your best bet would be to use advanced styling techniques for the buttons, refer to these articles for that:
http://coding.smashingmagazine.com/2009/11/18/designing-css-buttons-techniques-and-resources/
http://www.tyssendesign.com.au/articles/css/styling-form-buttons/
The following JSF/CSS should solve your problem:
JSF (the same as in your first example):
<h:commandButton id="savesettings" styleClass="avesettings" value="Save Settings" action="#{GeneralController.updateDBSettings}" rendered="true" update="growl">
<f:ajax render="#form" execute="#form"></f:ajax>
</h:commandButton>
CSS (adapted):
.avesettings {
background: url('../images/small.png') no-repeat;
cursor: pointer;
width: 126px;
height: 41px;
border: none;
}
Width and height of the css must be the width and height of your image. I also have the css in an external css file, not direct in the JSF template.
Did you try the "image" attribute of he commandButton tag?
One way to implement this is to load the image as jsf resource in your style sheet:
<style type="text/css">
.imageButton
{
background-image:url(#{resource['images/button.png']});
}
</style>
Then set the relevant commandButton styleClass in the xhtml:
<h:commandButton value="Submit" styleClass="imageButton" action="#{...}"/>
Put the file button.png under your resources folder i.e. resources/images/button.png and make sure your resources folder is located next to your WEB-INF folder
Or if you want the image to display as an icon next to the text in the commandButton then you can play around with css a little:
.imageButton
{
padding: ...
border: ...
color: ...
background: [<'background-color'> || <'background-image'> || <'background-repeat'> || <'background-attachment'> || <'background-position'>]
}

JSF commandLink with image

I have problem with <p:commandLink>. I want make hover effect but I can't load image to <p:graphicImage> via CSS.
CSS:
.accountEditBtn {
background-image:
url('#{request.contextPath}/resources/image/pencil_black.png');
}
JSF:
<p:commandLink
update="#form"
actionListener="#{someBean.someListener}">
<h:graphicImage styleClass="accountEditBtn" />
</p:commandLink>
I see empty rectangle with border.
But when I add alt to graphicImage, I get image over text from alt...
Where my mistake?
Thank you.
p.s. typing error - classType -> styleClass
try using styleClass instead of <h:graphicImage>
<p:commandLink
styleClass="accountEditBtn"
update="#form"
actionListener="#{someBean.someListener}"/>
try this class
.accountEditBtn { background-image: url('../resources/image/pencil_black.png'); }
B.T.W
isn't is should be images ? or it is image (folder name)
take a look at this as well.. in case you want commandButton with image: PrimeFaces icons
Why don't you use
<p:commandButton ... icon="yourbuttonstyleclass"/>
and in css
.yourbuttonstyleclass {
background-image: url('../images/yourimage.png') !important;
}

Resources