How integrate themeSwitcher in a menubar with primefaces? - primefaces

Is it possible to use or integrate themeSwitcher in a menubar
My idea is to transform this :
<p:themeSwitcher id="basic" value="#{themeSwitcherView.theme}" style="width:165px">
<f:selectItem itemLabel="Choose Theme" itemValue="" />
<f:selectItems value="#{themeSwitcherView.themes}" />
<p:ajax listener="#{themeSwitcherView.saveTheme}" />
</p:themeSwitcher>
and
public void saveTheme(AjaxBehaviorEvent ajax) {
setTheme((String) ((ThemeSwitcher)ajax.getSource()).getValue());
}
to that (begining of solution from here
<p:submenu label="Theme" >
<c:forEach items="#{themeSwitcherView.themes}" var="item">
<p:menuitem value="#{item}" actionListener="#{themeSwitcherView.saveTheme}" />
</c:forEach>
</p:submenu>
but don't work, I get the list but no action made !
thank you

Related

I cannot update menuitem of MenuBar primefaces

I have this code in xhtml
<p:menubar style="float:right; border: none; background-color: transparent; ">
<p:submenu label="#{bundlePantallas.txt_Acciones}" icon="ui-icon-gear" styleClass="botonVolver botonVolver:hover" style="right:12px">
<p:menuitem id="genInform" value="#{bundlePantallas.txt_GenerarInforme}" icon="ui-icon-disk" ajax="true" onclick="PrimeFaces.monitorDownload(start, stop);" update="growl" disabled="#{alumnoHAController.selected eq null}">
<p:fileDownload value="#{informesBean.informeAlumno()}"/>
</p:menuitem>
<p:menuitem value="#{bundlePantallas.EnviarCorreo}" icon="ui-icon-mail-closed" actionListener="#{menuController.abrirDialogoCorreo()}" update="growl"/>
</p:submenu>
// .... rest code ...
And I try that when I unselected a row on this datatable:
<p:dataTable id="datalist" widgetVar="datalistW" value="#{alumnoHAController.items}" var="item"
selectionMode="single" selection="#{alumnoHAController.selected}"
paginator="true" rowKey="#{item.idAlumno}" emptyMessage="#{bundlePantallas.texto_SinDatos}"
rowIndexVar="rowIndex" rowStyleClass="#{(rowIndex mod 2) eq 0 ? 'dataTableFila1' : 'dataTableFila2'}"
rows="10" rowsPerPageTemplate="10,20,30,40,50">
<p:ajax event="rowSelect" update="createButton viewButton editButton deleteButton"/>
<p:ajax event="rowUnselect" update="createButton viewButton editButton deleteButton"/>
<p:column width="3%">
<p:rowToggler />
</p:column>
the menuItem will be disabled if I didn't select any column of the previous datatable.
I don't know where I forgot the update because the item to be disabled the first time when I enter to this page (bean.selected = null in java code) but when I selected some one the menuitem remains disabled until that I entry in the view or edit button (on java code selected remains)

I would like to capture only ID with autocomplete with POJO Pimefaces

I need to capture the ID only instead of object. Here is my code snippet:
<p:outputLabel value="Buscar Aval:" for="aval"/>
<p:autoComplete id="aval" value="#{tipocambioBean.tipoc.modelo}"
completeMethod="#{anexoBean.filtrarAval}" var="aval"
itemLabel="#{aval.nombres}" itemValue="#{aval.idanexo}">
<o:converter converterId="omnifaces.ListConverter" list="#{anexoBean.anexos}"/>
<p:ajax event="itemSelect" process="#form" />
</p:autoComplete>
Well I solved it.
only I need to do is to remove the converter and change itemValue, Here is my code snippet:
<p:outputLabel value="Buscar Aval:" />
<p:autoComplete value="#{tipocambioBean.tipoc.modelo}"
completeMethod="#{anexoBean.filtrarAval}" var="aval"
itemLabel="#{aval.nombres}" itemValue="#{aval.idanexo}">
<p:ajax event="itemSelect" process="#form" />
</p:autoComplete>

I'm stuck on dynamic panel

I met a problem for two days. nowhere I advance
my problem is to make a dynamic content in a panel according to the selected element in the list p: selectOneMenu
<h:outputLabel value="Categorie :" />
<p:selectOneMenu value="#{composantbean.selectedCategoryId}" required="true" >
<f:selectItem itemLabel="Select categorie" itemValue="" />
<f:selectItems value="#{composantbean.listcat}" var="cat" itemValue="#{cat.nomCat}" itemLabel="#{cat.nomCat}" />
<p:ajax update="panl" event="change" listener="#{composantbean.catListener()}"/>
</p:selectOneMenu>
<p:panel id="panl" header ="Caracteristique selon la categorie" toggleable="true" rendered="true" >
<h:panelGrid id="panlecart" columns="2" cellpadding="5" rendered="true">
<c:forEach items="#{composantbean.categorie.proprietes}" var="var">
<h:outputText value="#{var.nomProp}"/>
<h:inputText value="" />
</c:forEach>
</h:panelGrid>
</p:panel>
content appears this is true but unfortunately it is not synchronized is displayed shift
but if I use another <p: selectOneMenu id = "panel" content is displayed and synchronized
Haw can I fixe my prblem .Please and thank you in advance
As Lucas said, it is a bad idea using c:foreach (and all kind of JSTL) in JSF, especially with ajax.
Here are references you should read, to know more about JSTL in JSF:
JSTL in JSF2 Facelets... makes sense?
https://rogerkeays.com/jsf-c-foreach-vs-ui-repeat
Using ui:repeat in h:panelGrid is not recommended also. You may read the discussion here.
So, IMHO, you should try another approach, such as using dataTable, as stated in above link.
Or, you could use html's table tag (<table>) as replacement of h:panelGrid, with html's tr and td tag inside ui:repeat. For example:
<h:outputLabel value="Categorie :" />
<p:selectOneMenu value="#{composantbean.selectedCategoryId}" required="true" >
<f:selectItem itemLabel="Select categorie" itemValue="" />
<f:selectItems value="#{composantbean.listcat}" var="cat" itemValue="#{cat.nomCat}" itemLabel="#{cat.nomCat}" />
<p:ajax update="panl" event="change" listener="#{composantbean.catListener()}"/>
</p:selectOneMenu>
<p:panel id="panl" header ="Caracteristique selon la categorie" toggleable="true" rendered="true" >
<table>
<ui:repeat value="#{composantbean.categorie.proprietes}" var="var">
<tr>
<td><h:outputText value="#{var.nomProp}" /></td>
<td><h:inputText value="" /></td>
</tr>
</ui:repeat>
</table>
</p:panel>

PrimeFaces Tabview Tab change not working

I have simple flow of 3 tabs. I have tested the Simple tabview example on showcase.
But When I change the first tab with my content, I can't switch to other tabs.
Kindly guide me with what is wrong that needs to be changed.
Earlier I was using Wizard but I had the same tab change problem there as clicking on next was taking me to the last tab everytime.
and Now facing other issue with Tabview
I am posting the code:
<h:form id="compositionmaster">
<p:tabView id="tabView">
<p:tab id="tab1" title="Committee Details">
<h:panelGrid columns="2" columnClasses="label, value">
<h:outputText value="Committee Type: " />
<p:selectOneMenu id="type" value="#{userWizard.comm.committeeType}" effect="fade">
<f:selectItem itemLabel="----Select----" itemValue="0" />
<f:selectItem itemLabel="New" itemValue="1" />
<f:selectItem itemLabel="Existing" itemValue="2" />
</p:selectOneMenu>
<h:outputText value="Concerned Division: " />
<p:selectOneMenu id="division" value="#{userWizard.comm.committeeSubType}" effect="fade">
<f:selectItem itemLabel="----Select----" itemValue="0" />
<f:selectItem itemLabel="Administration" itemValue="1"/>
<f:selectItem itemLabel="Finance" itemValue="2" />
<f:selectItem itemLabel="Marketing" itemValue="3" />
<f:selectItem itemLabel="Others" itemValue="4" />
</p:selectOneMenu>
<h:outputText value="Committee Name: " />
<p:inputText value="#{userWizard.comm.committeeName}" maxlength="100"/>
<h:outputText value="Subject: " />
<p:inputText value="#{userWizard.comm.committeeSubject}" maxlength="100" />
<h:outputText value="Description: " />
<p:inputText value="#{userWizard.comm.committeeDescription}" maxlength="500" />
<h:outputText value="Tenure of Committee: " />
<p:panelGrid columns="2" >
<p:inplace id="Tenure" label="From">
<p:calendar value="#{userWizard.comm.startDate}" id="start" showOn="button" />
</p:inplace>
<p:inplace label="To">
<p:calendar value="#{userWizard.comm.endDate}" id="end" showOn="button" />
</p:inplace>
</p:panelGrid>
<h:outputText value="Add Document: " />
<h:form enctype="multipart/form-data">
<p:fileUpload fileUploadListener="#{fileBean.handleFileUpload}" mode="advanced" update="messages" multiple="true" sizeLimit="100000" allowTypes="/(\.|\/)(gif|jpe?g|png|doc|pdf)$/"/>
</h:form>
</h:panelGrid>
</p:tab>
<p:tab id="tab2" title="Godfather Part II">
<h:panelGrid columns="2" cellpadding="10">
<h:outputText id="tab2Text" value="stature grows."/>
</h:panelGrid>
</p:tab>
<p:tab id="tab3" title="Godfather Part III">
<h:panelGrid columns="2" cellpadding="10">
<h:outputText id="tab3Text" value="After a promise that his family would one day be completely legitimate."/>
</h:panelGrid>
</p:tab>
</p:tabView>
</h:form>
Don't use nested forms
HTML doesn't allow nested forms, so you shouldn't use them in primefaces either.They can cause undesired behavior.
See: other stackoverflow questions, or a nice collection of things to avoid in JSF: here (note point 2)
This is the only problem I see in your code. Other than that in rare cases you might have problems if using ajax and not processing the whole form. But as I can see this is not the case in your code.

primefaces remotecommand partial process

I am working on webflow 2.3.1, primefaces 3.4.2 project.
As you see, i tried to update selectOneMenu according to parent city as shown at example from primefaces showcase. However i used p:remoteCommand to call webflow action.
At remoteCommand , if i set process="#this, subSelectOneMenu", action did not call . But if i did not set "process",it called action but it also give error for captcha which is empty.
How can i use remoteCommand to call action partially?
<h:form id="signUpUserInfo">
<p:panelGrid id="grid" columns="2">
<p:selectOneMenu id="citySelectOneMenu" value="#{userBean.address.cityId}" label="#{label.address_city}" onchange="selectionChanged()">
<f:selectItem itemValue="" itemLabel="" />
<f:selectItems value="#{flowScope.cityList}" />
</p:selectOneMenu >
<p:selectOneMenu id="subSelectOneMenu"
value="#{userBean.address.subId}" label="#{label.address_sub}">
<f:selectItem itemValue="" itemLabel="" />
<f:selectItems value="#{flowScope.subList}" />
</p:selectOneMenu>
<p:captcha id="captcha" label="Captcha" language="en" theme="white" required="true" secure="true" />
<f:facet name="footer">
<p:commandButton id="save" value="#{label.save_button}" ajax="false"
action="signUpStandartMember" update="signUpUserInfo" />
</f:facet>
</p:panelGrid>
<p:remoteCommand id="selectionChanged" name="selectionChanged" action="cityChangedAction" update="subSelectOneMenu" process="#this, subSelectOneMenu" />
</h:form>