p:dataTable: Trigger rowSelect event when click embedded content (image) - css

In the example below the rowSelect-event will be triggered if I click a row, but not if clicking the image in the row.
I understand why this happening, but i'm wondering if there is some elegant way to include the subcomponents also (possibly nested subcomponents also)?
<h:form id="form">
<p:growl id="growl" showDetail="true" />
<p:dataTable id="cars" var="car" value="#{tableBean.cars}" rows="5"
selectionMode="single">
<p:ajax event="rowSelect" listener="#{tableBean.onRowSelect}"
update=":form" />
<p:column headerText="Model">
<p:graphicImage value="myImage.png"
style="width: 40px; height: 40px;" />
</p:column>
</p:dataTable>
</h:form>

You can try to add an onclick event on the image:
<p:dataTable rowIndexVar="rowIndex" widgetVar="scrollist"...
... onclick="scrollist.unselectAllRows(); scrollist.selectRow(#{rowIndex})"

If the embedded content is an image that will be always displayed in a column (like in the picture below) and you want the image not interfering with the row selection, you can do:
<p:column styleClass="my_icon">
And create the css class:
.my_icon {
background-image: url("myicon.png");
background-repeat: no-repeat;
background-position: center;
}
You will get something like this:

just add the css to embeded img tag:
table tbody td img {
pointer-events: none;
-moz-user-select: -moz-none;
-khtml-user-select: none;
-webkit-user-select: none;
-o-user-select: none;
user-select: none;
}

Related

PrimeFaces menubar, last menuitem on float:right

i have this menubar in my project, i'm using PrimeFaces for the first time:
<p:menubar styleClass="sso_header ui-widget-header " style="width:99.5%; margin-top: 3px; border-radius: 10px;" >
<p:menuitem value="Test" rendered="true"
style="border: 1px solid; margin-right: 5px;" icon="ui-icon-triangle-1-s" />
<p:menuitem value="LOG IN" rendered="true"
style="border: 1px solid; margin-right: 5px;" icon="ui-icon-triangle-1-s" />
</p:menubar>
I need last menuitem float:right;, at least I tried to include external style in this way:
<h:outputStylesheet name="css/style.css" />
and assign my css class to the menutitem.
I tried inline style whit the !important attribute, nothing works.
After inspect code from browser i noticed that Primefaces assign my style to a <a> inside a <li>.
There is a way to assign float right to that <li> in PrimeFaces?
Thanks in advance.
Check the html code that PrimeFaces is generating and use the css classes to define your styles, for your posted code something like this should work
.sso_header .ui-menuitem.ui-widget.ui-corner-all:last-child {
float: right;
}

How to remove a specific (bottom) border from p:row in p:panelGrid?

I need to remove only a bottom border as displayed by <p:row> in <p:panelGrid>. I attempted the following.
CSS :
.panelgrid-cell-noborder.ui-panelgrid .ui-panelgrid-cell {
border-bottom: none;
}
XHTML :
<p:panelGrid style="width: 100%;">
<p:row>
<p:column>a</p:column>
<p:column>b</p:column>
</p:row>
<p:row>
<p:column styleClass="panelgrid-cell-noborder">c</p:column>
<p:column styleClass="panelgrid-cell-noborder">d</p:column>
</p:row>
<p:row>
<p:column>e</p:column>
<p:column>f</p:column>
</p:row>
</p:panelGrid>
The bottom border from the middle row is expected to be removed but it does not.
How to remove the bottom border from the middle row, in this example?
Every cell has border in this case by default, so you should cancel bottom border and top border of the row below:
XHTML:
<p:panelGrid style="width: 100%;">
<p:row>
<p:column>a</p:column>
<p:column>b</p:column>
</p:row>
<p:row>
<p:column styleClass="panelgrid-cell-noborder-bottom">c</p:column>
<p:column styleClass="panelgrid-cell-noborder-bottom">d</p:column>
</p:row>
<p:row>
<p:column styleClass="panelgrid-cell-noborder-top">e</p:column>
<p:column styleClass="panelgrid-cell-noborder-top">f</p:column>
</p:row>
</p:panelGrid>
CSS:
.ui-panelgrid .ui-panelgrid-cell.panelgrid-cell-noborder-bottom {
border-bottom: none;
}
.ui-panelgrid .ui-panelgrid-cell.panelgrid-cell-noborder-top {
border-top: none;
}
Also, your CSS was incorrect, you put ui-panelgrid together with the cell style, check that in my example too.
Edit:
You'll probably have to override theme styles too if you have them by default, because there are borders defined in both theme and primefaces styles, you could try adding this for example:
/* cancel border defined in aristo theme */
.ui-panelgrid .ui-widget-content{
border: none;
}
/* extra: you can add this if you want to recover the same color you cancelled above */
.ui-panelgrid .ui-panelgrid-cell {
border: 1px solid #a8a8a8;
}

How to Override .ui-panelgrid td for specific <p:panelGrid>

How do I override a specific <p:panelGrid> in my Stylecheet?
In according to this: How to hide time-slots ...
I tried:
#frm_dash\3Adisplay td.ui-panelgrid {
padding:0px 0px;
}
and
#frm_dash\3Adisplay .ui-panelgrid td {
padding:0px 0px;
}
But it seems not working.
The page is build in this physical structure:
<h:form id="frm_dash">
[...]
<p:panelGrid id="pnlg_page" style="width: 100%;">
[...]
<p:row>
<p:column style="width: 50%; vertical-align: top" colspan="1">
<p:panelGrid id="display" columns="2">
[...]
</p:panelGrid>
</p:column>
<p:column colspan="1" style="vertical-align: top;">
[...]
</p:column>
</p:row>
[...]
</p:panelGrid>
[...]
</h:form>
Primefaces 3.4.1. - Tomcat 7.x - Mojarra
Thanks for your help.
You made 2 mistakes:
The \3A must be followed by a blank space.
The .ui-panelgrid class is been set on the <table> itself, not on a child of it.
So, this should do:
#frm_dash\3A display.ui-panelgrid td {
padding: 0;
}
Or just this, as it makes no sense to use a classname selector on an element which is already selected by an ID which is by itself supposed to be unique already:
#frm_dash\3A display td {
padding: 0;
}
As a different alternative, give the panel grid a style class so that you can reuse the same appearance on the other elements:
<p:panelGrid id="display" columns="2" styleClass="nopadding">
with (a more clean CSS selector)
table.nopadding td {
padding: 0;
}
See also:
How to use JSF generated HTML element ID with colon ":" in CSS selectors?
just add a css code
.ui-panelgrid .ui-panelgrid-cell{
padding 0px;
}
this code if you import your page kill primefaces css

Pass CSS property dynamically from panelgrid

I have a hidden property which is fetched from ebean. how do i pass that color code property to css function?
<h:panelGrid id="testpanel"
columns="#{message.no_of_columns}" rows="#{message.no_of_rows}"
styleClass="dynamicGrid">
<c:forEach items="#{bLDashBoardAction.listBondLoc}" var="item">
<h:panelGroup> <h:outputText value="#{item.rackTagCode}" />
<h:hiddenInput value="#{item.colorEBean.colorCode};" />
</h:panelGroup>
</c:forEach>
</h:panelGrid>
this is my css property,background need to be assigned from panelgrid colorcode
.dynamicGrid td
{
width: 50px;
height: 50px;
border: 4px solid gray;
background:
}
As you're restricted by strange design, your best bet is really to apply the style directly on the cell's content instead.
<h:outputText value="#{item.rackTagCode}" style="display:block;color:#{item.colorEBean.colorCode};" />
The display:block will make it to span the entire cell.
Don't think you can pass from JSF to css , you can create several classes with predefined background color , like .dynamicGridRed and .dynamicGridYellow
and call them conditionally styleClass="#{item.colorEBean.colorCode}"
wher colorCode can return dynamicGridRed or dynamicGridYellow
or something like
styleClass="#{item.colorEBean.useRedCode?'dynamicGridRed':'dynamicGridYellow'}"
another option would be use inline css like:
style="width: 50px;height: 50px;border: 4px solid gray;background:#{item.colorEBean.colorCode}"
INMO , you better not try to manipulate the content of css, just make a bunch of predefined css classes...
but I'm not a css pro , so i might be wrong

How to align items in a <h:panelGrid> to the right

How would I align everything in my below to the far right?
<div id="container">
<h:form id="authenticate">
<h:panelGrid columns="5" cellpadding="6">
<h:inputText id="email" value="" />
<p:watermark for="email" value="Email"/>
<h:inputSecret id="password" value="" />
<p:watermark for="password" value="Password"/>
<p:commandButton id="login" value="Login" align="right"/>
</h:panelGrid>
</h:form>
</div>
The <h:panelGrid> renders a HTML table. You basically want to apply text-align: right; on every <td> element it renders. With the current code, easiest would be to apply the following:
#authenticate table td {
text-align: right;
}
You can of course also be more specific, e.g. giving the <h:panelGrid> its own styleClass and defining a rule in CSS (which would be applied directly on the rendered HTML <table> element).
<h:panelGrid styleClass="className">
with
.className td {
text-align: right;
}
You can also give each <td> element its own class by columnClasses attribute which accepts a commaseparated string of CSS classnames which are to be applied repeatedly on the <td> elements. If you want to apply the same class on every <td> element, just specify it once:
<h:panelGrid columnClasses="className">
with
.className {
text-align: right;
}
As an extra hint: rightclick the webpage in webbrowser and choose View Source, then you'll understand better what JSF is all exactly generating.
actually in same form i used <p:panel> and got good result. looks like ;
<p:panel styleClass="ui-panel-titlebar ui-widget-header ui-helper-clearfix ui-corner-all">
<p:commandButton value="Add New Tab"
actionListener="#{xxx.createNewTab}" process="#this"
update="tabView" style="float:right !important;margin:0px 0px 3px 0px;" />
</p:panel>
A little late, but might help someone, as it was what I needed...
If the alignment is not limited to this specific table, but rather the default format for all table cells, then just add this to your CSS file:
td {
text-align: right;
}
Then, all <td> elements, including those generated by JSF, will be formatted that way.

Resources