I developed an interface JEE / JSF for some statistics.
I created checkbox to select references that the user wishes to display, but the trouble is that I use to generate the checkbox Arraylist based on data from my database.
And I can not position them as I want. I wish that after 10 checkbox, others generates directly to the line etc. ..
I have this result
And i wish i could do this
MTBFBEAN
private List<String> selectedReference = new ArrayList<String>();
private List<String> listReference = new ArrayList<String>();
private Boolean afficher = false; // Déclaration du bool pour le rendered de
// ma vue dans MTBF
#SuppressWarnings("deprecation")
public StatisticsBeanMTBF() {
this.beginDate = new Date(2001, 00, 01);
List<ProductConfModel> listtmp = this.moduleGlobal.getProductConfModels(2);
for (ProductConfModel pcm : listtmp) {
this.listReference.add(pcm.getReference());
}
}
public void mTBFByType() {
this.afficher = true;
this.listMTBF = new ArrayList<StatistiquesMTBF>();
List<StatistiquesMTBF> suspense = this.moduleGlobal.getMTBFByType(nbHeure, nbJour, NS, DAE, beginDate, endDate);
for (StatistiquesMTBF smtbf : suspense) {
for (String s : this.selectedReference) {
if (smtbf.getReference().equals(s)) {
this.listMTBF.add(smtbf);
}
JSF XHTML
<h:outputText value="Date début :* " />
<p:calendar value="#{statisticsBeanMTBF.beginDate}"
navigator="true" required="true" />
<h:outputText value="Date fin:* " />
<p:calendar value="#{statisticsBeanMTBF.endDate}" navigator="true"
required="true" />
</h:panelGrid>
<h:panelGrid columns="1">
<h:outputText value="Selectionner votre référence : " />
<p:selectManyCheckbox id="grid" columns="5"
value="#{statisticsBeanMTBF.selectedReference}">
<f:selectItems value="#{statisticsBeanMTBF.listReference}" />
</p:selectManyCheckbox>
</h:panelGrid>
<p:separator />
If anyone can help me it would be nice.
Thank you !
I get this outcome using:
<h:panelGroup layout="block" styleClass="selection">
<p:selectManyCheckbox layout="pageDirection" value="#{selection.selection}">
</h:panelGroup>
and setting each <tr>:
.selection tr {
float: left;
width: 33%;
}
In your case set it to 10% and outer container to width: 100%.
It looks like that:
You should add layout="grid" to your p:selectManyCheckbox according to this example. Like this :
<p:selectManyCheckbox id="grid" layout="grid" columns="5" value="#{statisticsBeanMTBF.selectedReference}">
<f:selectItems value="#{statisticsBeanMTBF.listReference}" />
</p:selectManyCheckbox>
EDIT :
A fast search in PrimeFaces documentations show that columns was added in the version 4.0. If you doesn't have this version or can't upgrade, you'll need to do it the old way with some CSS.
Related
I need to solve this issue.
I am using jsf primefaces with c:foreach here is my code. but this code is not running.
<p:tab id="catagoryTab" title="#{hardvalue['tutor.reg.tab2']}">
<p:panel header="#{hardvalue['tutor.reg.tab2']}" id="rowCreator">
<h:outputLabel value="#{hardvalue['tutor.reg.selectStmt']}"></h:outputLabel>
<h:panelGrid columns="3" style="width:100%;">
<p:outputLabel value="#{hardvalue['tutor.reg.category.table.collection']}"/>
<p:outputLabel value="#{hardvalue['tutor.reg.category.table.level']}"/>
<p:outputLabel value="#{hardvalue['tutor.reg.category.table.subject']}"/>
</h:panelGrid>
<c:forEach begin="0" end="#{Registerbean.size -1}" varStatus="loop" var="row">
<h:panelGrid columns="3"
style="width:100%; border: 1px solid #d4f1ff; border-radius: 3px 3px 3px 3px; background:#F7FDFF 50% 50% repeat-x ;">
<p:selectOneMenu
value="#{Registerbean.selectedtutorialType[loop.index]}"
style="font-size:15px !important; width:100px;">
<p:ajax process="#this" update="levellist1_#{loop.index}, levellist2_#{loop.index}, subjectlist_#{loop.index}" event="change"
listener="#{Registerbean.updateRecords(loop.index)}" />
<f:selectItem itemLabel="#{hardvalue['tutor.tutorial']}"
itemValue="tutorial" />
<f:selectItem itemLabel="#{hardvalue['tutor.conversaion']}"
itemValue="conversation" />
<f:selectItem itemLabel="#{hardvalue['tutor.music']}"
itemValue="music" />
<f:selectItem itemLabel="#{hardvalue['tutor.other']}"
itemValue="other" />
</p:selectOneMenu>
<h:panelGrid columns="3" >
<p:selectOneMenu style="width:230px" id="levellist1_#{loop.index}" value="#{Registerbean.selectedtutorialLevelFrom[loop.index]}"
>
<f:selectItems value="#{Registerbean.levellist}" />
</p:selectOneMenu>
<p:outputLabel value=" #{hardvalue['tutor.reg.to']} " />
<p:selectOneMenu style="width:230px" id="levellist2_#{loop.index}" value="#{Registerbean.selectedtutorialLevelTo[loop.index]}"
>
<f:selectItems value="#{Registerbean.levellist}" />
</p:selectOneMenu>
</h:panelGrid>
<p:selectOneMenu id="subjectlist_#{loop.index}" value="#{Registerbean.selectedtutorialSubject[loop.index]}"
style="width:230px;"
label="#{hardvalue['tutorsearch.select']}" filter="true" filterMatchMode="startsWith"
panelStyle="width:383px">
<f:selectItems value="#{Registerbean.subjectslist}" />
</p:selectOneMenu>
</h:panelGrid>
</c:forEach>
<p:commandButton id="moreButton" value="#{hardvalue['tutor.reg.addmore']}" update="rowCreator" process="#this" actionListener="#{Registerbean.addNewRow}" />
</p:panel>
</p:tab>
The above code is a tab in wizard. So I need to move on the next page after this one.
But I am not able to get the values as it do not let me assign to the array variables using indexes. Here is my backingbean
bean name: #ManagedBean(name="Registerbean")
private Tutor tutor= new Tutor();
private String[] selectedtutorialType= new String[size];
private String[] selectedtutorialLevelFrom= new String[size];
private String[] selectedtutorialLevelTo= new String[size];
private String[] selectedtutorialSubject= new String[size];
public void addNewRow(){
System.out.println("In add row");
size++;
selectedtutorialSubject=selectedtutorialLevelTo= selectedtutorialLevelFrom=selectedtutorialType=new String[size];
}
Here is my flowlistner through which I am just checking about the values of this tab. flowListener="#{Registerbean.onFlowProcess}"
public String onFlowProcess(FlowEvent event) {
System.out.println("tab id is:"+event.getOldStep());
if(event.getOldStep().equalsIgnoreCase("catagoryTab")){
for(int i=0;i<selectedtutorialType.length;i++){
System.out.println("selectedtutorialType : "+selectedtutorialType[i]);
System.out.println("selectedtutorialLevelFrom : "+selectedtutorialLevelFrom[i]);
System.out.println("selectedtutorialLevelTo : "+selectedtutorialLevelTo[i]);
System.out.println("selectedtutorialSubject : "+selectedtutorialSubject[i]);
}
}
return event.getNewStep();
}
What I want is : I want to draw components. on add row A component line will be added here. first one of the component's value changes, it reflacts the values of other two in that row only. but I is not doing the same. As the next button of p:wizard is not allowing me to move upword.
for updates it uses this function of backing bean.
public void updateRecords(int index) {
System.out.println("In update records: "+index);
levellist = new ArrayList<String>();
if (selectedtutorialType[index].equals("tutorial")) {
subjectslist = Arrays.asList(tutorialSubject);
levellist = Arrays.asList(tutorialLevel);
System.out.println("tutorial selection done..");
return;
} else if (selectedtutorialType[index].equals("conversation")) {
subjectslist = Arrays.asList(conversationSubject);
levellist = Arrays.asList(conversationLevel);
System.out.println("Conversation selection done..");
return;
} else if (selectedtutorialType[index].equals("music")) {
subjectslist = Arrays.asList(musicSubject);
levellist = Arrays.asList(musicLevel);
System.out.println("Music selection done..");
return;
} else {
subjectslist = Arrays.asList(otherSubject);
levellist = Arrays.asList(otherLevel);
System.out.println("Other selection done..");
return;
}
}
What to do. Plz help. Any other detail for this, if I am missing, let me know.
Thanks
I have a <p:panelGrid> like this:
<p:panelGrid style="margin:inherit !important; width: 100%;
display: flex !important;"
styleClass="new_player_panel">
<p:row>
<p:column>
<p:outputLabel value="Name in passport: " />
</p:column>
<p:column>
<p:inputText id="nameInPassport"
value="#{firstPlayerLoginManagedBean.surnameInPassport}"
required="true">
</p:inputText>
</p:column>
<p:column>
<p:message for="nameInPassport" display="icon" />
</p:column>
</p:row>
<p:row>
<p:column>
<p:outputLabel value="Firstname in passport:" />
</p:column>
<p:column>
<p:inputText id="firstnameInPassport" label="Utazási"
value="#{firstPlayerLoginManagedBean.firstnameInPassport}"
required="true">
</p:inputText>
</p:column>
<p:column>
<p:message for="firstnameInPassport" display="icon" />
</p:column>
</p:row>
</p:panelGrid>
and so on.
I tried to create this with dataGrid(managedbean, inputfields in lists), but <p:dataGrid> is not the perfect way to do my task exactly. I want to get behavior like this: If I click the plus icon next to the nationality field then creates another <p:inputText> for my second nationality and the other part of the form stay in the same state, and the new field push down the other fields. I have to use it a lot parts of my application. thanks in advance.
You can use <ui:repeat> to achieve this functionality, this is how you can achieve this functionality:
*.xhtml page, you build nationality field dynamically after you press "Add Nationality" button.
<h:outputPanel id="nationality_container">
<ui:repeat value="#{bean.passport.nationalities}" var="nationality">
<h:outputLabel value="#{bean.getNationalyLabel(nationality)}"
<h:inputText value="#{nationality}"/>
</ui:repeat>
</h:outputPanel>
<h:commandButton value="Add Nationality" listener="#{bean.addNationality}" update="nationality_container"/>
Backing Bean:
public Bean{
private Passport passport;
//adding new nationality and set its index
public void addNationality(){ //adding new nationality and set its index
passport.getNationalities.add(new Nationality(passport.getNationalities.size()));
}
//this method return you appropriate label, for id = 1 it's "First Nationality", and so on
public String getNationalityLabel(Nationality nationality){
if(nationality.id == 1){
return "Nationality";
}else if(nationality.id == 2){
return "Second nationality";
}
...
}
}
Object passport which encapsulates List<Nationality> nationalities;
public Passport{
...
private List<Nationality> nationalities;
...
}
Object Nationality with parameter index to store its index, first, second, third.
public Nationality{
int index; //1,2,3... first, second, third nationality, etc...
String nationality;
public Nationality(int index){
this.index = index;
}
}
Of course you can find a more elegant solution for your task, but using <ui:repeat> tag is required.
Pay attention that I didn't test this code, this is only general idea how this functionality should be implemented.
I'm working with JSF Primefaces and I want to make a search and show results in but results won't show, I'm doing this with Result type and had implemented like this in JSF 2.1 whith MyFaces tomahawk, but now with primefaces this doesn't work, here is my code
<h:form id="buscar_sucursal">
<p:panel style="width: 800px">
<h:panelGrid columns="5">
<h:outputText value="Criterio: " />
<p:selectOneMenu id="citerio" value="#{SucursalesBean.criterio}">
<f:selectItem itemValue="1" itemLabel="CVE SUCURSAL"></f:selectItem>
<f:selectItem itemValue="2" itemLabel="NOMBRE"></f:selectItem>
</p:selectOneMenu>
<h:outputText value="Valor: " />
<p:inputText id="valor" value="#{SucursalesBean.valor}"></p:inputText>
<p:commandButton action="#{SucursalesBean.buscar}" value="Buscar"></p:commandButton>
</h:panelGrid>
</p:panel>
<p:dataTable id="sucursalesTable" var="suc" value="#{SucursalesBean.sucursalesTable}">
<p:column headerText="Id">
<h:outputText value=""></h:outputText>
</p:column>
<p:column headerText="Cve">
<h:outputText value="#{suc.cve_sucursal}"></h:outputText>
</p:column>
<p:column headerText="Sucursal">
<h:outputText value="#{suc.sucursal}"></h:outputText>
</p:column>
<p:column headerText="Domicilio">
</p:column>
<p:column headerText="Contraseña">
</p:column>
<p:column headerText="Accion">
<h:commandLink value="Editar"></h:commandLink> /
<h:commandLink value="Eliminar"></h:commandLink>
</p:column>
</p:dataTable>
</h:form>
And the code of my ManagedBean
public Result getSucursalesTable()
{
return this.sucursalesTable;
}
public void setSucursalesTable(Result sucursalesTable)
{
this.sucursalesTable = sucursalesTable;
}
public void buscar() throws ClassNotFoundException
{
HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
this.valor = request.getParameter("buscar_sucursal:valor");
try
{
LoginBean loginBean = (LoginBean) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("LoginBean");
Connection conn = loginBean.getConectar_db();
//int id_empresa = loginBean.getId_empresa();
ArrayList<SucursalesBean> al = new ArrayList<SucursalesBean>();
st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
ResultSet rs = null;
//ResultSet rs = st.executeQuery("SELECT *FROM clientes WHERE id_cliente='"+request.getParameter("id_cliente")+"';"); // AND id_contribuyente='' AND id_empresa=''
//if(request.getParameter("sucursales:id_sucursal") != null)
//rs = st.executeQuery("SELECT *FROM sucursales WHERE id_sucursal='"+request.getParameter("sucursales:id_sucursal")+"' AND id_empresa='"+loginBean.getId_empresa()+"' AND id_contribuyente='"+loginBean.getId_contribuyente()+"';"); // AND id_contribuyente='' AND id_empresa=''
if(getCriterio().toString() != null)
{
if(getCriterio().toString().equals("1"))
rs = st.executeQuery("SELECT cve_sucursal,sucursal FROM sucursales WHERE cve_sucursal='"+this.valor+"' AND id_empresa='"+loginBean.getId_empresa()+"' AND id_contribuyente='"+loginBean.getId_contribuyente()+"';");
if(getCriterio().toString().equals("2"))
rs = st.executeQuery("SELECT *FROM sucursales WHERE sucursal LIKE '%"+this.valor+"%' AND id_empresa='"+loginBean.getId_empresa()+"' AND id_contribuyente='"+loginBean.getId_contribuyente()+"';");
}
this.sucursalesTable = ResultSupport.toResult(rs);
//this.sucursalesTable = rs;
//setSucursalesTable(ResultSupport.toResult(rs));
/*while(rs.next())
{
//out.println("<tr><td>"+rs.getString("sucursal")+"</td><td>"+rs.getString("cve_sucursal")+"</td><td>"+rs.getString("telefono")+"</td><td>"+rs.getString("e_mail")+"</td><td>"+rs.getString("calle")+"</td><td><a href='sucursales.jsp?accion=editar&id_sucursal="+rs.getString("id_sucursal")+"'>Editar</a></td><td></td></tr>");
//setId_sucursal(String.valueOf(rs.getInt("id_sucursal")));
setCve_sucursal(rs.getString("cve_sucursal"));
setSucursal(rs.getString("sucursal"));
al.add(this);
}
this.sucursalesTable = al;*/
}
catch(SQLException ex)
{
}
}
I don't want to use serialized objects in order to use List type because I think it's to much code for doing something that supposed to be simple, even if this it's not the best aproach.
My doubt it's if Primefaces has support for Result type or am I lost with this and maybe that's why this aproach isn't working.
Any help I really appreciate thank in advance
It looks to me as you've converted a h:commandButton to p:commandButton. The first by default uses non-ajax request, but the latter uses an ajax request. If correct, you just need to tell the button which components to process during and update after the request:
<p:commandButton action="#{SucursalesBean.buscar}"
value="Buscar"
process="criterio valor"
update="sucursalesTable" />
Or use a non-ajax request:
<p:commandButton action="#{SucursalesBean.buscar}"
value="Buscar"
ajax="false" />
i am using jsf and i am trying to show a hidden panel this what i tried
<h:commandButton update=":outPanel" actionListener="#{SelectBean.mod1()}" image="Ressources/images/update.png" style="vertical-align:middle" >
Modifier
</h:commandButton>
<p:panel visible="#{SelectBean.bol}" closable="true" toggleable="true" id="outPanel" styleClass="outPanel" widgetVar="outpanel">
<h:outputLabel value="Nom " />
<h:inputText value="#{SelectBean.nom}" />
<br/>
<h:outputLabel value="Experience " />
<h:inputText value="#{SelectBean.exp}" />
<br/>
<h:commandButton value="Modifier"/>
</p:panel>
my bean is
private boolean bol=false;
public boolean getBol() {
return bol;
}
public void setBol(boolean bol) {
this.bol = bol;
}
public String mod1()
{
bol = true;
return "success";
}
but this thing not working the panel is always hidden.
Try like this, your panel will be shown if bol is true
<p:panel rendered="#{selectBean.bol}" closable="true" toggleable="true" id="outPanel" styleClass="outPanel" widgetVar="outpanel">
Also i think you have wrong syntax, you should call methods and variables of your class through selectBean but not SelectBean
I have a jsf page that I can't update the value of some checkboxes in a list of userDamain objects, in fact this is a part of my jsf page :
<h:outputText value="USER's rights list: "></h:outputText>
<p:dataTable id="userss" var="userr" value="#{userMB.userListe}">
<p:column>
<f:facet name="header"><h:outputText value="FirstName" /></f:facet>
<h:outputText value="#{userr.firstName}" />
</p:column>
<p:column>
<h:panelGrid columns="1" style="margin-bottom:10px" cellpadding="5">
<h:outputText value="Basic Usage: " />
<p:selectBooleanCheckbox value="#{userr.deletee}" immediate="true" actionListener="#{userr.deletee}" />
</h:panelGrid>
<p:commandButton value="Submit" update="display" oncomplete="dlg.show()" />
<p:dialog header="Selected Values" modal="true" showEffect="fade" hideEffect="fade" widgetVar="dlg">
<h:panelGrid columns="1" id="display">
<h:outputText value="Value 1: #{userr.deletee}" />
</h:panelGrid>
</p:dialog>
</p:column>
when I click on the boolean button 'Submit', the value of the userr.deletee is always false ( the default value ) and it's not updated anyway, I tried to use the Listner and actionListener in the booleanButton but it doesn't work, I also tried the postValidate event, so if someone has any idea of that, I would be graceful.
this is a part of my managed bean:
private List<UserDomain> userListe ;
public List<UserDomain> getUserListe() {
return this.userListe;
}
public void loadUserListe(){
this.userListe = new ArrayList<UserDomain>();
this.userListe.addAll(getUserServicee().getAll());
}
public void setUserListe(List<UserDomain> userListe) {
this.userListe = userListe;
}
a part of the userDomain bean:
...
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
#Transient
private boolean deletee;
public boolean isDeletee() {
return deletee;
}
public void setDeletee(boolean deletee) {
this.deletee = deletee;
}
I found out a solution which seems logic to me, I added to my checkbox an ajax behavior to execute a method and an attribute which called in this method to get the whole userDomain object, so on I can get the user.deletee value, here is a part of the code I m talking about:
<h:panelGrid columns="1" style="margin-bottom:10px" cellpadding="5">
<h:outputText value="Delete Right: " />
<p:selectBooleanCheckbox value="#{userr.deletee}">
<f:ajax execute="#this" listener="#{userMB.saveUserRights}" />
<f:attribute name="user" value="#{userr}" />
</p:selectBooleanCheckbox>
</h:panelGrid>
I hope this will be helpful for you