Editable p:selectOneMenu - jsf

How to set placeholder in editable <p:selectOneMenu>?
In editable <p:selectOneMenu> of PrimeFaces, initial UI looks as below:
http://www.primefaces.org/showcase/ui/input/oneMenu.xhtml
(see the editable menu)
Is there a way to place a placeholder which says text like "Click to enter manual input" or to make user aware that this dropdown is editable.
Find the code snippet below for reference.
<div class="setupDataSection">
<div class="pageCenter pageCenterShortened">
<div style="float: left;" class="sectionTitle sectionTitleInline">
<h:outputLabel value="Tenant "/>
</div>
<div style="float: left; padding-left: 40px;">
<p:selectOneMenu id="tenant"
styleClass="ddlPOS"
style="width: 190px;"
label="Tenant"
value="#{onBoardingAction.selTenant}"
editable="true">
<p:watermark for="tenant"
value="Search with a keyword"
id="watermark" />
<f:selectItem itemLabel="Add new tenant" />
<f:selectItems value="#{onBoardingAction.tenants}" />
<p:ajax event="change"
execute="#this"
update="tenant region POS"
listener="#{onBoardingAction.settingRegions()}" />
</p:selectOneMenu>
</div>
</div>
</div>

Primefaces call it watermark SEE, If your SelectOneMenu is empty this water martk's text automatically appears
<p:watermark for="fileSize" value="Search with a keyword" id="watermark" />
Update
I have tested your code and It work fine for me if you are using template maybe your CSS overriding component try this, I just put p:watermark outside the component code:
<f:selectItem itemLabel="Add new tenant" />
<f:selectItems value="#{onBoardingAction.tenants}" />
<p:ajax event="change"
execute="#this"
update="tenant region POS""
listener="#{onBoardingAction.settingRegions()}" />
</p:selectOneMenu>
<p:watermark for="tenant"
value="Search with a keyword"
id="watermark" />
HOPE RESOLVED :)

Related

SelectBooleanCheckbox receives focus without mouseover

I have a weird problem with jsf components (h:inputFile & h:selectBooleanCheckbox).
Both components receive focus, even when my mouse is somewhere else on the page. Here is the code:
<h:form id="logoUpload" enctype="multipart/form-data">
<div>
<h:outputLabel rendered="true">
<h:inputFile id="companyLogo" label="file" value="#{fileHandlerBean.part}" >
<f:validator validatorId="FileUploadValidator" />
</h:inputFile>
</h:outputLabel>
</div>
<div class="clear" />
<h:outputLabel rendered="true">
<div>
<div style="width: 5%">
<h:selectBooleanCheckbox id="acceptToULogo" value="#{companyEditController.confirmToU}">
<p:ajax event="change" update="buttonLogo" />
</h:selectBooleanCheckbox>
</div>
<div style="width: 95%">
<h:outputText value="Some Text " />
</div>
<br />
<h:commandButton id="buttonLogo" styleClass="formbutton" value="Upload"
action="#{companyEditController.companyLogoUpload()}"
actionListener="#{fileHandlerBean.uploadCompanyLogo()}"
disabled="#{!companyEditController.confirmToU}"/>
</div>
</h:outputLabel>
</h:form>
If I move the mouse over the h:outputText the checkbox receives focus.
I had the same problem with the h:inputFile tag. I solved it by surrounding it with a h:outputLabel tag, but unfortunately it doesn´t workd with the selectBooleanCheckbox.
Did somebody have the same problem in the past and knows a solution?
This is because everything is wrapped in the h:outputLabel tag. This outputLable is rendered as a plain label html element.
You can see form the W3C specification that anything inside the label will toggle the control
The element does not render as anything special for the user. However, it provides a usability improvement for mouse users, because if the user clicks on the text within the element, it toggles the control
To fix this, you need to replace the h:output label tag using a h:panelGroup layout="block" which renders a <div>:
<h:panelGroup layout="block" rendered="true">
<div>
<div style="width: 5%">
<h:selectBooleanCheckbox id="acceptToULogo" >
<p:ajax event="change" update="buttonLogo" />
</h:selectBooleanCheckbox>
</div>
<div style="width: 95%">
<h:outputText value="Some Text " />
</div>
<br />
<h:commandButton id="buttonLogo" styleClass="formbutton" value="Upload"/>
</div>
</h:panelGroup>

h:inputText between p:selectManyCheckbox items

Is it possible, on some way, to display an h:inputText between the selectItems of a p:selectManyCheckbox?
What I'd like to have is:
checkbox1
checkbox2
inputTextIfCheckbox2IsMarked (disabled if not marked..)
checkbox 3
checkbox 4
I know how to do the enable/disable etc of the checkbox, but outside of the selectItems. I'd like to put it between them.
Is that possible on SOME way?
My solution is (with the inputText not between the selectItems):
<h:panelGrid columns="2">
<p:selectManyCheckbox converter="otherAdmissionReasonConverter"
id="otherAdmissionReasonCheckbox"
value="#{potentialDonorFileBackingBean.potentialDonorFile.generalPatientInformation.otherAdmissionReasons}"
layout="grid" columns="1">
<f:selectItems value="#{patientInformationBackingBean.otherAdmissionReasons}"
var="otherAdmissionReason"
itemValue="#{otherAdmissionReason}"
itemLabel="#{msgs['ar.'.concat(otherAdmissionReason)]}"/>
<p:ajax update="customAdmissionReasonGrid"/>
</p:selectManyCheckbox>
<h:panelGroup id="customAdmissionReasonGrid"
styleClass="customAdmissionReason">
<p:inputText id="customAdmissionReason"
disabled="#{!potentialDonorFileBackingBean.potentialDonorFile.generalPatientInformation.otherAdmissionReasonChecked()}"
value="#{potentialDonorFileBackingBean.potentialDonorFile.generalPatientInformation.customAdmissionReason}"/>
</h:panelGroup>
</h:panelGrid>
PrimeFaces: 5.2
For PrimeFaces < 5.2.3 you can't. For PrimeFaces >=5.2.3 you can use a custom layout like this (© PrimeFaces)
<h3>Custom Layout (since v5.2.3)</h3>
<p:outputPanel id="customPanel" style="margin-bottom:20px">
<p:selectManyCheckbox id="custom" value="#{checkboxView.selectedConsoles2}" layout="custom">
<f:selectItem itemLabel="Xbox SixSixSix" itemValue="Xbox SixSixSix" />
<f:selectItem itemLabel="PS9" itemValue="PS9" />
<f:selectItem itemLabel="Wii Them" itemValue="Wii Them" />
</p:selectManyCheckbox>
<div class="ui-grid ui-grid-responsive">
<div class="ui-grid-row">
<div class="ui-grid-col-4">
<h:outputLabel for="opt1" value="Xbox SixSixSix" style="display:block"/>
<p:checkbox id="opt1" for="custom" itemIndex="0" />
</div>
Some Custom Text between item 1 and 2
<div class="ui-grid-col-4">
<h:outputLabel for="opt2" value="PS9" style="display:block"/>
<p:checkbox id="opt2" for="custom" itemIndex="1" />
</div>
<div class="ui-grid-col-4">
<h:outputLabel for="opt3" value="Wii Them" style="display:block"/>
<p:checkbox id="opt3" for="custom" itemIndex="2" />
</div>
</div>
</div>
</p:outputPanel>

<p:selectOneMenu> generates input field behind select box

I'm trying to associate a label tag with my dropdown menu to make it accessible to screen readers. I've noticed that when using p:selectOneMenu primefaces generates an input element that should not be there. When applying p:outputLabel, it appears to work fine (ie you click on the label text and focus moves to the dropdown menu). However it turns out that the focus is in fact moving to the input element and the select element is not keyboard accessible (tabindex="-1"). Here's an example taken from the primefaces website:
http://www.primefaces.org/showcase/ui/input/oneMenu.xhtml
<h:form>
<p:messages autoUpdate="true" />
<h:panelGrid columns="2" style="margin-bottom:10px" cellpadding="5">
<p:outputLabel for="console" value="Basic:" />
<p:selectOneMenu id="console" value="#{selectOneMenuView.console}" style="width:125px">
<f:selectItem itemLabel="Select One" itemValue="" />
<f:selectItem itemLabel="Xbox One" itemValue="Xbox One" />
<f:selectItem itemLabel="PS4" itemValue="PS4" />
<f:selectItem itemLabel="Wii U" itemValue="Wii U" />
</p:selectOneMenu>
<p:outputLabel for="car" value="Grouping: " />
<p:selectOneMenu id="car" value="#{selectOneMenuView.car}">
<f:selectItem itemLabel="Select One" itemValue="" />
<f:selectItems value="#{selectOneMenuView.cars}" />
</p:selectOneMenu>
<p:outputLabel for="city" value="Editable: " />
<p:selectOneMenu id="city" value="#{selectOneMenuView.city}" effect="fold" editable="true">
<f:selectItem itemLabel="Select One" itemValue="" />
<f:selectItems value="#{selectOneMenuView.cities}" />
</p:selectOneMenu>
<p:outputLabel for="advanced" value="Advanced:" />
<p:selectOneMenu id="advanced" value="#{selectOneMenuView.theme}" converter="themeConverter" panelStyle="width:180px"
effect="fade" var="t" style="width:160px" filter="true" filterMatchMode="startsWith">
<f:selectItems value="#{selectOneMenuView.themes}" var="theme" itemLabel="#{theme.displayName}" itemValue="#{theme}" />
<p:column style="width:10%">
<h:outputText styleClass="ui-theme ui-theme-#{t.name}" />
</p:column>
<p:column>
<h:outputText value="#{t.displayName}" />
</p:column>
</p:selectOneMenu>
</h:panelGrid>
<p:commandButton value="Submit" update="display" oncomplete="PF('dlg').show()" icon="ui-icon-check" />
<p:dialog header="Values" modal="true" showEffect="bounce" widgetVar="dlg" resizable="false">
<p:panelGrid columns="2" id="display" columnClasses="label,value">
<h:outputText value="Basic:" />
<h:outputText value="#{selectOneMenuView.console}" />
<h:outputText value="Grouping:" />
<h:outputText value="#{selectOneMenuView.car}" />
<h:outputText value="Editable" />
<h:outputText value="#{selectOneMenuView.city}" />
<h:outputText value="Advanced:" />
<h:outputText value="#{selectOneMenuView.theme.displayName}" />
</p:panelGrid>
</p:dialog>
When you look at the page with just the html loaded, you can see each p:selectOneMenu generates an input as well as a select.
<td>
<label id="j_idt88:j_idt91" class="ui-outputlabel ui-widget" for="j_idt88:console_focus">Basic:</label>
</td>
<div id="j_idt88:console" class="ui-selectonemenu ui-widget ui-state-default ui-corner-all" style="width:125px">
<div class="ui-helper-hidden-accessible">
<input id="j_idt88:console_focus" name="j_idt88:console_focus" type="text" autocomplete="off">
</div>
<div class="ui-helper-hidden-accessible">
<select id="j_idt88:console_input" name="j_idt88:console_input" tabindex="-1" data-p-label="Basic" data-p-hl="onemenu">
<option value="">Select One</option><option value="Xbox One">Xbox One</option>
<option value="PS4">PS4</option>
<option value="Wii U">Wii U</option>
</select>
</div>
<label id="j_idt88:console_label" class="ui-selectonemenu-label ui-inputfield ui-corner-all">Select One</label>
<div class="ui-selectonemenu-trigger ui-state-default ui-corner-right">
<span class="ui-icon ui-icon-triangle-1-s ui-c"></span>
</div>
</div>
I'm looking to have the dropdown menu to behave like the JSF one h:selectOneMenu (when it comes to accessibility). Specific to the example, I want the "Basic:" label associated with it's dropdown menu so that when you click "Basic" focus moves to the dropdown menu. I also want a screen reader to actually treat it as a select element rather than an input element. So far I can't find a way to do this because of that input element that's generated. I'm currently using Primefaces 5.2. Does anyone know a way to prevent this input element from being generated?
I gave up on the p:selectOneMenu for two reasons : it is not accessible and it is a pain to use on a mobile device because it doesn't bring the native control picker (the "spinning wheel" on the iPad for instance).
Instead I use the h:selectOneMenu customized with something like :
<h:selectOneMenu
styleClass="ui-inputfield ui-widget ui-state-default ui-corner-all #{component.valid ? '' : 'ui-state-error'}"
onmouseover="$(this).addClass('ui-state-active')"
onmouseout="$(this).removeClass('ui-state-active')"
onfocus="$(this).addClass('ui-state-active ui-state-focus')"
onblur="$(this).removeClass('ui-state-active ui-state-focus')"/>
It doesn't look that bad, it is accessible and it works well with mobile device.

How to clear p:autoComplete values on page refresh or click back on browser in JSF using PrimeFaces?

using p:autoComplete to display city name and test name. Here i select one city name and/or test name Then refresh page Still displayed selected values and also after search goes to another page and then clicked on Back arrow on browser values are not clear.
Here we are using <p:autoComplete> to display dropdown values. Here is my code.
I tried with jQuery.
<script>
$(function () {
$("#homePageForm").attr("autocomplete", "off");
});
</script>
But it is not working.
<h:form id="homePageForm" styleClass="serform">
<p:panel id="validate_home" >
<div class="serbox subsel mydropbox">
<p:autoComplete dropdown="true"
required="true"
requiredMessage="Testname required"
id="testDD"
forceSelection="true"
maxlength="6"
cache="true"
update="testMsg"
queryDelay="100"
value="#{searchController.testName}"
completeMethod="#{searchController.completeTest}">
</p:autoComplete>
<p:message for="testDD" id="testMsg" />
<p:watermark for="testDD" value="Search TestName" id="testWatermark" />
</div>
<div class="serbox subsel mydropbox">
<p:autoComplete dropdown="true"
required="true"
requiredMessage="City Name required"
id="cityDD"
forceSelection="true"
maxlength="6"
cache="true"
queryDelay="100"
value="#{searchController.city}"
completeMethod="#{searchController.completeCity}">
<p:ajax event="itemSelect"
listener="#{searchController.onItemSelect}"
update="localityDD" />
</p:autoComplete>
<p:message for="cityDD" />
<p:watermark for="cityDD" value="Search City" id="cityWatermark" />
</div>
<div class="serbox subsel mydropbox">
<p:autoComplete dropdown="true"
required="false"
id="localityDD"
requiredMessage="Locality required"
forceSelection="true"
maxlength="6"
cache="true"
queryDelay="100"
value="#{searchController.locality}"
completeMethod="#{searchController.completeLocality}">
</p:autoComplete>
<p:watermark for="localityDD"
value="Search Locality"
id="localityWatermark" />
</div>
<div class="serbox subsel mydropbox">
<p:calendar required="false"
requiredMessage="Date required"
id="date"
value="#{searchController.date}"
pattern="MM/dd/yyyy">
<p:watermark for="date" value="Search Date" id="dateWatermark" />
</p:calendar>
<p:message for="date" />
</div>
<div class="serbox hserbtn">
<p:commandLink id="searchBtn"
update="validate_home"
action="#{searchController.simpleSearch}">
<p:graphicImage value="images/search_home.png" alt="" title="" />
</p:commandLink>
</div>
</p:panel>
</h:form>

Clicking on a row opens a new link, based on what was clicked

I am new to JSF, and I tried Googling this and going over BalusC's example, but failed. I have a datatable right now, which works, but what I want to acheive is that when you click on a row, I want to store some information in a bean of course, and then open a new page where I can display some more detail about the row that was clicked. Here is my code:
<h:panelGrid columns="2" style="margin-bottom:10px" cellpadding="5">
Degree:
<div class="degreeProgram">
<h:selectOneMenu onchange="submit()" valueChangeListener="#{course.degreeProgramChanged}">
<f:selectItems value="#{course.programs}" />
</h:selectOneMenu>
</div>
Major:
<div class="major">
<h:selectOneMenu onchange ="submit()" valueChangeListener="#{course.majorChanged}">
<f:selectItems value="#{course.majors}" />
</h:selectOneMenu>
</div>
Identifier:
<h:inputText value="#{course.identifier}"></h:inputText>
Course coordinator:
<div class="major">
<h:selectOneMenu onchange ="submit()" valueChangeListener="#{course.coordinatorChanged}">
<f:selectItems value="#{course.coordinators}" />
</h:selectOneMenu>
</div>
</h:panelGrid>
</h:form>
<b>Course Offering:</b>
<br></br>
<h:form>
<h:panelGrid columns="2" style="margin-bottom:10px" cellpadding="5">
Section:
<div class="degreeProgram">
<h:inputText value="#{course.section}"></h:inputText>
</div>
Semester
<div class="major">
<h:inputText value="#{course.semester}"></h:inputText>
</div>
Instructors:
<div class="major">
<h:selectOneMenu onchange ="submit()" valueChangeListener="#{course.coordinatorChanged}">
<f:selectItems value="#{course.instructors}" />
</h:selectOneMenu>
</div>
<h:commandButton value="submit" action="#{course.executeSearch()}"></h:commandButton>
</h:panelGrid>
</h:form>

Resources