Is there any way to change the used language in the above mentioned component dropdown?
adding lang="DE" for german language did not work:
<div class="p-field p-col-12 p-md-6">
<h7>Festnetz</h7>
<pe:inputPhone id="festnetz" label="Hallo" lang="DE"
initialCountry="#{kontakt.countryIsoFestnetz}"
value="#{kontakt.festnetz}" formatOnDisplay="true">
<p:ajax event="countrySelect"
listener="#{kontakt.onCountrySelectFestnetz}" />
</pe:inputPhone>
</div>
PrimeFaces Extensions 12.0.2 and up
Since PrimeFaces Extensions 12.0.2 you can use the localizedCountries to do so. You can either supply a Map<String, String> containing the ISO 2 abbreviation (lower case) (key), and the name (value):
private Map<String, String> localizedCountries;
#PostConstruct
protected void init() {
localizedCountries = new HashMap<>();
localizedCountries.put("nl", "Nederland");
localizedCountries.put("be", "België");
localizedCountries.put("de", "Duitsland");
}
// Add getter
<pe:inputPhone onlyCountries="nl,be,de"
localizedCountries="#{bean.localizedCountries}"/>
or a JSON string:
<pe:inputPhone onlyCountries="nl,be,de"
localizedCountries="{'nl':'Nederland','be':'België','de':'Duitsland'}"/>
See also:
https://github.com/primefaces-extensions/primefaces-extensions/issues/983
Related
I am working on Managedbeans and JSF. As shown below that my ManagedBean contains all the requirements that are required for the JSF to get the value. I have initialised my dropdown list as below. In selectOneMenu, I have chosen the country as a string where it will store the value selected by the dropdown list and the dropdown list will bring up the list that I declared in the Beans.
Unfortunately, it is not happening like that. Every time dropdown renders it gives me an empty value. I have spent days on it but cannot figure out the exact solution to it. I have cleaned my server, build workspace and also change servers but nothing is working.
** ManagedBean_list **
private List<String> listCountry;
private String country;
public void tada(){
listCountry=Arrays.asList("India", "pakisatan","America");
}
public List<String> getListCountry() {
return listCountry;
}
public void setListCountry(List<String> listCountry) {
this.listCountry = listCountry;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
JSF
<p:selectOneMenu id="country" value="#{loginBeans.country}">
<f:selectItems value="#{loginBeans.listCountry}" />
</p:selectOneMenu>
Your help is appreciated. Empty dropdown list image
enter image description here
Which bean annotation are you using? You say "Managedbeans", but the source you posted does not show the entire bean, or does it? Check to make sure you are not mixing old style JSF managed bean annotations with CDI annotations.
The issue is that on initialization, the list is not being called up. I resolved it by including the list function inside the constructor of managed beans class. so that when the constructor fired up. It also generates the dropdown list.
Either convert your listCountry to a
private Map<String, String> listCountry = new HashMap<>();
listCountry.put("India", "India");
listCountry.put("Pakistan", "Pakistan");
listCountry.put("America", "America");
or
private List<SelectItem> listCountry = new ArrayList<>();
listCountry.add(new SelectItem("India", "India"));
listCountry.add(new SelectItem("Pakistan", "Pakistan"));
listCountry.add(new SelectItem("America","America"));
Hi i have an "fieldset" tag in my jsf page
now i need to conditional add an "disabled" attribute
i have a solution, but it is very ugly:
<h:outputText escape="false" value="<fieldset disabled='disabled'>" rendered="#{surveysHandler.surveyRunning}" />
<h:outputText escape="false" value="</fieldset>" rendered="#{surveysHandler.surveyRunning}" />
is there a cool jsf 2.2 method?
Yes, there is a cool new JSF 2.2 way to achieve this!
You can make the fieldset a JSF 2.2 passthrough element and pass it a map of attributes like this:
<fieldset jsf:id="fieldset">
<f:passThroughAttributes value="#{customerBean.params}"/>
</fieldset>
The prefix jsf is for the new JSF 2.2 namespace http://xmlns.jcp.org/jsf. If an HTML tag has any attribute in this namespace, JSF will convert it to a real JSF component in the component tree. Therefore it is possible to use f:passThroughAttributesto add attributes coming from a map in a managed bean.
The getter for the params property could look like this (you can add attributes based on any condition in the bean):
public Map<String, String> getParams() {
HashMap<String, String> params = new HashMap<String, String>();
if (disabled) {
params.put("disabled", "disabled");
}
return params;
}
For further information about passthrough attributes and elements, have a look at my blogpost about HTML5 friendly markup with JSF 2.2.
I'm trying to use SelectItemsConverter with PrimeFaces Picklist.
XHTML:
<p:pickList id="plUpdateFirma" value="#{bsvttController.dlmFirma}" var="plFirma"
itemLabel="#{plFirma.schluesselFirma}" itemValue="#{plFirma}"
converter="FirmaConverter">
<f:facet name="sourceCaption">
Vorjahr
</f:facet>
<f:facet name="targetCaption">
#{bsvttController.selSaison}
</f:facet>
<p:column>
#{plFirma.schluesselFirma}
</p:column>
</p:pickList>
Converter:
#FacesConverter(value = "FirmaConverter")
public class FirmaConverter extends SelectItemsConverter
{
#Override
public String getAsString(final FacesContext facesContext, final UIComponent component, final Object object)
{
return ((Firma) object).getSchluesselFirma();
}
}
Bean:
#ManagedBean
#ViewScoped
public class BsvttController implements Serializable
{
private DualListModel<Firma> dlmFirma;
private List<Firma> dlmFirmaSource;
private List<Firma> dlmFirmaTarget;
private Firma firma;
#PostConstruct
public void init()
{
dlmFirmaSource = FirmaPersistenz.leseFirmaAlle();
dlmFirmaTarget = new ArrayList<Firma>();
dlmFirma = new DualListModel<>(dlmFirmaSource, dlmFirmaTarget);
}
public DualListModel<Firma> getDlmFirma()
{
return dlmFirma;
}
public List<Firma> getDlmFirmaSource()
{
return dlmFirmaSource;
}
public List<Firma> getDlmFirmaTarget()
{
return dlmFirmaTarget;
}
public void setDlmFirma(DualListModel<Firma> dlmFirma)
{
this.dlmFirma = dlmFirma;
}
public void setDlmFirmaSource(List<Firma> dlmFirmaSource)
{
this.dlmFirmaSource = dlmFirmaSource;
}
public void setDlmFirmaTarget(List<Firma> dlmFirmaTarget)
{
this.dlmFirmaTarget = dlmFirmaTarget;
}
}
While debugging converter I could see that getAsString method is working fine. But after submitting the form both arraylists (dlmFirmaSource and dlmFirmaTarget) are empty.
OmniFaces showcase says that
"The omnifaces.SelectItemsConverter allows you to populate e.g. a drop-down with complex Java model objects as value of f:selectItems and have JSF convert those automatically back without the need to provide a custom converter which may need to do the job based on possibly expensive service/DAO operations."
But in case of PickList component there doesn't exist any f:selectItems tag.
Does SelectItemsConverter even support PickList component?
Does SelectItemsConverter even support PickList component?
No, it doesn't.
Since OmniFaces 1.5, you can use omnifaces.ListConverter or omnifaces.ListIndexConverter for the desired purpose. See also the ListConverter showcase example which also demonstrates the usage on <p:pickList>.
No, the SelectItemsConverter handles conversion of core JSF SelectItem objects for use with various JSF components.
The class DualListModel is a PrimeFaces specific class meant for use with advanced PrimeFaces data components. The workaround of course is to possible use a #PostConstruct method to initialize your DualListModel in the managed bean so that it does not require a converter, or you can simply implement the converter in the traditional way. From the PrimeFaces guide on the converter attribute of Pick List:
An el expression or a literal text that defines a
converter for the component. When it’s an EL
expression, it’s resolved to a converter instance.
In case it’s a static text, it must refer to a
converter id
I want to create selectOneRadio list and selectCheckboxMenu which items get from related bean objects.
For non selected list it is working well.But how can i provide these lists with some item(s) selected by default.
My current selectCheckboxMenu code is like this.
<p:selectCheckboxMenu id="trdays"
value="#{mybean.selectedDay}"
label="Select Days">
<f:selectItems value="#{mybean.dayList}" var="day"
itemValue="#{day.value}" itemLabel="#{day.name}"/>
</p:selectCheckboxMenu>
it should look like this when page loaded and user haven't done anything yet.
EDIT
Day Class :-
public class Day{
private String name;
private String value;
//getters and setters
}
Value attribute of selectCheckboxMenu component should get the your default values.
On bean side you should write a getter for selectedDayList and all daylist.
Example:
#PostConstruct
public void init() {
dayList= new ArrayList<String>();
dayList.add("Mon");
dayList.add("Tue");
dayList.add("Wed");
dayList.add("Thu");
dayList.add("Fri");
dayList.add("Sat");
dayList.add("Sun");
selectedDayList= new ArrayList<String>();
selectedDayList.add("Tue");
selectedDayList.add("Wed");
}
public List<String> getDayList()
{
return dayList;
}
public List<String> getSelectedDaylist()
{
return selectedDayList;
}
.xhtml page should be like this.
<p:selectCheckboxMenu id="trdays"
value="#{mybean.selectedDaylist}"
label="Select Days">
<f:selectItems value="#{mybean.dayList}" var="day"
itemValue="#{day.value}" itemLabel="#{day.name}"/>
</p:selectCheckboxMenu>
Good Luck!
Just add default values in the selectedDay list (or array) in init method (with #PostConstruct annotation). These values should have same value as corresponding itemValue attribute (in your case this is day.value).
JSF 1.2 DataTable
I know how to remove the row from datatable writing following code.
jsp
<h:graphicImage id="deleteRowBtn_img" url="../../images/table_icon_delete.gif" style="cursor:pointer" alt="Delete Row">
<a4j:support id="deleteRowBtn" event="onclick" actionListener="#{mnpAction.deleteMultiNoPortRow}" reRender="multiNoPortTable" oncomplete="resetViewConfigs();"/>
</h:graphicImage>
action bean
public void deleteMultiNoPortRow(ActionEvent ae) {
{
int index = abcBean.getDataTable().getRowIndex();
mnpBean.getMultiNoPortingList().remove(index);
}
}
But i want to know is there any other way to remove row from datatable in JSF1.2.
Any help regarding this appreciate!!!!!!
You can get the same appearance and functionality by using an a4j:commandButton and its image attribute instead of <h:graphicImage> as below.
<a4j:commandButton image="../../images/table_icon_delete.gif" actionListener="#{mnpAction.deleteMultiNoPortRow}"/>
If your <h:graphicImage> is in a column of the table, you can pass the var of the table to a method in your baking bean and remove that element from the list without having to use the row index. Here use action instead of actionListener.
<a4j:support id="deleteRowBtn" event="onclick" action="#{mnpAction.remove(myVar)}".../>
In mnpAction bean (Assuming the type of your list is T)
public void remove(T s) {
mnpBean.getMultiNoPortingList().remove(s);
}
Edit:
Since you are using JSF1.2 you may not use #{mnpAction.remove(myVar)}" to pass parameters to the bean if you don't like to upgrade your EL library.