JSF2 or primefaces p:selectManyCheckbox styling with icons - jsf

One question who styled manycheckboxes with icons?
<p:selectManyCheckbox value="#{Step4Bean.selectedItems}" id="tag-list" >
<f:selectItems value="#{Step4Bean.allItems}" var="item" itemLabel="#{item}" itemValue="#{item}"/>
</p:selectManyCheckbox>
I have check boxes with 6 items , I must have 2 rows with 3 items in each row, near each item must be one icon.
How we can solve this?
Here is a output example link
http://jpeg.am/images/?i=5692b9db7ea1d060bc7c97bcc788d6b8.jpg

PF already had the Grid layout for this component.
<h3>Grid Layout</h3>
<p:selectManyCheckbox id="grid" value="#{checkboxView.selectedCities}" layout="grid" columns="3">
<f:selectItems value="#{checkboxView.cities}" var="city" itemLabel="#{city}" itemValue="#{city}" />
</p:selectManyCheckbox>
But the latest PF 5.2.3 and 5.3-SNAPSHOT has custom layout options
<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 One" itemValue="Xbox One" />
<f:selectItem itemLabel="PS4" itemValue="PS4" />
<f:selectItem itemLabel="Wii U" itemValue="Wii U" />
</p:selectManyCheckbox>
<div class="ui-grid ui-grid-responsive">
<div class="ui-grid-row">
<div class="ui-grid-col-4">
<p:checkbox id="opt1" for="custom" itemIndex="0" />
</div>
<div class="ui-grid-col-4">
<p:checkbox id="opt2" for="custom" itemIndex="1" />
</div>
<div class="ui-grid-col-4">
<p:checkbox id="opt3" for="custom" itemIndex="2" />
</div>
</div>
<div class="ui-grid-row">
<div class="ui-grid-col-4">
<h:outputLabel for="opt1" value="Xbox One" />
</div>
<div class="ui-grid-col-4">
<h:outputLabel for="opt2" value="PS4" />
</div>
<div class="ui-grid-col-4">
<h:outputLabel for="opt3" value="Wii U" />
</div>
</div>
</div>
</p:outputPanel>
Not sure how and if the latest functionaly can be used with an <f:selectItems/> or only with multiple <f:selectItem/>. I suspect the latter
See also:
- See http://www.primefaces.org/showcase/ui/input/manyCheckbox.xhtml
(examples taken from the PF showcase!)

Related

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>

commandButton to commandLink in a login form

This is my xhtml login page ...
<div id="externalborderReg">
<p:spacer height="70px" />
<div id="loginForm" >
<h:form id="login" onsubmit="document.getElementById('login').action='j_security_check';" prependId="false">
<h:panelGrid columns="2">
<p:outputLabel for="j_username" value="Email:" />
<p:inputText id="j_username" name="j_username" placeholder="Email" required="true"/>
<p:outputLabel for="j_password" value="Password:" />
<p:password id="j_password" name="j_password" placeholder="Password" required="true" />
</h:panelGrid>
<p:spacer height="40px"/>
<div id="loginButton">
<p:commandButton id="submit" value="Login" ajax="false" />
</div>
</h:form>
</div>
</div>
Now i want to make the p:commandButton a h:commandLink but if i try change it the login button/link stops working ... how can i cahnge it???
Please help me ...

JSF ui:repeat with render

I want to use a ui:repeat or any other iterative tag to display a number of components once
for each item in an Array list.
<!-- print multiple mandates -->
<ui:repeat id="mandates" var="mandate" value="#{taxheadDirectDebit.mandates}">
<a4j:region id="remittanceDetailsSection"
rendered="#{(taxheadDirectDebit.accountFinancialInfo.registration.type != 'PREM') or (taxheadDirectDebit.accountFinancialInfo.registration.type != 'VAT')}">
<!-- Remittance Details -->
<fieldset><legend class="sub"> <h:outputText
value="#{msg['remittanceDetails.title']}" /> </legend>
<!-- Estimated Liability -->
<div class="field">
<div class="label"><label for="allocatedAmount"><h:outputText
for="estimatedLiability"
value="#{msg['remittanceDetails.estimatedLiability']}" /> </label><span
class="requiredFlag">*</span></div>
<div class="error">
<rich:message styleClass="errorText" for="estimatedLiability" />
</div>
<div class="input">
<h:inputText id="estimatedLiability" size="30"
maxlength="11" label="#{msg['registerContractPage1.subTaxNumber']}"
value="#{taxheadDirectDebit.estimatedLiability}">
<a4j:ajax event="change" render="remittanceFrequency" />
</h:inputText>
</div>
<br class="clear" />
</div>
<!-- Is Seasonal -->
<div class="field">
<div class="label"><label for="isSeasonal"> <h:outputText
for="isSeasonal"
value="#{msg['remittanceDetails.isTheNatureSeasonal']}" /> </label><span
class="requiredFlag">*</span></div>
<div class="error"><rich:message styleClass="errorText"
for="isSeasonal" /></div>
<div class="input"><h:selectOneRadio id="isSeasonal"
label="#{msg['remittanceDetails.isTheNatureSeasonal']}"
value="#{taxheadDirectDebit.isSeasonal}"
styleClass="radioLabelTop">
<ddo:twoOptionSelection />
<a4j:ajax event="click" render="remittanceFrequency" />
</h:selectOneRadio></div>
<br class="clear" />
</div>
</fieldset>
</a4j:region>
<!-- Remittance Frequency -->
<a4j:outputPanel id="remittanceFrequency">
<div class="field">
<div class="label"><label for="allocatedAmount"><h:outputText
for="estimatedLiability"
value="#{msg['remittanceDetails.estimatedLiability']}" /> </label><span
class="requiredFlag">*</span></div>
<div class="error">
<rich:message styleClass="errorText" for="estimatedLiability" />
</div>
<div class="input">
<h:inputText id="estimatedLiability" size="30"
maxlength="11" label="#{msg['registerContractPage1.subTaxNumber']}"
value="#{taxheadDirectDebit.estimatedLiability}">
<a4j:ajax event="change" render=":remittanceDetails:mandates:remittanceFrequency" />
</h:inputText>
</div>
<br class="clear" />
</div>
<fieldset><legend class="sub"> <h:outputText
value="#{msg['remittanceDetails.frequency']}" /> </legend>
<!-- Amount to be Debited -->
<div class="field">
<div class="label"><label for="amountEachMonth"><h:outputText
for="amountEachMonth"
value="#{msg['remittanceDetails.amountToBeDebited']}" /> </label></div>
<div class="error"><rich:message styleClass="errorText"
for="amountEachMonth" /></div>
<div class="input"><h:inputText id="amountEachMonth" size="30" readOnly="true"
maxlength="8" label="#{msg['remittanceDetails.amountToBeDebited']}"
value="#{mandate.remittanceDetails.amountEachMonth}">
<a4j:ajax event="change" render="remittanceFrequencyNoDebitedEachMonth"/>
</h:inputText></div>
<br class="clear" />
</div>
<a4j:outputPanel id="remittanceFrequencyNoDebitedEachMonth">
<!-- Months -->
<div class="field">
<div class="grid1"><h:outputText
value=" " /> 
</div>
<rich:panel styleClass="ddo-panel" rendered="#{taxheadDirectDebit.isSeasonal == 1}">
<div class="grid2"><div align="center">
<h:outputText value="#{msg['reviewDetails.reduce']}"/><div align="center"></div>
</div></div>
</rich:panel>
<rich:panel styleClass="ddo-panel" rendered="#{taxheadDirectDebit.action == 'AMEND'}">
<div class="grid3">
<div align="center">
<h:outputText value="#{msg['reviewDetails.suspend']}"/><div align="center"></div>
</div>
</div>
</rich:panel>
<rich:panel styleClass="ddo-panel" rendered="#{taxheadDirectDebit.isSeasonal == 1}">
<div class="grid2">
<div align="center">
<h:outputText value="#{msg['reviewDetails.exclude']}"/><div align="center"></div>
</div>
</div>
</rich:panel>
<br class="clear" />
<div class="floatleft">
<div class="row3">
<div class="row1">
<!-- January -->
<!-- Months Column -->
<div class="grid1">
<label>
<h:outputText readOnly="true" disabled="true" size="4" value="#{msg['calendar.month.0']}" />
</label>
</div>
<!-- Reduce check box -->
<rich:panel styleClass="ddo-panel" rendered="#{taxheadDirectDebit.isSeasonal == 1}">
<div class="grid2">
<div align="center">
<h:selectBooleanCheckbox
id="reduce12"
value="#{mandate.remittanceDetails.remittanceFrequencys[0].reduce}"
disabled="#{mandate.remittanceDetails.remittanceFrequencys[0].exclude}">
<a4j:ajax event="click" render="remittanceFrequency" />
</h:selectBooleanCheckbox>
</div>
</div>
</rich:panel>
<!-- Suspend check box -->
<rich:panel styleClass="ddo-panel" rendered="#{taxheadDirectDebit.isSeasonal != 1}">
<div class="grid2hidden">
<h:outputText value=" " />
</div>
</rich:panel>
<rich:panel styleClass="ddo-panel" rendered="#{taxheadDirectDebit.action == 'AMEND'}">
<div class="grid3">
<div align="center">
<h:selectBooleanCheckbox
id="suspend0"
value="#{mandate.remittanceDetails.remittanceFrequencys[0].suspend}">
<a4j:ajax event="change" />
</h:selectBooleanCheckbox>
</div>
</div>
</rich:panel>
<!-- Exclude check box -->
<rich:panel styleClass="ddo-panel" rendered="#{taxheadDirectDebit.isSeasonal == 1}">
<div class="grid2">
<div align="center">
<h:selectBooleanCheckbox
id="exclude0"
value="#{mandate.remittanceDetails.remittanceFrequencys[0].exclude}"
disabled="#{mandate.remittanceDetails.remittanceFrequencys[0].reduce}">
<a4j:ajax event="change" render="remittanceFrequency" />
</h:selectBooleanCheckbox>
</div>
</div>
</rich:panel>
<rich:panel styleClass="ddo-panel" rendered="#{taxheadDirectDebit.isSeasonal != 1}">
<div class="grid2hidden">
<h:outputText value=" " />
</div>
</rich:panel>
<div class="errorRemittance">
<rich:message styleClass="errorText" for="remittanceAmount0"/>
</div>
<!-- Monthly Amount field -->
<div class="grid5">
<h:inputText
id="remittanceAmount0" size="30" maxlength="8" readOnly="true"
value="#{mandate.remittanceDetails.remittanceFrequencys[0].amount}"
disabled="#{!mandate.remittanceDetails.remittanceFrequencys[0].reduce}"
label="#{msg['remittanceDetails.amountToBeDebited']}">
<a4j:ajax event="change" render="remittanceFrequency" />
</h:inputText>
</div>
</div>
</div>
<div class="errorText" font="bold">
<rich:message styleClass="errorTextNoPadding" for="continue"/>
</div>
</div>
</div>
</a4j:outputPanel>
</fieldset>
</a4j:outputPanel>
<rich:message>
<rich:message for="remittanceFrequency" ajaxRendered="true" />
</rich:message>
</ui:repeat>
I've taken out a lot of my code here so there may be un macthed divs etc but the idea is there.
I have two problems:
You can see that some components have change events that render other components based on id. These don't work inside the repeat
I'm using webflow and adding messages to the message context so that the message tags can display validation messages but these don't work in the iteration either.
I have tried tr:iterator, c:forEach, a4j:repeat, tr:forEach. I'm pretty sure what I'm trying to do isn't possible the way I'm trying to do it so if anyone has experience trying to achieve similar I'd appreciate some help. I can't change the MVC frameowork I'm using but could use perhaps jQuery.
I solved this by moving the ajax region outside the repeat and just calling render on the whole region. Not beautiful I know but the quickest solution I could find.
On the message front I simply add the index of the item in the list being iterated over into the message.
"remittanceDetails:mandates:"+taxhead.getMandates().indexOF(mandate)+":remittanceAmount" + frequency.getMonth().getCode()
JSF looks after the rest.

Resources