my problem is that I use a template in pages. This template has a SelectOneMenu. I want to actualize the new selection value in all pages using this template. It should be the same component. Do I need websockets for this or is it possible to actualize the selection of this selectOneMenu without websockets (event-based communication).
My code snippet:
<h:form prependId="false" id="masterTemplateForm">
<p:menubar style="align">
<p:menuitem value="Tab1">
</p:menuitem>
<p:menuitem value="Tab2">
</p:menuitem>
<p:menuitem value="Tab3">
</p:menuitem>
<f:facet name="options">
<ui:insert name="tabTitle" />
<p:outputLabel value="Benutzer: " />
<p:selectOneMenu style="vertical-align:middle;" id="userSelect"
value="#{masterTemplateController.actualUser}"
converter="omnifaces.SelectItemsIndexConverter">
<f:selectItem itemLabel="-- Benutzer auswählen --" itemValue="#{null}" />
<f:selectItems var="currentUser"
value="#{masterTemplateController.findAllUser()}"
itemLabel="#{currentUser.benutzerName}" itemValue="#{currentUser}" />
<p:ajax update="userSelect" event="change" listener="#{masterTemplateController.selectUserHandler}" />
</p:selectOneMenu>
</f:facet>
</p:menubar>
</h:form>
<ui:insert name="bodyContent" />
Thanks in advance for any hints.
Related
I have a select and I want that when the user doesn't select anything it prints an error. So I use validator and my xhtml code is:
<p:selectOneMenu id="students"
value="#{studentsBean.selectedStudent}"
converter="studentsConverter" effect="fold">
<f:selectItem itemLabel="Select..." itemValue="" />
<f:selectItems value="#{studentsBean.studentsList}"
var="student" itemValue="#{student}"
itemLabel="#{student.name}" />
<p:ajax event="change" update="students" process="#this" />
<f:validator validatorId="studentNotNull" />
<f:ajax execute="#this" render="studentPanel"/>
</p:selectOneMenu>
<h:panelGroup id="studentPane">
<h:message for="students" style="color:red" />
</h:panelGroup>
The problem is that if I don't select anythin it print me "The students is not selected" while I choice an student the label it doesn't disappear.
the validatior works and I don't think I must write the code.
Anyone can help?
Can you try this
<p:selectOneMenu id="students"
value="#{studentsBean.selectedStudent}"
converter="studentsConverter" effect="fold"
required="true" requiredMessage="Student is required">
<f:selectItem itemLabel="Select..." noSelectionOption="true"/>
<f:selectItems value="#{studentsBean.studentsList}"
var="student"
itemValue="#{student}"
itemLabel="#{student.name}" />
</p:selectOneMenu>
Add in your form
<p:growl id="msgs" showDetail="true" life="3000"/>
and of course, update msgs in form submit
I would like to display a <p:panel> when selecting an item of <p:selectOneRadio>. It works when selecting for the first time, but after the ajax call it stops working.
<p:selectOneRadio id="console" value="#{myBean.membre}">
<f:selectItem itemLabel="a" itemValue="false" />
<f:selectItem itemLabel="b" itemValue="true" />
<p:ajax update="panel2,panel1" />
</p:selectOneRadio>
<p:panel id="panel1" visible="#{myBean.membre == false}"
closable="true" toggleable="true">
<ui:include src="a.xhtml" />
</p:panel>
<p:panel id="panel2" visible="#{myBean.membre == true}"
closable="true" toggleable="true">
<ui:include src="b.xhtml" />
</p:panel>
On PrimeFaces 4.0, I had to remove the closable attributes from the panels before I could toggle the visibility. I also added a form which is always required when working with form fields.
Here is my working solution:
<h:form id="testForm">
<p:selectOneRadio id="console" value="#{myBean.membre}">
<f:selectItem itemLabel="a" itemValue="false" />
<f:selectItem itemLabel="b" itemValue="true" />
<p:ajax update="panel2,panel1" />
</p:selectOneRadio>
<p:panel id="panel1" visible="#{not myBean.membre}" toggleable="true">
test 111
</p:panel>
<p:panel id="panel2" visible="#myBean.membre}" toggleable="true">
test 222
</p:panel>
</h:form>
Why the closable attribute conflicts with the visible attribute I don 't know. It is possible a bug or unplanned for combination.
I am using PF 5.2 for the web app. I wanted to use notificationBar to reside some data inputs and commandButton to trigger these inputs data to the backing bean. Therefore I put a commandButton inside the notificationBar but actionListener is not calling the backing bean method. CommandButton is defined with id of "filterBtn".
The .xhtml page code is in the below:
<h:form>
<p:notificationBar position="top" effect="slide" styleClass="top" widgetVar="bar" style="height:200px;">
<h:panelGrid columns="1">
<h:panelGrid id="filterGrid1" columns="4" >
<h:outputLabel id="vhclIdLbl" value="#{general.vehicleId}"/>
<p:inputText id="fMtsId" value="#{notifyBean.fMtsId}" style="width:200px"/>
<h:outputLabel id="serialNoLabel" value="#{general.serialNo}"/>
<p:inputText id="fSerialNo" value="#{notifyBean.fSerialNo}" style="width:200px"/>
<h:outputLabel id="brandLbl" value="#{general.brand}"/>
<p:selectCheckboxMenu id="fBrand" value="#{notifyBean.fBrands}" effect="slide" style="width:210px"
appendTo="#this">
<f:selectItem itemLabel="#{general.pleaseSelect}" itemValue=""/>
<f:selectItems value="#{notifyBean.brandList}"/>
</p:selectCheckboxMenu>
<h:outputLabel id="modelLabel" value="#{general.model}"/>
<p:selectCheckboxMenu id="fModel" value="#{notifyBean.fModels}" effect="slide" style="width:210px"
appendTo="#this">
<f:selectItem itemLabel="#{general.pleaseSelect}" itemValue=""/>
<f:selectItems value="#{notifyBean.modelList}"/>
</p:selectCheckboxMenu>
<h:outputLabel id="provLabel" value="#{general.province}"/>
<p:selectCheckboxMenu id="fProvince" value="#{notifyBean.fProvinces}" effect="slide" style="width:210px"
filter="true" filterMatchMode="startsWith" appendTo="#this">
<f:selectItem itemLabel="#{general.pleaseSelect}" itemValue=""/>
<f:selectItems value="#{notifyBean.provinceList}"/>
</p:selectCheckboxMenu>
<h:outputLabel id="regionLabel" value="#{general.region}"/>
<p:selectCheckboxMenu id="fRegion" value="#{notifyBean.fRegions}" effect="slide" style="width:210px"
appendTo="#this">
<f:selectItem itemLabel="#{general.pleaseSelect}" itemValue=""/>
<f:selectItems value="#{notifyBean.regionList}"/>
</p:selectCheckboxMenu>
</h:panelGrid>
<p:commandButton id="filterBtn" value="Filter" actionListener="#{notifyBean.filterByProperties()}" icon="ui-icon-arrow-1-n"/>
<p:commandButton value="Hide" onclick="PF('bar').hide()" type="button" icon="ui-icon-arrow-1-n"/>
</h:panelGrid>
</p:notificationBar>
</h:form>
I know it is a simple use of the components but it is not working. Any help?
The notificationBar should not be embedded in a form. Just exchange the notificationBar and form tags, so the form is within the notificationbar.
<p:notificationBar position="top" effect="slide" styleClass="top" widgetVar="bar">
<h:form>
<p:commandButton value="yes" actionListener="#{backingBean.onDeleteButton}" onclick="PF('bar').hide()" />
<p:commandButton value="no" onclick="PF('bar').hide()" />
</h:form>
</p:notificationBar>
I want to use other primefaces components in p:menuitem. Components display in page but actionlistener doesn't work and inputtext's value doesn't push to bean's value1 attribute. Is there any way to handle this problem?
<p:commandButton id="dynaButton" value="Search" type="button" icon="ui-icon-extlink"/>
<p:slideMenu overlay="true" trigger="dynaButton" my="left top" at="left bottom" style="width:180px">
<p:submenu label="Search">
<p:menuitem>
<p:outputLabel value="Search by Id" />
<p:inputText value="#{bean.value1}" />
<p:commandButton value="save" actionListener="#{bean.method1}" />
</p:menuitem>
</p:submenu>
<p:submenu label="Search By Product">
<p:menuitem value="Delete" ajax="false" icon="ui-icon-close"/>
</p:submenu>
<p:submenu label="Location" icon="ui-icon-extlink">
<p:submenu label="Prime Links">
<p:menuitem value="Prime" url="http://www.prime.com.tr" />
<p:menuitem value="PrimeFaces" url="http://www.primefaces.org" />
</p:submenu>
<p:menuitem value="Mobile" />
</p:submenu>
</p:slideMenu>
Try change your code to the following:
<p:menuitem>
<p:outputLabel value="Search by Id" />
<p:inputText id="inputField" value="#{bean.value1}" />
<p:commandButton process="inputField #this" value="save" actionListener="#{bean.method1}" />
</p:menuitem>
Check these answers too:
Why to add process=“#this” explicitly to p:commandButton to get action invoked?
Understanding process and update attributes of PrimeFaces
You miss the update attribute.
Note that menuitems can be directly processed, but cannot be directly updated, you need to update the entire menu
<p:slideMenu id="menu" ...>
<p:submenu label="Search">
<p:menuitem id="item">
<p:outputLabel value="Search by Id" />
<p:inputText value="#{bean.value1}" />
<p:commandButton value="save" actionListener="#{bean.method1}" process="item" update="menu" />
<h:outputText value="#{bean.value1}" />
</p:menuitem>
</p:submenu>
</p:slideMenu>
i am beginner in JSF ,i have a problem with selectonemenu item.When i choose the an item ,for example ' FirstLabel',outputpanel should be shown.However ,selectone menu does not update my choice.I use primefaces 3.1 library.How can i solve this problem.Thanks for helps.
<p:selectOneMenu value="#{denemeView.str}" effect="fold" editable="true" >
<f:selectItem itemLabel="Please choose!." itemValue="" />
<f:selectItem itemLabel="FirstLabel" itemValue="1" />
<f:selectItem itemLabel="SecondLabel" itemValue="2" />
<p:ajax process="#this" update=":Form2:panel1"/>
<p:ajax process="#this" update=":Form2:panel2"/>
</p:selectOneMenu>
</p:outputPanel>
<p:outputPanel id="panel1" rendered="#{denemeView.str=='1'}">
<h:outputText value="Output: * " />
<p:inputText id="out" value="#{denemeView.islem}" />
</p:outputPanel>
<p:outputPanel id="panel2" rendered="#{denemeView.str=='2'}">
<h:outputText value="True choice! " />
</p:outputPanel>
If a JSF component has rendered="false" set then it's not redered (the component object is not present in the object tree) and cannot be updated using <p:ajax update="someId"/> or <f:ajax render="someId"/>. What you need to do is wrap these two panels in an outer panel and update that one. Something like this:
<p:ajax process="#this" update="outerPanel"/>
...
<p:outputPanel id="outerPanel">
<p:outputPanel id="panel1" rendered="#{denemeView.str=='1'}">
<h:outputText value="Output: * " />
<p:inputText id="out" value="#{denemeView.islem}" />
</p:outputPanel>
<p:outputPanel id="panel2" rendered="#{denemeView.str=='2'}">
<h:outputText value="True choice! " />
</p:outputPanel>
</p:outputPanel>
See here for a similar problem.