I have this code:
<div class="p-col-12">
<p:outputLabel for="tripType" value="Testing new title"/>
<p:selectCheckboxMenu id="tripType"
value="#{analyticsController.selectedNewTripType}"
label="Cities"
filter="true"
filterMatchMode="in"
panelStyle="width:250px">
<f:selectItems value="#{analyticsController.newTripType}" />
</p:selectCheckboxMenu> </div>
And the controller is:
private String[] selectedNewTripType;
private List<String> newTripType;
#PostConstruct
public void init() {
newTripType = new ArrayList<String>();
newTripType.add("Miami");
newTripType.add("London");
newTripType.add("Paris");
newTripType.add("Istanbul");
newTripType.add("Berlin");
newTripType.add("Barcelona");
newTripType.add("Rome");
newTripType.add("Brasilia");
newTripType.add("Amsterdam");
}
public String[] getSelectedNewTripType() {
return selectedNewTripType;
}
public void setSelectedNewTripType(String[] selectedNewTripType) {
this.selectedNewTripType = selectedNewTripType;
}
public List<String> getNewTripType() {
return newTripType;
}
I used like describe in the documentation https://www.primefaces.org/showcase-v8/ui/input/checkboxMenu.xhtml but this is the result:
This is the result
Now I need somithing like this:
This is I need
And I don't know what happened, why doesn't it show even an error?
Could you help me please?
I am using PrimeFaces v8
Related
I am trying to display below list of list of object in datatable. But nothing is showing up. Help is very much appreciated!
public class TimrsDisplayBean {
private static final long serialVersionUID = 1L;
private String teamName = "";
private String teamType = "";
private boolean reported;
private boolean noProd;
private boolean missing;
public String getTeamName() {
return teamName;
}
public void setTeamName(String teamName) {
this.teamName = teamName;
}
public String getTeamType() {
return teamType;
}
public void setTeamType(String teamType) {
this.teamType = teamType;
}
public boolean getReported() {
return reported;
}
public void setReported(boolean reported) {
this.reported = reported;
}
public boolean getNoProd() {
return noProd;
}
public void setNoProd(boolean noProd) {
this.noProd = noProd;
}
public boolean getMissing() {
return missing;
}
public void setMissing(boolean missing) {
this.missing = missing;
}
}
XHTML FILE
<p:dataTable value="#{dashboardMBean.timrsDisplayDataList}" var="var" rowIndexVar="row"
styleClass="large-card-datatable alternatingRowTable no-border nowrap">
<f:facet name="header">
<span class="updateDate"> </span>
</f:facet>
<p:column headerText="Type" value=" #{dashboardMBean.timrsDisplayDataList[0]}" columnIndexVar="i">
#{var[i].teamType}
</p:column>
<p:column headerText="Type" value=" #{dashboardMBean.timrsDisplayDataList[0]}" columnIndexVar="i">
#{var[i].teamName}
</p:column>
Please support full code parts if possible. Your datatable tag doesn't even finish.
Beside that, it seems like you've done too much work. Did you try to calculate the row indices by yourself? Not needed. The basic column definiton is more comfortable. Use your defined variable var to name each element/row as shown in the Primefaces showcase:
http://www.primefaces.org/showcase/ui/data/datatable/basic.xhtml
In your case, it will be something like
<p:column headerText="Type">
<h:outputText value="#{var.teamType}"/>
</p:column>
Plus, as Jasper De Vries said correctly, there is no attribute called columnIndexVar. Remove it to prevent strange behaviour.
If this is not enough, you need to share some more code of your ManagedBean. Not sure if your posted java class represent your Bean, but if so, you need to declare it as a ManagedBean like
#ManagedBean(name = "timrsDisplayBean)
#SessionScoped
public class TimrsDisplayBean {
I hope this helps!
i know that this is quetion is already answered here but i don't know why my code didn't work
i have two list and i want that when the first one changes that's the others update
here's my code
<h:selectOneMenu id="e4" styleClass="col-md-5" value="#{categoryModel.selectedMenu}">
<f:selectItem />
<f:selectItems value="#{categoryModel.catFinanceVect}" var="catFinance"itemLabel="#{catFinance.designation}" itemValue="#{catFinance.ligne}" />
<!-- <a4j:ajax event="valueChange" render="e3" execute="#this" />-->
<f:ajax event="valueChange" execute="#this" render="e3" listener="#{categoryModel.getCatItList}"/>
</h:selectOneMenu>
<div class="col-md-1"></div>
<h:selectOneMenu id="e3" styleClass="col-md-6">
<f:selectItem />
<f:selectItems value="#{categoryModel.catItVect}" var="catIt"itemLabel="#{catIt.designation}" itemValue="#{catIt.designation}" />
</h:selectOneMenu>
and here's my backing bean :
#ManagedBean
#SessionScoped
public class CategoryModel {
private CatFinance catFinance= new CatFinance();
private Vector<CatFinance> catFinanceVect = new Vector<CatFinance>();
private CatIt catIt= new CatIt();
private Vector<CatIt> catItVect = new Vector<CatIt>();
private Integer selectedMenu;
public CategoryModel() {
super();
// TODO Auto-generated constructor stub
}
public CatFinance getCatFinance() {
return catFinance;
}
public void setCatFinance(CatFinance catFinance) {
this.catFinance = catFinance;
}
public Vector<CatFinance> getCatFinanceVect() {
return catFinanceVect;
}
public void setCatFinanceVect(Vector<CatFinance> catFinanceVect) {
this.catFinanceVect = catFinanceVect;
}
public CatIt getCatIt() {
return catIt;
}
public void setCatIt(CatIt catIt) {
this.catIt = catIt;
}
public Vector<CatIt> getCatItVect() {
return catItVect;
}
public void setCatItVect(Vector<CatIt> catItVect) {
this.catItVect = catItVect;
}
public Integer getSelectedMenu() {
return selectedMenu;
}
public void setSelectedMenu(Integer selectedMenu) {
this.selectedMenu = selectedMenu;
}
public void getCatFinanceList(){
this.setCatFinance(new CatFinance());
CatFinanceService catFinanceService = (CatFinanceService) SpringDaoCtxFactory.getDaoContext().getBean("CatFinanceService");
this.getCatFinanceVect().clear();
try {
this.getCatFinanceVect().addAll(catFinanceService.getCatFinanceList());
} catch (Exception e) {
e.printStackTrace();
}
}
public void getCatItList(AjaxBehaviorEvent event){
this.setCatIt(new CatIt());
CatItService catItService = (CatItService) SpringDaoCtxFactory.getDaoContext().getBean("CatItService");
this.getCatItVect().clear();
System.out.println("aaaa");
try {
this.getCatItVect().addAll(catItService.getCatItList(2));
} catch (Exception e) {
e.printStackTrace();
}
}
#PostConstruct
public void init(){
getCatFinanceList();
}
}
if anyone can help in this or give me a good tutoriel of how to do it i will appreciate it so much
thanks in advance
The f:ajax event is invalid. It should be change (or empty as it defaults to change for h:selectOneMenu.)
<f:ajax execute="#this" render="e3" listener="#{categoryModel.getCatItList}"/>
I'm using selectOneMenu for displaying some pictures and Strings, the pictures is for displaying purposes only i have (i.e. i have nothing to do with them on submitting) i want only to set the string next to the image, i have a conflict in setting the itemValue of the f:selectItems to the String required, when i do that the images doesn't appear at all, in a word i want to only submit the value of the string in the chosen selectItem without using converter:
JSF Code:
<p:selectOneMenu id="SkinChooser" value="#{personBean.ObjectDTO.personDescription.skin}"
panelStyle="width:150px" effect="fade" var="s"
style="width:160px" converter="#{personBean.converter}">
<f:selectItem itemLabel="Select One" itemValue="" />
<f:selectItems value="#{missedPersonBean.selectedSkins}"
var="skin" itemLabel="#{skin.skinType}" itemValue="#{skin}" />
<p:column>
<p:graphicImage value="/resources/images/skin/#{s.skinPhoto}"
width="40" height="50" />
</p:column>
<p:column>
#{s.skinType}
</p:column>
</p:selectOneMenu>
Skin.Java
public class Skin {
String skinPhoto;
String skinType;
public Skin() {
}
public Skin(String photo, String type) {
this.skinPhoto = photo;
this.skinType = type;
}
public String getSkinPhoto() {
return skinPhoto;
}
public void setSkinPhoto(String skinPhoto) {
this.skinPhoto = skinPhoto;
}
public String getSkinType() {
return skinType;
}
public void setSkinType(String skinType) {
this.skinType = skinType;
}
}
personBean.Java
#ManagedBean(name = "personBean")
#SessionScoped
public class ReportPerson {
private Skin skin;
private static List<Skin> selectedSkins;
static {
System.err.println("Array is filled");
selectedSkins = new ArrayList<Skin>();
selectedSkins.add(new Skin("1", "Pale white"));
selectedSkins.add(new Skin("2", "Fair white"));
selectedSkins.add(new Skin("3", "Light brown"));
selectedSkins.add(new Skin("4", "Moderate brown"));
selectedSkins.add(new Skin("5", "Dark brown"));
selectedSkins.add(new Skin("6", "Deeply pigmented"));
System.err.println("Finished Filling");
}
public List<Skin> getSelectedSkins() {
return selectedSkins;
}
public void setSelectedSkins(List<Skin> selectedSkins) {
this.selectedSkins = selectedSkins;
}
public Skin getSkin() {
return skin;
}
public void setSkin(Skin skin) {this.skin = skin;}
}
I'm trying to create a DataTable with Multiple Row Selection but i'm getting an error here's the link of the tutorial http://www.primefaces.org/showcase/ui/datatableRowSelectionMultiple.jsf :
Here's my xhtml:
<p:dataTable border="1" value="#{projectAdminisrationMB.projectNoUsersList}"
var="userObj"
selection="#
{projectAdminisrationMB.selectedUsers}"
selectionMode="multiple" rowIndexVar="rowIndex"binding="#{table2}">
<p:column id="column3">
<f:facet name="header">
<h:outputText value=" user "></h:outputText>
</f:facet>
<h:outputText value="#{userObj.name}"/>
/
<h:outputText value="#{userObj.lastName}"></h:outputText>
<h:outputText value="#{userObj.firstName}"></h:outputText>
</p:column>
<f:facet name="footer">
<p:commandButton id="addProjectUser" value=" Add " onclick="dlg1.show()" />
<p:commandButton id="deleteProjectUser" value=" Delete " />
</f:facet>
</p:dataTable>
Managed Bean :
#ManagedBean
#SessionScoped
public class ProjectAdminisrationMB implements Serializable {
private static final long serialVersionUID = 1L;
private String projectName;
private List <User> projectUsersList;
private List<User> projectNoUsersList;
private List<User> selectedUsers;
private String projectAdmin;
public ProjectAdminisrationMB() {
super();
AdministrationProjectFinal administrationProjectFinal =new
AdministrationProjectFinal();
this.projectUsersList=administrationProjectFinal.getUserList();
this.projectNoUsersList=administrationProjectFinal.getNotUserList();
}
public String getProjectName() {
return projectName;
}
public void setProjectName(String projectName) {
this.projectName = projectName;
}
public List<User> getProjectUsersList() {
return projectUsersList;
}
public void setProjectUsersList(List<User> projectUsersList) {
this.projectUsersList = projectUsersList;
}
public String getProjectAdmin() {
return projectAdmin;
}
public void setProjectAdmin(String projectAdmin) {
this.projectAdmin = projectAdmin;
}
public List<User> getProjectNoUsersList() {
return projectNoUsersList;
}
public void setProjectNoUsersList(List<User> projectNoUsersList) {
this.projectNoUsersList = projectNoUsersList;
}
public List<User> getSelectedUsers() {
return selectedUsers;
}
public void setSelectedUsers(List<User> selectedUsers) {
this.selectedUsers = selectedUsers;
}
}
i'm getting this error:
javax.faces.FacesException: DataModel must implement
org.primefaces.model.SelectableDataModel when selection is enabled.....
just add this attribute rowKey to the datatable tag :
<p:dataTable border="1" value="#{projectAdminisrationMB.projectNoUsersList}"
var="userObj"
rowKey="#{userObj.name}"selection="#{projectAdminisrationMB.selectedUsers}"
selectionMode="multiple" rowIndexVar="rowIndex"
binding="#{table2}">
You can get this error if you try to add a new item to the underlying list and forget to assign a value to that new item's rowKey.
Alternatively to rowKey you can wrap your data in a custom model which really implements org.primefaces.model.SelectableDataModel. This is helpful if
all of your your classes have the same kind of #Id (e.g. a long) and can implement the same interface (e.g. EjbWithId)
you want to add additional functionalities to your data which are not domain specific and don't belong e.g. User.
The interface may be something like this:
public interface EjbWithId
{
public long getId();
public void setId(long id);
}
Then a generic implementation of SelectableDataModel for all your classes can be used:
public class PrimefacesEjbIdDataModel <T extends EjbWithId>
extends ListDataModel<T> implements SelectableDataModel<T>
{
public PrimefacesEjbIdDataModel(List<T> data)
{
super(data);
}
#Override public T getRowData(String rowKey)
{
List<T> list = (List<T>) getWrappedData();
for(T ejb : list)
{
if(ejb.getId()==(new Integer(rowKey))){return ejb;}
}
return null;
}
#Override public Object getRowKey(T item) {return item.getId();}
}
In your #ManagedBean:
private PrimefacesEjbIdDataModel<User> dmUser; //+getter
dmUser = new PrimefacesEjbIdDataModel<User>(administrationProjectFinal.getUserList());
first check whether you've added
rowKey="#{userObj.id}"
then you need to have the data table List set in filteredValue attribute of your data table in xhtml, instead of value.
I have a simple page where a I use <ui:repeat> and it gets the value from a backing bean.
The initial request will give it an empty list. The postback then will invoke an action that will change the model behind the <ui:repeat> but it is not rendered?!
I debugged through it and I saw that the <ui:repeat> evaluates the value at restore view phase but thats it. When it reaches render response it does not use the latest value from my bean. Is that the expected behavior?
How can I make that work? Do I have to write my own repeat tag?
I can't really tell what could be the problem without some of your code, but these are the basics:
Backing bean:
public class ObjectService{
private DataModel objectDataModel;
private List<Object> objectList;
private Pagination paginationHelper;
private ObjectDao objectDao = new ObjectDao();
private String queryOption;
public void setQueryOption(String queryOption){
this.queryOption = queryOption;
}
public String getQueryOption(){
return this.queryOption;
}
public <E> PaginationHelper getPagination(final List<E> list) {
pagination = new PaginationHelper(10) {
#Override
public int getItemsCount() {
return list.size();
}
#Override
public DataModel createPageDataModel() {
return new ListDataModel(list);
}
};
return pagination;
}
public void setPagination(PaginationHelper pagination) {
this.pagination = pagination;
}
public List<Object> getObjectList(){
this.objectList = objectDao.readObjectsWhere(queryOption);
return this.objectList;
}
public void setObjectList(List<Object> objectList){
this.objectList = objectList;
}
public DataModel getObjectDataModel(){
if (objectDataModel == null) {
objectDataModel = getPagination(getObjectList()).createPageDataModel();
}
return objectDataModel;
}
public void setObjectDataModel(DataModel objectDataModel){
this.objectDataModel = objectDataModel
}
public String changeModel(){
objectDataModel = null;
return null;
}
}
XHTML page:
...
<h:form>
<fieldset>
<label>
<span>Option:</span>
<h:inputText value="#{objectService.queryOption}" />
</label>
<h:commandButton action="#{objectService.changeModel}" value="request data" />
</fieldset>
<ui:repeat value="#{objectService.objectDataModel}" var="objectVar">
<h:outputLabel value="#{objectVar.property1}" />
<h:outputLabel value="#{objectVar.property2}" />
<h:outputLabel value="#{objectVar.property3}" />
</ui:repeat>
</h:form>
...