Please refer the following image:
and my code is as follows:
<h:selectOneRadio group="result" value="#{sampleCOntroller.testRslt}">
<p:column>
<f:selectItem itemValue="PS" />
</p:column>
<p:column>
<f:selectItem itemValue="NE" />
</p:column>
<p:column>
<f:selectItem itemValue="NA" />
</p:column>
</h:selectOneRadio>
but I don't even get the radio buttons and just blank is displayed.
How can I do this?
Related
I 'record' objects and I put them in a datatable. A record has a boolean value 'Ignored', my idea is to make a filter so that it either shows all ignored records or everything. Here is my code:
<p:column headerText="Status" filterMatchMode="equals" filterBy="#{record.ignored}">
<f:facet name="filter">
<p:selectOneButton onchange="PF('logTable').filter()">
<f:converter converterId="javax.faces.Boolean" />
<f:selectItem itemLabel="All" itemValue="" />
<f:selectItem itemLabel="Ignored" itemValue="#{record.ignored}" />
</p:selectOneButton>
</f:facet>
<h:outputText value="#{record.status}" />
</p:column>
For some reason it is not working properly which i could not find, after searching for some examples online.
The item value for this item
<f:selectItem itemLabel="Ignored" itemValue="#{record.ignored}" />
should be either true or false since that is the condition that will be check during the filtering of the records
<f:selectItem itemLabel="Ignored" itemValue="true" />
I want to create webpage having table with radio buttons in primefaces using datatable component like below.
I found one solution to implement custom component as mentioned in http://www.javaworld.com/article/2077687/enterprise-java/group-radio-buttons-inside-a-jsf-datatable-component.html for JSF.
But it is time taking and a lot of code.
Primefaces provides the custom layout for selectOneRadio. I implemented the table using the custom layout example of selectOneRadio as below. In this first column has width zero which contains the radio button.
<p:dataTable id ="employeeTable" rowIndexVar="rowId" var ="emp" value ="#{employeeList.employeeData}" widgetvar ="employeeTable" resizableColumns="true">
<p:column headerText="" style="width:0px;">
<p:selectOneRadio id="action" value="#{emp.status}" layout ="custom">
<f:selectItem itemLabel="Yes" itemValue="Yes" />
<f:selectItem itemLabel="No" itemValue="No" />
<f:selectItem itemLabel="Amendment" itemValue="Amendment" />
<f:selectItem itemLabel="KIV" itemValue="KIV" />
</p:selectOneRadio>
</p:column>
<p:column headerText="Personnel No">
<h:outputText value="#{emp.perNum}" />
</p:column>
<p:column headerText="Empl Name">
<h:outputText value="#{emp.name}" />
</p:column>
<p:column headerText="Yes">
<p:radioButton for="action" itemIndex="0" />
</p:column>
<p:column headerText="No">
<p:radioButton for="action" itemIndex="1" />
</p:column>
<p:column headerText="Amendment">
<p:radioButton for="action" itemIndex="2" />
</p:column>
<p:column headerText="KIV">
<p:radioButton for="action" itemIndex="3" />
</p:column>
</datatable>
Use p:selectOneRadio outside of your dataTable with layout attribute set to "custom". Fill this radio with f:selectItems same as data provided to dataTable via "value" parameter.
<p:selectOneRadio id="customRadio"
value="#{beanMB.selectedItem}"
layout="custom">
<f:selectItems value="#{beanMB.tableItems}"
var="item"
itemValue="#{item.radioValue}"
itemLabel="#{item.radioLabel}"/>
</p:selectOneRadio>
In dataTable column use p:radioButton with itemIndex matching current rowIndex.
<p:dataTable var="item"
rowIndexVar="rowIndex"
value="#{beanMB.tableItems}">
<p:column headerText="Choice">
<p:radioButton for="#form:customRadio"
itemIndex="#{rowIndex}"
rendered="#{item.radioRendered}"/>
</p:column>
</p:dataTable>
I'm working with a <p:overlayPanel> that includes a couple of <p:selectOneMenu>s, as well as several other components. When the <p:selectOneMenu>s are opened, some of the fields fall outside of the <p:overlayPanel>, and clicking on them causes the panel to close. (See image below).
.
.
.
One solution would be to modify the <p:overlayPanel> as follows:
dismissable="false"
showCloseIcon="true"
Another would be to modify the <p:selectOneMenu>:
height="50"
I'm looking for some options for solutions that are as simple as possible and preferably don't involve a change to the UI (the above solutions both change the UI). Is there a way to keep the <p:overlayPanel> open when a click outside of it falls within one of its <p:selectMenu>s?
More Complete Code
<p:overlayPanel styleClass="col-settings-panel"
id="colSettingsPanel"
for="columnSettingsBtn"
hideEffect="fade"
widgetVar="wvcolSettingsPanel"
rendered="#{empty rendered ? 'true' : rendered}" >
<p:pickList id="pickList"
value="#{fileSearchPersonalizationBean.columns}"
var="column"
showSourceFilter="true"
itemLabel="#{column}"
itemValue="#{column}"
itemDisabled="#{column eq 'Ref No'}">
<p:ajax event="transfer" listener="#{fileSearchPersonalizationBean.onTransfer}" update="pickList availableCount selectedCount selectSortBy" />
<f:facet name="sourceCaption">
<h:outputText value="Available Columns ("/>
<h:outputText id="availableCount" value="#{fileSearchPersonalizationBean.sourceCount}"/>
<h:outputText value=")"/>
</f:facet>
<f:facet name="targetCaption">
<h:outputText value="Selected Columns ("/>
<h:outputText id="selectedCount" value="#{fileSearchPersonalizationBean.targetCount}"/>
<h:outputText value=")"/>
</f:facet>
</p:pickList>
<p:panelGrid columns="1">
<p:outputPanel styleClass="col-settings-panel-option">
<h:outputLabel value="Sort By: " />
<p:selectOneMenu id="selectSortBy"
value="#{fileSearchPersonalizationBean.sortBy}" >
<p:ajax listener="#{fileSearchPersonalizationBean.sortByChanged}" />
<f:selectItems id="sortByList" value="#{fileSearchPersonalizationBean.columns.target}" />
</p:selectOneMenu>
</p:outputPanel>
<p:outputPanel styleClass="col-settings-panel-option">
<h:outputLabel value="Items per Page:"/>
<p:selectOneMenu id="selectRows" value="#{fileSearchPersonalizationBean.sRows}" >
<f:selectItem itemLabel="10" itemValue="10" />
<f:selectItem itemLabel="25" itemValue="25" />
<f:selectItem itemLabel="50" itemValue="50" />
<f:selectItem itemLabel="100" itemValue="100" />
</p:selectOneMenu>
</p:outputPanel>
</p:panelGrid>
<p:panelGrid styleClass="toolbar" columns="2">
<p:outputPanel>
<p:commandButton styleClass="btn-secondary"
id="loadDefaults"
value="Reset Defaults"
update="selectSortBy pickList selectRows"
actionListener="#{fileSearchPersonalizationBean.loadDefaultVO}" />
</p:outputPanel>
<p:outputPanel styleClass="toolbar-right">
<p:commandButton styleClass="btn-secondary"
id="columnClose"
value="Cancel"
actionListener="#{fileSearchPersonalizationBean.panelCancel}"
immediate="false">
<f:attribute name="panelId" value="#{formId}:colSettingsPanel" />
</p:commandButton>
<p:commandButton styleClass="btn-primary"
id="columnSubmit"
value="Save & Apply"
actionListener="#{fileSearchPersonalizationBean.panelSave}"
oncomplete="refreshSearchResults();" >
<f:attribute name="panelId" value="#{formId}:colSettingsPanel" />
</p:commandButton>
</p:outputPanel>
</p:panelGrid>
</p:overlayPanel>`
I am creating a selectonemenu using Primefaces and JSF.
I want to appear a message saying "Choose one of the options". How can I do that?
This is the code:
<!--Gender-->
<p:selectOneMenu id="gender" value="#{users.gender}" required="true"
requiredMessage="Choose one of the options">
<f:selectItem itemLabel="Choose gender" itemValue="#{null}" />
<f:selectItem itemLabel="Male" itemValue="Male" />
<f:selectItem itemLabel="Female" itemValue="Female" />
</p:selectOneMenu>
Thanks
adding below on the submit button will work fine as well.
ajax="false"
*********************edited**********
As you requested, please find below block of codes that works fine for me ::
<h:form>
<p:panelGrid style="margin-top:5px;width:730px;">
<f:facet name="header">
<p:row >
<p:column colspan="20">Select Company</p:column>
</p:row>
</f:facet>
<p:row>
<p:column>
<p:selectOneMenu id="companyMenu" value="#{clientList.clientCode}"
style="width:550px;margin:5px;text-color:black" required="true"
requiredMessage="Please select a company !">
<f:selectItem itemLabel="Select a Company" noSelectionOption="true"
itemValue="#{null}" />
<f:selectItems value="#{clientList.clients.entrySet()}" var="entry"
itemValue="#{entry.key}" itemLabel="#{entry.value}" >
</f:selectItems>
</p:selectOneMenu>
</p:column>
<p:column>
<p:commandButton value="Submit" style="margin:5px;" action="#
{viewPayment.companyDetails(clientList.clientCode)}" ajax="false"/>
</p:column>
</p:row>
</p:panelGrid>
</h:form>
You can use :
if (users.getGender()==null) {
FacesContext.getCurrentInstance().addMessage(
null,
new FacesMessage(FacesMessage.SEVERITY_ERROR,
"Choose one of the options",
"Choose one of the options"));
}
SOLVED.I forgot to add the line <p:message for="gender" /> to the code. Thanks.
Iam trying to update a panel based selected data using primefaces selectonemenu and ajax listener was taken care by updating the panels.But my panel was not updated and selected item was shown at console window.That means ,The ajax call was got into managed bean.but its not updated at faces pages and mentioned my code
<p:panelGrid columns="1" style="align:center;width:80%" styleClass="companyHeaderGrid">
<p:row>
<p:column><h:outputLabel for="runobject" value="Run Object: " /></p:column>
<p:column>
<p:selectOneMenu id="selectedState" value="#{TAScheduleBean.selectedRunObjectItem}" >
<p:ajax listener="#{TAScheduleBean.changePanelState}" render="#this" update=":form:displayDailyPanel"/>
<f:selectItem itemLabel="Select One" itemValue="Select One" />
<f:selectItems value="#{TAScheduleBean.runObjectsValue}" />
</p:selectOneMenu>
</p:column>
</p:row>
<p:row id="displayDailyPanel" rendered="#{TAScheduleBean.appSelectedRunObject eq 'Daily'}">
<p:column>
<p:outputLabel value=" N days" />
<p:outputLabel value="Days=" /><p:inputText id="s"/>
</p:column>
</p:panelGrid>
I read relevant issues in the same forums and other forums also. but the issue is not resolved.How can i resolve this.Please help me
Update :-
ManagedBean
public class TAScheduleBean extends TASBean {
private String selectedRunObjectItem="";
private String appSelectedRunObject="";
TAScheduleBean(){
}
public void changePanelState(){
String methodName="changePanelState";
setPanelIsVisible(true);
TALogger.log(Logger.INFO, className,
methodName, "---------"+getSelectedRunObjectItem());
setAppSelectedRunObject(getSelectedRunObjectItem().trim());
}
}
Thanks guys.I resolved the issue.when we are selected item up to that time the row was not created because we called 'rendered' attribute.So i created panel and mentioned below code
<p:panel id="toppanel"> <------- added panel
<p:panelGrid columns="1" style="align:center;width:80%" styleClass="companyHeaderGrid">
<p:row>
<p:column><h:outputLabel for="runobject" value="Run Object: " /></p:column>
<p:column>
<p:selectOneMenu id="selectedState" value="#{TAScheduleBean.selectedRunObjectItem}" >
<p:ajax listener="#{TAScheduleBean.changePanelState}" render="#this" update="toppanel"/> <------changed
<f:selectItem itemLabel="Select One" itemValue="Select One" />
<f:selectItems value="#{TAScheduleBean.runObjectsValue}" />
</p:selectOneMenu>
</p:column>
</p:row>
<p:row id="displayDailyPanel" rendered="#{TAScheduleBean.appSelectedRunObject eq 'Daily'}">
<p:column>
<p:outputLabel value=" N days" />
<p:outputLabel value="Days=" /><p:inputText id="s"/>
</p:column>
</p:panelGrid>
</p:panel>
then its working fine.