How to add minimize and maximize button in rich: popup panel window - jsf-2

Like below, how can we add minimize and maximize button at the upper right corner of the page in richface popup panel?
Using the below code, we can add the 'X' at the upper right corner and, on click of this, popup window gets closed.
<f:facet name="controls">
<h:outputLink value="#"
onclick="#{rich:component('simplePopup2')}.hide(); return false;">
X
</h:outputLink>
</f:facet>
Please, suggest me.

It is possible to extend jQuery with two custom functions that will do the maximize/minimize.
(function($) {
$.fn.maximize = function() {
var $this = $(this);
var viewport = $(window);
var bt = $this.css('border-top-width');
var br = $this.css('border-right-width');
var bb = $this.css('border-bottom-width');
var bl = $this.css('border-top-width');
bt = bt ? parseInt(bt) : 0;
br = br ? parseInt(br) : 0;
bb = bb ? parseInt(bb) : 0;
bl = bl ? parseInt(bl) : 0;
$this.css({
width: (viewport.width() - (bl + br)) + 'px',
height: (viewport.height() - (bt + bb)) + 'px',
top: 0,
left: 0
});
$this.find('div.rf-pp-cnt-scrlr').css({
width: 100 + '%',
height: 100 + '%'
});
}
$.fn.minimize = function() {
var $this = $(this);
var viewport = $(window);
$this.css({
width: '170px',
height: '20px',
top: (viewport.height() - 20),
left: 0
});
$this.find('div.rf-pp-shdw').hide();
$this.find('div.rf-pp-cnt-scrlr').hide();
}
})(jQuery);
Than you can use it with richfaces popupPanel
<rich:popupPanel id="window">
<f:facet name="controls">
<h:outputLink value="#" onclick="#{rich:component('window')}.cdiv.minimize(); return false;">
<h:outputText value="Minimize"/>
</h:outputLink>
<h:outputText value=" | "/>
<h:outputLink value="#" onclick="#{rich:component('window')}.cdiv.maximize(); return false;">
<h:outputText value="Maximize"/>
</h:outputLink>
<h:outputText value=" | "/>
<h:outputLink value="#" onclick="#{rich:component('window')}.hide(); return false;">
<h:outputText value="Close"/>
</h:outputLink>
</f:facet>
<h:outputText value="Window"/>
</rich:popupPanel>
Note the .cdiv before calling the maximize/minimize function. This is intended for reference to jQuery object itself so it will be possible to access the new functions.
The functions provided above is just a proof of concept so you will have to extend them in order to be able to restore to original size etc..

Related

Combine primefaces p:keyboard and p:password components

I have an issue here, that I want combine p:password and p:keyboard components in primefaces, I want password options like strength, on keyboard with password="true" so I can get strength meter, validations, match ,.. etc what special for p:password on keyboard of password='true' OR vice versa, adding keyboard to p:password.
I think easier to add keyboard to password field, as example password auto clear value when validation or re-enter form while keyboard save it !
Any idea how to do this, or workaround to make that?
In another word a solution for this equation :
<p:keyboard id="pwdPassword" value="#{loginManagedBean.password}" password="true" required="true" requiredMessage="Please enter your password"/>
And
<p:password id="pwd1" name="pwd1" value="#{loginManagedBean.newpassword}" match="pwd2" feedback="true" required="true" requiredMessage="Please Enter your new password">
<f:validateLength minimum="6" />
</p:password>
= ?
There is a workaround that you might find interesting.
The strategy is to synchronize the value between a keyboard and a password component and hide the input value for one of them.
If you check what's happening behind the curtains (here and here) you will be able to see some possibilities.
The first one that comes to my mind is hiding the input from the main password component and write some javascript code to make things appear and disappear as needed.
Here is the scenario I've created to test the idea:
<h:form id="mainForm">
<h:panelGrid columns="2" id="matchGrid" cellpadding="5">
<h:outputLabel for="pwd1" value="Password 1: *" />
<h:panelGroup>
<p:keyboard id="pwdPassword" widgetVar="kVar" value="#{viewMBean.password}" password="true" required="true" requiredMessage="Please enter your password"/>
<p:password id="pwd1" widgetVar="pVar" value="#{viewMBean.password2}" match="pwd2" label="Password 1" required="true" feedback="true" />
</h:panelGroup>
<h:outputLabel for="pwd2" value="Password 2: *" />
<p:password id="pwd2" value="#{viewMBean.password2}" label="Password 2" required="true" />
</h:panelGrid>
</h:form>
And here is the javascript:
function updateStrength() {
var p = PF('pVar');
var k = PF('kVar');
p.jq.val(k.jq.val());
var value = p.jq.val(),
label = null,
meterPos = null;
if (value.length === 0) {
label = p.cfg.promptLabel;
meterPos = '0px 0px';
} else {
var score = p.testStrength(p.jq.val());
if (score < 30) {
label = p.cfg.weakLabel;
meterPos = '0px -10px';
}
else if (score >= 30 && score < 80) {
label = p.cfg.goodLabel;
meterPos = '0px -20px';
}
else if (score >= 80) {
label = p.cfg.strongLabel;
meterPos = '0px -30px';
}
}
//update meter and info text
p.meter.css('background-position', meterPos);
p.infoText.text(label);
}
$(document).ready(function() {
var p = PF('pVar');
//p.jq.hide();
var k = PF('kVar');
k.jq.focus(function() {
p.show();
}).blur(function() {
if (!$.keypad._keypadShowing) {
p.hide();
}
}).keyup(updateStrength);
PrimeFaces.widget.Password.prototype.show = function() {
$(".keypad-close").click(function() {
console.log("close p");
p.hide();
});
$(".keypad-key").click(updateStrength);
//align panel before showing
if (!this.cfg.inline) {
this.panel.css({
left: '',
top: '',
'z-index': ++PrimeFaces.zindex
})
.position({
my: 'left top',
at: 'right top',
of: k.jq
});
this.panel.fadeIn();
}
else {
this.panel.slideDown();
}
};
});
I hope that will give you more "ammo" to deal with that challenge of yours.

how to have delimeter/separate between <f:selectItems> for <p:selectManyMenu>

I need to have a separator/delimiter between <f:selectItems> for <p:selectManyMenu> this is JSF2 + Primeface3 web application. Please find the code below:
<p:selectManyMenu
id="venue" value="#{PstOfrBen.selectedVenues}"
required="true" style="width: 285px;height: 200px">
<f:selectItems value="#{BsnsDshbrdBen.business.venues}" var="venue"
itemLabel="#{venue.venueAsDisplayString}" itemValue="#{venue.seoURL}" />
</p:selectManyMenu>
Just adapt the class of the menuitems:
.ui-selectlistbox-item {
border-bottom: 1px solid black;
}

How <p:dialog>'s position remain center of a page after increasing its size dynamically?

In my application I have a <p:dialog>, in the dialog I placed a h:selectBooleanCheckbox . If this is checked then one row below this will apear otherwise
this row will hidden.By default dialog's position is center of the page. Now Problem is when I checked this booleanCheckbox the height and width of dialog is
increased as new row's content is greater than previous dialog , then the position doesn't remain center of the page, I mean the dialog's size increases bottom and right side.
How I can display dialog at center after increasing its content? Any pointer will be very helpful to me . Thanks,
Sory for my bad English.
code of .xhtml is given below:
<p:dialog id="popUp" widgetVar="popUpWidget"
showEffect="fade" hideEffect="explode" resizable="false" modal="true">
<p:row>
<h:outputLabel value="#{adbBundle['addRemoveActivityManagers']}" />
<h:selectBooleanCheckbox value="#{activityListController.editActivityManager}" immediate="true">
<p:ajax event="click" update="adminPanel" listener="#{activityListController.updateActivityManager}"/>
</h:selectBooleanCheckbox>
</p:row>
<p:row rendered="#{activityListController.editActivityManager}">
<p:column>
<p:dataTable id="sourceManagerDataTable" value="#{activityListController.activitySourceUsers}" var="manager" liveScroll="true" scrollRows="5"
scrollHeight="125" selection="#{activityListController.selectedActivitySourceUsers}" selectionMode="multiple"
filteredValue="#{activityListController.filteredSourceUsers}" scrollable="true" styleClass="activityManager">
<f:facet name="header">
<h:outputText value="Available Managers" />
</f:facet>
<p:column headerText="Full Name" sortBy="#{manager.lastName}" filterBy="#{manager.fullName}" filterMatchMode="contains">
<h:outputText value="#{manager.lastName}, #{manager.firstName}" />
</p:column>
</p:dataTable>
</p:column>
</p:row></p:dialog>
So when you click to the checkbox or check it call a function which re-renders your dialog so add this onstart="setSize();" to you p:ajax:
And below is the JavaScript function:
function setSize () {
$(".ui-dialog").css ({
"width": 300,
"height": 200,
"left": "50%",
"top": "50%",
"margin-left": -150,
"margin-top": -100
});
}
Don't forget if you decide to change height or width values you should give the margin values as -1/2 times of them. The values that I gave are not certain you should chande them if it should be bigger or whatever.
If you want to detect unchecked checkbox and set height due to it's state our function can be sth. like that:
function setSize () {
var checkBox = $(document.getElementById('myCheckBox'));
$('.ui-dialog').css ({
'width' : 300,
'height': 200,
'left': "50%",
'top': "50%",
'margin-left': -150,
'margin-top': -100
});
if(!checkBox.checked) {//If it doesn't checked; it can be checkBox.attr('checked')
$(".ui-dialog").css ({
"height": 150, //New height value which is starting dialog height when it's unchecked
"margin-top": -75
});
}
}
}
You should give the correct clientID of your checkbox which you can see in your browser's developer options also maybe instead of this; height:auto; can work as well.

jQuery draggable(), resizable() in jsf doesn't work perfectly

I'm having a problem with jQuery: resizable() and draggable. When I move the div on datatable works perfectly and when I resize too, but after resize if drag the div it moves 1px on top and 1px on left. I can do this from the container div on top of the page. The divs on the rich:dataTable had been generated from jsf with h:outputtext/escape=false
I have considered this bug: http://bugs.jqueryui.com/ticket/4696 and this http://bugs.jquery.com/ticket/2793 and I have applied the patches
This is my xhtml code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:rich="http://richfaces.org/rich"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title>TC</title>
<h:outputScript name="jsf.js" library="javax.faces" />
<h:outputScript name="jquery.js" />
<script type="text/javascript"
src="resources/js/jquery-ui-1.10.1.custom.js" />
<h:outputScript library="js" name="jquery.json-2.4.js" />
<style type="text/css">
.ui-resizable {
position: relative;
}
.ui-resizable-handle {
position: absolute;
font-size: 0.1px;
z-index: 99999;
display: block;
}
.ui-resizable-e {
cursor: e-resize;
width: 2px;
right: 0;
top: 0;
height: 100%;
background-color: black;
}
</style>
</h:head>
<h:body>
<a4j:outputPanel rendered="false">
<rich:dataTable/>
</a4j:outputPanel>
<h:form id="formulario">
<script type="text/javascript">
function extenderHoras(div, index){
var contenedor = '#'+div.id;
var left = jQuery(contenedor).css("left");
var contenedorPadre = jQuery(contenedor).parent();
var padreDePadre = jQuery(contenedorPadre).parent();
var cantidadHijos = contenedorPadre[0].childElementCount;
jQuery(document).mousemove(function(e){
window.mouseXPos = e.pageX;
window.mouseYPos = e.pageY;
});
jQuery(contenedor).droppable({
accept: ".ui-draggable-dragging",
tolerance: 'pointer'
}).resizable({
handles: 'e',
minWidth: 41,
grid: [ 41, 0 ],
containment: contenedorPadre,
stop: function(event, ui) {
if(!index){
//Si no tiene index
var divArray = new Array();
var colorDiv = div.style.background;
var idPadreDePadre = padreDePadre[0].id;
var fila = idPadreDePadre.split(':');
index = fila[2];//Obtenemos el index
var cantidadHijosDiv = contenedorPadre[0].childElementCount; //Obtenemos Todos los hijos que se tiene en la fila
cantidadHijosDiv = cantidadHijosDiv - 1; //La lista es empieza desde 0 se le quita un elemento (tamaño -1)
var sumaTotalDiv = 0;
if(cantidadHijosDiv==0){//Si solo tiene un hijo obtenemos el tamaño de ese hijo para ponerlo como margen del div que estamos colocando
sumaTotalDiv = contenedorPadre[0].children[cantidadHijosDiv].style.width;
sumaTotalDiv = sumaTotalDiv.replace('px','');
}else{//Si tiene más de un hijo tenemos que recorrer el arreglo y sumar el tamaño de todos los div
for(var i = 0; i <= cantidadHijosDiv; i++){
var ancho = contenedorPadre[0].children[i].style.width;
sumaTotalDiv = sumaTotalDiv + parseInt(ancho.replace('px',''));
}
}
var leftUbicacion = sumaTotalDiv * -1;
var csstxt = jQuery(div.id).css('cssText') + ';top:0;left:'+leftUbicacion+' px;background-color:'+colorDiv+';height:'+ui.element.height()+'; width:'+ui.element.width()+';float:left;margin-left:'+sumaTotalDiv;
jQuery(div.id).css('cssText', csstxt);
} else {
jQuery(contenedor).css({
'width': ui.element.width(),
'height': ui.element.height(),
'top': ui.element[0].style.top,
'left': ui.element[0].style.left,
'float': 'left',
position: 'absolute'
});
};
var divArray = [{
"id":ui.element[0].id,
"width":ui.element[0].style.width,
"height":ui.element[0].style.height,
"top":ui.element[0].style.top,
"left":ui.element[0].style.left,
"right":ui.element[0].style.right,
"top":ui.element[0].style.top,
"backgroundColor":ui.element[0].style.background
}];
var json = jQuery.toJSON(divArray);
convertirJson(json, index);
}
}).draggable({
containment: contenedorPadre,
grid: [ 41, 0 ],
revert: 'valid',
stop: function(event, ui) {
if(!cantidadHijos){
//Si no tiene hijos que no haga nada, por si lo coloca en otro lado que no sea la tabla
} else {
}
}
}).removeClass("ui-draggable");
}
function arrastrarALado(div){
var contenedor = '#'+div.id;
var colorDiv = div.style.background;
jQuery(contenedor).draggable({
helper: 'clone',
revert: 'valid',
stop: function(event, ui) {
var elem = document.elementFromPoint(event.pageX, event.pageY);
event.stopPropagation();
var tag = elem.tagName;
var cantidadHijosDiv = elem.childElementCount; //Obtenemos Todos los hijos que se tiene en la fila
cantidadHijosDiv = cantidadHijosDiv - 1; //quitamos un elemento men la lista es (tamaño -1)
var sumaTotalDiv = 0;
if(cantidadHijosDiv==0){//Si solo tiene un hijo obtenemos el tamaño de ese hijo para ponerlo como margen del div que estamos colocando
sumaTotalDiv = elem.children[cantidadHijosDiv].style.width;
sumaTotalDiv = sumaTotalDiv.replace('px','');
}
else{//Si tiene más de un hijo tenemos que recorrer el arreglo y sumar el tamaño de todos los div
for(var i = 0; i <= cantidadHijosDiv; i++){
var ancho = elem.children[i].style.width;
sumaTotalDiv = sumaTotalDiv + parseInt(ancho.replace('px',''));
}
}
var divHijo = elem.children[cantidadHijosDiv];//Obtenemos el último hijo de la lista
if(!divHijo){//Si es undefined no tiene hijos o ha puesta fuera de la barra - Propenso a cambios
alert('No puede colocar la barra aquí');
} else if(divHijo.tagName=='TH'){//Si el hijo
alert('No puede colocar la barra aquí');
}
else if(divHijo.tagName=='SPAN'){//Si el hijo es un SPAN es que crea richfaces
var divHijo = elem.children[cantidadHijosDiv+1];//obtenemos el siguiente hijo, solo ocurre en el caso de que sea el span padre
divHijo = divHijo.id;
} else {//Si no usamos el nombre del ultimo div
divHijo = divHijo.id;
}
if(tag == 'TD'){
var leftUbicacion = sumaTotalDiv * -1;
var divNuevo = divHijo+cantidadHijosDiv+div.id;
//Implementando cssText de Jquery ya que no se puede insertar el estilo de forma normal al crear el div, tengo que agregarlo
var csstxt = jQuery('#'+divNuevo).css('cssText') + ';top:0;left:'+leftUbicacion+' !important;background-color:'+colorDiv+';height:25px; width:82px;float:left;margin-left:'+sumaTotalDiv;
jQuery('<div/>', {
id: divNuevo, //obtenemos el ultimo hijo, luego le ponemos la cantidad y el id del div que estoy arrastrando
//onmousedown: 'arrastrarBarra(this);',
onmouseover: 'extenderHoras(this);'
}).appendTo(elem);
jQuery('#'+divNuevo).css('cssText', csstxt);
}
}
});
}
</script>
<a4j:jsFunction name="convertirJson"
action="#{pruebasmb.obtenerDiv()}" >
<a4j:param name="divArray" assignTo="#{pruebasmb.divJSON}" ></a4j:param>
<a4j:param name="index" assignTo="#{pruebasmb.indexPersonaSeleccionada}"></a4j:param>
</a4j:jsFunction>
<div id="contenedores" style="width: 600px; height: 30px; background-color: #f0f0f0; ">
<div id="divBlue" style="width: 82px; height: 25px; background-color: blue; float: left; " onmouseover="arrastrarALado(this);"></div>
<div id="divRojo" style="width: 82px; height: 25px; background-color: red; float: left; " onmouseover="arrastrarALado(this);"></div>
<div id="divVerde" style="width: 82px; height: 25px; background-color: green; float: left; " onmouseover="arrastrarALado(this);"></div>
</div>
<a4j:commandButton action="#{pruebasmb.llenarlista()}"
value="Llenar lista" render="dataTablePersonas"></a4j:commandButton>
<br />
<br />
<a4j:outputPanel ajaxRendered="false">
<rich:dataTable var="persona" value="#{pruebasmb.personas}"
id="dataTablePersonas" rowKeyVar="index">
<f:facet name="header">
<rich:columnGroup>
<rich:column rowspan="2" >
<h:outputText value="Persona" style="padding: 0px;" />
</rich:column>
<rich:column colspan="24" style="padding: 0px;">
<h:outputText value="Horas" />
</rich:column>
<rich:column breakRowBefore="true"
style="width: 40px; padding: 0px;">
<h:outputText value="00h00" />
</rich:column>
<rich:column style="width: 40px; padding: 0px;">
<h:outputText value="00h30" />
</rich:column>
<rich:column style="width: 40px; padding: 0px;">
<h:outputText value="01h00" />
</rich:column>
<rich:column style="width: 40px; padding: 0px;">
<h:outputText value="01h30" />
</rich:column>
<rich:column style="width: 40px; padding: 0px;">
<h:outputText value="02h00" />
</rich:column>
<rich:column style="width: 40px; padding: 0px;">
<h:outputText value="02h30" />
</rich:column>
<rich:column style="width: 40px; padding: 0px;">
<h:outputText value="03h00" />
</rich:column>
<rich:column style="width: 40px; padding: 0px;">
<h:outputText value="03h30" />
</rich:column>
<rich:column style="width: 40px; padding: 0px;">
<h:outputText value="04h00" />
</rich:column>
<rich:column style="width: 40px; padding: 0px;">
<h:outputText value="04h30" />
</rich:column>
<rich:column style="width: 40px; padding: 0px;">
<h:outputText value="05h00" />
</rich:column>
<rich:column style="width: 40px; padding: 0px;">
<h:outputText value="05h30" />
</rich:column>
<rich:column style="width: 40px; padding: 0px;">
<h:outputText value="06h00" />
</rich:column>
<rich:column style="width: 40px; padding: 0px;">
<h:outputText value="06h30" />
</rich:column>
<rich:column style="width: 40px; padding: 0px;">
<h:outputText value="07h00" />
</rich:column>
<rich:column style="width: 40px; padding: 0px;">
<h:outputText value="07h30" />
</rich:column>
<rich:column style="width: 40px; padding: 0px;">
<h:outputText value="08h00" />
</rich:column>
<rich:column style="width: 40px; padding: 0px;">
<h:outputText value="08h30" />
</rich:column>
<rich:column style="width: 40px; padding: 0px;">
<h:outputText value="09h00" />
</rich:column>
<rich:column style="width: 40px; padding: 0px;">
<h:outputText value="09h30" />
</rich:column>
<rich:column style="width: 40px; padding: 0px;">
<h:outputText value="10h00" />
</rich:column>
<rich:column style="width: 40px; padding: 0px;">
<h:outputText value="10h30" />
</rich:column>
<rich:column style="width: 40px; padding: 0px;">
<h:outputText value="11h00" />
</rich:column>
<rich:column style="width: 40px; padding: 0px;">
<h:outputText value="11h30" />
</rich:column>
</rich:columnGroup>
</f:facet>
<rich:column>
<h:outputText value="#{persona.apellido}" />
</rich:column>
<rich:column colspan="24" style="padding: 0px; height:25px; position: relative;" >
<h:outputText value="#{pruebasmb.divDefault.get(index)}" escape="false" />
</rich:column>
</rich:dataTable>
</a4j:outputPanel>
</h:form>
</h:body>
</html>
pruebasmb Bean
import java.awt.Color;
import java.io.Serializable;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
#ManagedBean(name = "pruebasmb")
#SessionScoped
public class PruebasMB implements Serializable {
private static final long serialVersionUID = 2290961655122569612L;
private List<Persona> personas = new ArrayList<Persona>();
private String valorDelSlider;
private String celdaClickeada;
private String estiloBarra;
private String indexPersonaSeleccionada;
private EstilosCss estilos = new EstilosCss();
private List<String> divDefault = new ArrayList<String>();
private String divJSON;
public void llenarlista() {
divDefault.clear();
personas.clear();
for (int i = 1; i <= 10; i++) {
Integer horasTrabajadas;
// Para generar un temporal de las horas trabajadas aleatoriamente
horasTrabajadas = (int) Math.round((Math.random() * 16));
if (horasTrabajadas == 0)
horasTrabajadas = 1;
else
horasTrabajadas = horasTrabajadas * 41;
estiloBarra = estilos.generarEstilo(horasTrabajadas.toString(), "25", "yellow", "0", "0", "0", "0", "0", "0", "left", null, null);
Persona p = new Persona("nombre" + i, "apellido" + i, i + 20, "Calle J y la " + i, estiloBarra, horasTrabajadas, (i/2));
generarBarras(p, horasTrabajadas, i);
personas.add(p);
}
}
public void obtenerDiv(){
Gson gson = new Gson();
Type type = new TypeToken<List<Div>>(){}.getType();
List<Div> div = gson.fromJson(divJSON.toString(), type);
Integer index = Integer.valueOf(indexPersonaSeleccionada);
if(index==null){
index=0;
}
valorDelSlider = div.get(0).getWidth().replace("px", "");
System.out.println("Width: "+div.get(0).getWidth());
Integer valor = Integer.valueOf(valorDelSlider);
int valorTemporal = valor;
int horasTrabajadas = personas.get(index).getHorasTrabajadas();
if (horasTrabajadas == 1) {
valor = valor - 1;
valorTemporal = valorTemporal - 1;
valor = valor / 82;
} else
valor = valor / 82;
if ((valorTemporal % 82) > 0) {
System.out.println("El total de horas es " + valor + " y media ");
} else
System.out.println("Ha realizado " + valor + " horas");
System.out.println(valor * 82);
estiloBarra = "left: 0px; background-color: yellow; height: 25px; width: " + (valor * 82) + "px; top: 0px !important; float: left;";
personas.get(index).setEstiloUsuario(estiloBarra);
}
public void generarBarras(Persona p, Integer horasTrabajadas, Integer i) {
Integer horasSegundoDiv=0;
String rgb="";
String estiloBarra2 ="";
String div ="";
for(int j = 0; j<= 2; j ++){
horasSegundoDiv = (int) Math.round((Math.random() * 16));
if (horasSegundoDiv == 0)
horasSegundoDiv = 1;
else
horasSegundoDiv = horasSegundoDiv * 41;
rgb = Color2Hex();
estiloBarra2 = estilos.generarEstilo(horasSegundoDiv.toString(), "25", rgb, "0", "0", "0", "0", "0", "0", "left", null, null);
div = div + "<div id='nombrediv" + i+"_"+j + "' style='" + estiloBarra2 + "' onmouseover='extenderHoras(this," + (i) + ");'> </div>";
}
divDefault.add(div);
}
/**
* Se genera un color al azar en rgb y se convierte a hexadecimal
*
* #return Color en hexadecimal
*/
public String Color2Hex() {
int R = (int) Math.round((Math.random() * 256));
int G = (int) Math.round((Math.random() * 256));
int B = (int) Math.round((Math.random() * 256));
Color c = new Color(R, G, B);
String rgb = Integer.toHexString(c.getRGB() & 0xffffff);
if(rgb.length()<6)
rgb = "0"+rgb;
return "#"+rgb;
}
//getter and setter
}
and Estilos.css where I generate the Style of div
import java.io.Serializable;
public class EstilosCss implements Serializable {
private static final long serialVersionUID = -1279423720796129516L;
private String width;
private String height;
private String backgroundColor;
private String leftMargin;
private String rightMargin;
private String left;
private String right;
private String top;
private String bottom;
private String floatEstilo;
private String gradientColor1;
private String gradientColor2;
public String generarEstilo(String width, String height, String backgroundColor, String leftMargin, String rightMargin, String left, String right,
String top, String bottom, String floatEstilo, String gradientColor1, String gradientColor2) {
String estilo = "";
estilo = "width:" + width + "px; height:" + height + "px; background-color:" + backgroundColor + "; left-margin:" + leftMargin
+ "px; right-margin:" + rightMargin + "px; left:" + left + "px; right:" + right + "px; top:" + top + "px; bottom:" + bottom + "px; float:"+floatEstilo+" !important;";
//Si ingresa los colores del gradient del div
if(gradientColor1!=null&&gradientColor2!=null){
estilo = estilo + "background-image: -ms-linear-gradient(bottom, "+gradientColor1+" 0%, "+gradientColor2 +" 100%);";
estilo = estilo + "background-image: -moz-linear-gradient(bottom, "+gradientColor1+" 0%, "+gradientColor2 +" 100%);";
estilo = estilo + "background-image: -o-linear-gradient(bottom, "+gradientColor1+" 0%, "+gradientColor2 +" 100%);";
estilo = estilo + "background-image: -webkit-gradient(linear, left bottom, left top, color-stop(0, "+gradientColor1+"), color-stop(1,"+gradientColor2 +"));";
estilo = estilo + "background-image: -webkit-linear-gradient(bottom, "+gradientColor1+" 0%, "+gradientColor2 +" 100%);";
estilo = estilo + "background-image: linear-gradient(to top, "+gradientColor1+" 0%, "+gradientColor2 +" 100%);";
estilo = estilo + "filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='"+gradientColor1+"', endColorstr='"+gradientColor2 +"');";
}
return estilo;
}
//getter and setter
}

Tab Index is not working richfaces pop up panelk

I am new to Rich Faces and we are using richfaces 4.0. We are having an pop up requirement in our project and we used rich:popupPanel.
In the pop up we are having a form with 5 to 10 input text boxes.
We are facing the following issue:
Tab is not working in order to go the next text box.
We used tabindex property but it is not working in rich faces.
Can anyone help me on this?
Thanks in advance.
Here is a sample popup panel with tab feature enabled in Richfaces 4:
<script type="text/javascript">
jQuery('input').live("keypress", function(e) {
var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
/* ENTER PRESSED*/
if (key == 9) { // 9 for TAB
/* FOCUS ELEMENT */
var inputs = jQuery(this).parents("form").eq(0).find(":input");
var idx = inputs.index(this);
var move = (e.shiftKey) ? (-1) : (1); // for Shift+TAB
if (idx == inputs.length - 1) {
inputs[0].select()
} else {
inputs[idx + move].focus(); // handles submit buttons
inputs[idx + move].select();
}
return false;
}
});
</script>
<rich:jQuery query="focus().select()" selector="#thegrid :input:visible:enabled:first" name="focusInput"/>
<rich:popupPanel id="samplepopup" modal="true" resizeable="true" height="220" width="400"
onmaskclick="#{rich:component('samplepopup')}.hide()"
onshow="focusInput();">
<f:facet name="header">
<h:outputText value="sample"/>
</f:facet>
<h:form>
<h:panelGrid id="thegrid" columns="2" style="direction: rtl;">
<h:outputText value="Current Pass"/>
<h:inputSecret id="pass1" value="#{userBean.pass}"/>
<h:outputText value="New Pass"/>
<h:inputSecret id="pass2" value="#{userBean.newPass}"/>
<h:outputText value="New Pass Confirm"/>
<h:inputSecret id="pass3"/>
</h:panelGrid>
</h:form>
</rich:popupPanel>
<a4j:commandButton value="show sample" onclick="#{rich:component('samplepopup')}.show()"/>
A generic workaround could be to override the responsible function:
RichFaces.ui.PopupPanel.prototype.processTabindexes = function (input) {
if (!this.firstOutside) {
this.firstOutside = input;
}
if (!input.prevTabIndex) {
input.prevTabIndex = input.tabIndex;
// input.tabIndex = -1; // This line was marked out
}
if (!input.prevAccessKey) {
input.prevAccessKey = input.accessKey;
input.accessKey = "";
}
};

Resources