I m working on a project with jsf spring hibernate and primefaces. I have a form in which I add items. One field of that form is not a primitive type but an custom object. I know I have to use a converter and get the object I choose. I have tryied a custom converter with no luck since I cant inject the service and is always null. So I turned to omnifaces to make my life easier and move on. Unfortunately I have problems with that too. I look over and over my code but I cant see whats wrong. Below I add the code related to the problem:
First the page I use omnifaces:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:o="http://omnifaces.org/ui"
xmlns:of="http://omnifaces.org/functions">
<h:head><title>Welcome to OTV_JSF_Spring_Hibernate_Project</title></h:head>
<h:body>
<ui:include src="/pages/topMenu.xhtml"/>
<h:form>
<table>
<tr>
<td><h:outputLabel for="itemId" value="id: "/></td>
<td><h:inputText id="itemId" value="#{inventoryItemsMB.itemId}"></h:inputText></td>
</tr>
<tr>
<td><h:outputLabel for="RefItemCategories" value="Category Code"/></td>
<td>
<h:selectOneMenu value="#{inventoryItemsMB.refItemCategories}" id="refItemCategories" immediate="true" converter="omnifaces.SelectItemsConverter">
<f:selectItems value="#{refItemCategoriesMB.refItemCategoriesList}" var="ref" itemLabel="#{ref.itemCategoryDescription}" itemValue="#{ref}"/>
<!--<f:converter converterId="catConverter"/>-->
</h:selectOneMenu>
</td>
</tr>
<tr>
<td><h:outputLabel for="description" value="Description"/></td>
<td><h:inputText id="description" value="#{inventoryItemsMB.description}" immediate="false"></h:inputText></td>
</tr>
<tr>
<td><h:outputLabel for="AvgMonthlyUsage" value="Average Monthly Usage: "/></td>
<td><h:inputText id="AvgMonthlyUsage" value="#{inventoryItemsMB.avgMonthlyUsage}"></h:inputText></td>
</tr>
<tr>
<td><h:outputLabel for="reorderQuantity" value="Reorder Quantity: "/></td>
<td><h:inputText id="reorderQuantity" value="#{inventoryItemsMB.reorderQuantity}"></h:inputText></td>
</tr>
<tr>
<td><h:outputLabel for="Price" value="Price: "/></td>
<td><h:inputText id="Price" value="#{inventoryItemsMB.price}"></h:inputText></td>
</tr>
<tr>
<td><h:outputLabel for="ItemStockLevels" value="Item stock levels: "/></td>
<td><h:inputText id="ItemStockLevels" value="#{itemStockLevelsMB.quantityInStock}"></h:inputText></td>
</tr>
<tr>
<td><p:commandButton id="addInventoryItems" value="ADD" action="#{inventoryItemsMB.addInventoryItems}" ajax="false" immediate="false"/></td>
</tr>
</table>
</h:form>
</h:body>
Secondly my managedBeans:
#ManagedBean(name="inventoryItemsMB")
#RequestScoped
public class InventoryItemsManagedBean implements Serializable {
private static final long serialVersionUID = 1L;
private static final String SUCCESS = "successInventoryItems";
private static final String ERROR = "error";
#ManagedProperty(value="#{InventoryItemsService}")
IInventoryItemsService inventoryItemsService;
List<InventoryItems> inventoryItemsList;
private int id;
private String avgMonthlyUsage;
String description;
Set<ItemStockLevels> itemStockLevels;
float price;
String reorderQuantity;
RefItemCategories refItemCategories;
byte[] photo;
public String addInventoryItems(){
try{
InventoryItems inventoryItems = new InventoryItems();
//RefItemCategories refItemCategories = new RefItemCategories();
inventoryItems.setAvgMonthlyUsage(getAvgMonthlyUsage());//DONE is it a string?look at impl
inventoryItems.setDescription(getDescription());//DONE
inventoryItems.setItemId(getItemId());//DONE
inventoryItems.setItemStockLevels(getItemStockLevels());//DONE ----- why is it a set?
inventoryItems.setPhoto(getPhoto());
inventoryItems.setPrice(getPrice());//DONE
inventoryItems.setRefItemCategories(getRefItemCategories());//DONE---why refItemCategories
inventoryItems.setReorderQuantity(getReorderQuantity());//DONE-----why string?
//refItemCategories.getItemCategoryCode();
//refItemCategories.getItemCategoryDescription();
getInventoryItemsService().addInventoryItems(refItemCategories, inventoryItems);
return SUCCESS;
} catch (DataAccessException e) {
e.printStackTrace();
}
return ERROR;
}
public List<InventoryItems> getInventoryItemsList() {
inventoryItemsList = new ArrayList<InventoryItems>();
inventoryItemsList.addAll(getInventoryItemsService().getInventoryItems());
return inventoryItemsList;
}
public IInventoryItemsService getInventoryItemsService() {
return inventoryItemsService;
}
public void setInventoryItemsService(IInventoryItemsService inventoryItemsService) {
this.inventoryItemsService = inventoryItemsService;
}
public void setInventoryItemsList(List<InventoryItems> inventoryItemsList) {
this.inventoryItemsList = inventoryItemsList;
}
public int getItemId() {
return id;
}
public void setItemId(int id) {
this.id = id;
}
public void setAvgMonthlyUsage(String avgMonthlyUsage){
this.avgMonthlyUsage = avgMonthlyUsage;
}
public String getAvgMonthlyUsage(){
return avgMonthlyUsage;
}
public void setDescription(String description){
this.description = description;
}
public String getDescription(){
return description;
}
public void setItemStockLevelses(Set<ItemStockLevels> itemStockLevels){
this.itemStockLevels = itemStockLevels;
}
public Set<ItemStockLevels> getItemStockLevels(){
return itemStockLevels;
}
public void setPrice(float price){
this.price = price;
}
public float getPrice(){
return price;
}
public void setReorderQuantity(String reorderQuantity){
this.reorderQuantity = reorderQuantity;
}
public String getReorderQuantity(){
return reorderQuantity;
}
public void setRefItemCategories(RefItemCategories refItemCategories){
this.refItemCategories = refItemCategories;
}
public RefItemCategories getRefItemCategories(){
return refItemCategories;
}
public byte[] getPhoto(){
return photo;
}
public void setPhoto(byte[] photo){
this.photo = photo;
}
}
and the other managedbean
#ManagedBean(name="refItemCategoriesMB")
#RequestScoped
public class RefItemCategoriesManagedBean implements Serializable{
private static final long serialVersionUID = 1L;
private static final String SUCCESS = "addCategorySuccess";
private static final String ERROR = "error";
#ManagedProperty(value="#{RefItemCategoriesService}")
IRefItemCategoriesService refItemCategoriesService;
List<RefItemCategories> refItemCategoriesList;
private int id;
private String description;
public String addRefItemCategories(){
try{
RefItemCategories refItemCategories = new RefItemCategories();
refItemCategories.setItemCategoryCode(getItemCategoryCode());
refItemCategories.setItemCategoryDescription(getItemCategoryDescription());
getRefItemCategoriesService().addRefItemCategories(refItemCategories);
return SUCCESS;
} catch (DataAccessException e){
e.printStackTrace();
}
return ERROR;
}
public List<RefItemCategories> getRefItemCategoriesList() {
refItemCategoriesList = new ArrayList<RefItemCategories>();
refItemCategoriesList.addAll(getRefItemCategoriesService().getRefItemCategories());
return refItemCategoriesList;
}
public IRefItemCategoriesService getRefItemCategoriesService() {
return refItemCategoriesService;
}
public void setRefItemCategoriesService(IRefItemCategoriesService refItemCategoriesService) {
this.refItemCategoriesService = refItemCategoriesService;
}
public void setRefItemCategoriesList(List<RefItemCategories> refItemCategoriesList) {
this.refItemCategoriesList = refItemCategoriesList;
}
public String DeleteCategory(RefItemCategories refItemCategoriesList){
getRefItemCategoriesService().deleteRefItemCategories(refItemCategoriesList);
return SUCCESS;
}
public void setItemCategoryCode(int id){
this.id = id;
}
public int getItemCategoryCode(){
return id;
}
public void setItemCategoryDescription(String description){
this.description = description;
}
public String getItemCategoryDescription(){
return description;
}
#Override
public boolean equals(Object object){
if(this.id == ((RefItemCategories) object).getItemCategoryCode()) {
return true;
}else {
return false;
}
}
}
the service Im not able to inject:
#Transactional(readOnly = true)
#Service("RefItemCategoriesService")
public class RefItemCategoriesService implements IRefItemCategoriesService{
#Autowired
RefItemCategoriesDAOImpl refItemCategoriesDAO;
#Transactional(readOnly = false)
#Override
public void addRefItemCategories(RefItemCategories refItemCategories) {
getRefItemCategoriesDAO().addRefItemCategories(refItemCategories);
}
#Transactional(readOnly = false)
#Override
public void updateRefItemCategories(RefItemCategories refItemCategories) {
getRefItemCategoriesDAO().updateRefItemCategoriesUser(refItemCategories);
}
#Transactional(readOnly = false)
#Override
public void deleteRefItemCategories(RefItemCategories refItemCategories) {
getRefItemCategoriesDAO().deleteRefItemCategories(refItemCategories);
}
#Override
public RefItemCategories getRefItemCategoriesByID(int id) {
return getRefItemCategoriesDAO().getRefItemCategoriesById(id);
}
#Override
public List<RefItemCategories> getRefItemCategories() {
return getRefItemCategoriesDAO().getRefItemCategories();
}
public RefItemCategoriesDAO getRefItemCategoriesDAO(){
return refItemCategoriesDAO;
}
}
this way I get a transactional error where item_cat_code (the db table) cannot be null.
Thank you for your time.
As per the documentation, the omnifaces.SelectItemsConverter relies on the Object#toString() representation of the to-be-converted object to properly match the selected item. You didn't show the code of your RefItemCategories entity, so it's just guessing, but the symptoms indicate that you indeed didn't #Override the toString() on your entity, and it is thus relying on the default FQN#hashcode representation. This all would then only work if the available items (the value of <f:selectItems>) is exactly the same across postbacks on the same view.
However, the RefItemCategoriesManagedBean backing bean which provides the available items is request scoped and loads them in a getter. Everytime the getter is hit, a brand new list with brand new instances is returned. Those don't have the same hashcode as those which are already loaded in the list of available items and the submitted selected item thus never matches any of the newly loaded items.
That are thus at least 2 design problems.
You should choose the right bean scope for the data it holds. Make it at least #ViewScoped.
You should never interact with the DB in a getter method. Do it in #PostConstruct.
If you fix both, then the problem should disappear.
Or, just implement the toString() for your entity. E.g.
public class RefItemCategories {
#Override
public String toString() {
return "RefItemCategories[" + id + "]";
}
}
By the way, it's strange to see an equals() method on the RefItemCategoriesManagedBean backing bean class. Didn't you mean to put it on the RefItemCategories entity instead? In any way, carefully read the documentation of SelectItemsConverter how to properly use it and how to properly design your entities.
Related
I m having trouble to set value for entity bean. the problem is that when i populate form file will be upload but i need file path to store in data base. In my bean i have used setter of employee entity to set file url but And I think the code is enough to set file path for database but data is storing on database leaving employeePicture as null..
#Named
#RequestScoped
public class EmployeeAddController {
private Employees employees;
private String fileNameForDataBase;
private Part file;
#Inject
private EmployeeUpdateService updateService;
#PostConstruct
public void init() {
employees = new Employees();
}
public Employees getEmployees() {
return employees;
}
public void setEmployees(Employees employees) {
this.employees = employees;
}
public String getFileNameForDataBase() {
return fileNameForDataBase;
}
public void setFileNameForDataBase(String fileNameForDataBase) {
this.fileNameForDataBase = fileNameForDataBase;
}
public Part getFile() {
return file;
}
public void setFile(Part file) {
this.file = file;
}
public void upload() throws IOException {
ServletContext ctx = (ServletContext) FacesContext.getCurrentInstance()
.getExternalContext().getContext();
String realPath = ctx.getRealPath("/");
int random =(int) (Math.random() * 10000 + 1);
String fileString= realPath + File.separator + "resources/image/employee"+random+".jpg";
employees.setEmployeePicture(fileString);
try (InputStream input = file.getInputStream()) {
Files.copy(input, new File(fileString).toPath());
}
}
public String addEmployee() {
try {
this.updateService.add(employees);
return "index?faces-redirect=true";
} catch (Exception e) {
return null;
}
}
}
in My jsf page
"<div class="form-group">
<h:outputText value=" Employee Picture" class="col-sm-3 control-label"/>
<div class="col-sm-9">
<h:inputFile value="#{employeeAddController.file}">
<f:ajax listener="#{employeeAddController.upload()}"/>
</h:inputFile>
<h:outputText value="#{employeeAddController.fileNameForDataBase}"/>
</div>
<div>
<h:message for="fileUpload" class="text-primary"/>
</div>
</div>"***strong text***
I tried to make same list as in the below link:
http://www.primefaces.org/showcase/ui/input/listbox.xhtml
Unfortunately I get validation error:
Select Box: Validation Error: Value is not valid
I don't know where I've made mistake. I read a lot about this issue (in most cases it was solved by BalusC) however still can't find the issue.
If you can help I really appreciate.
StoreHouse.java
#Entity
public class StoreHouse implements Serializable {
#Id
#GeneratedValue
private Integer id;
#OneToOne
private Supply supply;
#Column(nullable = false)
private Integer amount;
//geters setters namedqueryies
Supply.java
#Entity
public class Supply implements Serializable {
#Id
#GeneratedValue
private Integer id;
#Column(unique = true, nullable = false, length = 32)
private String name;
#Column(length = 1024)
private String description;
#Column
private Double price;
#Enumerated(EnumType.STRING)
#NotNull
private SupplyType supplyType;
//geters setters namedqueryies
StoreHouseController.java
#ManagedBean
public class StoreHouseController implements Serializable {
#Inject
private StoreHouseBean storeHouseBean; // DAO for storeHouse
#ManagedProperty("#{supplyController}")
private SupplyController supplyController; //Manged bean for Supply
private StoreHouse storeHouse = new StoreHouse();
private List<Supply> allSupplies;
#PostConstruct
public void init() {
allSupplies = supplyController.findAll();
}
public void check() {
System.out.println("storeHousetheme" + storeHouse.toString()); // Function just to check if the supply was set
}
SupplyConverter.java
#FacesConverter("supplyConverter")
public class SupplyConverter implements Converter {
#Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
if (value != null && value.trim().length() > 0) {
try {
SupplyController supplyController = (SupplyController) context.getExternalContext().getApplicationMap().get("supplyController");
Supply supply = supplyController.findById(Integer.parseInt(value));
System.out.println("CONVERTER:" + supply.toString());
return supply;
} catch (NumberFormatException e) {
throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Conversion error", "ERROR."));
}
} else {
return null;
}
}
#Override
public String getAsString(FacesContext context, UIComponent component, Object object) {
if (object != null) {
return String.valueOf(((Supply) object).getId());
} else {
return null;
}
}
}
view.xhtml
<h:form>
<p:messages autoUpdate="true" />
<h:panelGrid columns="2">
<h:outputLabel value="Nazwa" />
<p:selectOneListbox id="supplies" value="#{storeHouseController.storeHouse.supply}" converter="supplyConverter" var="s" filter="true" label="Select Box">
<f:selectItems value="#{storeHouseController.allSupplies}" var="supply" itemLabel="#{supply.name}" itemValue="#{supply}"/>
<p:column>
<h:outputText value="#{s.name}" />
</p:column>
</p:selectOneListbox>
<p:commandButton action="#{storeHouseController.check}" type="submit" value="submit" />
</h:panelGrid>
If you need any other file/class please just add comment.
Your SelectItem-value is your object, so the toString()-method is called and you get something like "Supply#44de6bae".
Then, your controller tries to parse it to int and fails. Try...
<f:selectItems value="#{...}" var="..." itemLabel="..." itemValue="#{supply.id}"/>
If the error occures while loading the page, this might help as well as at least some components don't like "none-basic-type-or-enum" values. I hope this helped, Greez.
After few more days of searching and googling I've found the solution. I'm a bit angry that this is not posted anywhere on primefaces because I've lost many hours to fix the issue.
It came out that I did not overwrite equals method of Supply class which is required.
#Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Supply other = (Supply) obj;
if (!Objects.equals(this.id, other.id)) {
return false;
}
if (!Objects.equals(this.name, other.name)) {
return false;
}
if (this.supplyType != other.supplyType) {
return false;
}
return true;
}
I believe that this topic will help someone in the future...
I am currently implementing a orderable list using PrimeFaces' component, embedded inside a . I was able to get the list to appear properly with my items. However, when I saved the list and submitted it back to the server, the rearranged items did not get reflected in the backing bean for some reason. Since the Primefaces showcase was able to see the changes, what am I doing wrong?
XHTML Snippet:
<h:form id="confirmDialogForm">
<p:confirmDialog id="arrangeProjDialog" widgetVar="arrangeDlg" width="600"
header="Meeting Order"
appendToBody="true" message="Drag and drop to rearrange meeting order">
<p:orderList id="arrangeProjDialogList"
value="#{adminMeetingListBean.orderProjList}"
converter="#{adminMeetingListBean.rowConverter}"
var="po"
controlsLocation="left"
styleClass="wideList"
itemLabel="#{po.projectTitle}"
itemValue="#{po}"
>
<f:facet name="caption">Proposals</f:facet>
</p:orderList>
<p:commandButton value="Save" ajax="true" process="arrangeProjDialogList #this"
actionListener="#{adminMeetingListBean.updateProposalMeetingOrder}" onclick="arrangeDlg.hide();">
</p:commandButton>
<p:button value="Cancel" onclick="arrangeDlg.hide(); return false;" />
</p:confirmDialog>
</h:form>
Backing Bean:
public void updateProposalMeetingOrder() {
if (selectedMeeting != null) {
orderProjTitles.get(0);
meetingService.updateMeetingProjSequence(orderProjList, selectedMeeting.getMeetingId());
}
}
The List is a list of POJO "ProposalOrderRow" objects. This has the definition:
public class ProposalOrderRow implements Serializable {
private static final long serialVersionUID = -5012155654584965160L;
private int dispSeq;
private int appId;
private int assignmentId;
private String refNo;
private String projectTitle;
public int getDispSeq() {
return dispSeq;
}
public void setDispSeq(int dispSeq) {
this.dispSeq = dispSeq;
}
public int getAppId() {
return appId;
}
public void setAppId(int appId) {
this.appId = appId;
}
public String getRefNo() {
return refNo;
}
public void setRefNo(String refNo) {
this.refNo = refNo;
}
public String getProjectTitle() {
return projectTitle;
}
public void setProjectTitle(String projectTitle) {
this.projectTitle = projectTitle;
}
public int getAssignmentId() {
return assignmentId;
}
public void setAssignmentId(int assignmentId) {
this.assignmentId = assignmentId;
}
}
Converter:
#FacesConverter("proposalOrderRowConverter")
public class ProposalOrderRowConverter implements Converter {
private List<ProposalOrderRow> orderRows;
#Override
public Object getAsObject(FacesContext context, UIComponent component, String newValue) {
if (newValue.isEmpty()) {
return null;
}
for (ProposalOrderRow item : orderRows) {
String refNo = item.getRefNo();
if (refNo.equals(newValue)) {
return item;
}
}
return null;
}
#Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
if (value == null) {
return "";
}
ProposalOrderRow row = (ProposalOrderRow) value;
String output = row.getRefNo();
return output;
}
public List<ProposalOrderRow> getOrderRows() {
return orderRows;
}
public void setOrderRows(List<ProposalOrderRow> orderRows) {
this.orderRows = orderRows;
}
}
This problem is caused by appendToBody="true" in the confirm dialog. Setting it to false solved the problem.
See link here: link
I am working in seam with jsf1.2.
Everything working fine for me, except the search operation. Can anyone please suggest me to go in a right way?
Here, how I am having my form:
<h:form class="input-list" id="searchUser" style="width:100%;"
name="searchUser">
<div class="edit-label">FIRST NAME :</div>
<h:inputText tabindex="1" id="firstName" type="text" class="miniusername clp"
value="#{userListAction.firstName}" required="true">
<f:validateLength minimum="3" maximum="20" />
</h:inputText>
<h:commandButton value="Search" tabindex="2" style="margin-left: 5px"
action="#{userListAction.retrieveName}" class="usersearch">
</h:commandButton>
</h:form>
My interface:
#Local
public interface UserListAction extends Serializable {
public List<User> retrieveCustomers();
public List<User> retrieveEmployees();
public List<User> getUsersList();
public CLRPUser getLoginUser();
public List<User> retrieveName();
#WebRemote
public String deleteById(Integer userId);
#WebRemote
public CLRPUser getUserById(Integer userId);
public UserTypeEnum getUserType();
public void setUserType(UserTypeEnum userType);
public void setFirstName(String firstName);
public String getFirstName();
public CLRPUser getCurrentUser();
public void setCurrentUser(CLRPUser currentUser);
}
Action class which implements the interface:
#Name("userListAction")
#Stateless
#AutoCreate
public class UserListActionImpl implements UserListAction {
#In
protected UserService userService;
#Out(value = "userType", scope = ScopeType.CONVERSATION, required = false)
private UserTypeEnum userType;
#In
private LoggedInUser loggedInUser;
#Out(value = "currentUser", scope = ScopeType.CONVERSATION, required = false)
#In(value = "currentUser", scope = ScopeType.CONVERSATION, required = false)
private CLRPUser currentUser;
#In(value = "firstName", scope = ScopeType.CONVERSATION, required = false)
private String firstName;
/**
*
*/
private static final long serialVersionUID = 8649412602585430272L;
/*
* (non-Javadoc)
*
* #see com.ermms.clrp.user.UserAction#getUsersList()
*/
public List<User> retrieveName() {
System.out.print("FirstName is :" + firstName);
return userService.getAllUsers(firstName);
}
public UserTypeEnum getUserType() {
return this.userType;
}
public void setUserType(UserTypeEnum userType) {
this.userType = userType;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getFirstName() {
return firstName;
}
#Override
public CLRPUser getCurrentUser() {
// TODO Auto-generated method stub
return null;
}
#Override
public void setCurrentUser(CLRPUser currentUser) {
// TODO Auto-generated method stub
}
}
Console says the First name is : null.
I tried more times, but lost my mind in this. Please suggest me.
Why do you inject the firstName in the userListAction-component? Where should this come from?
If there is nothing more, I guess it works as follows:
user enters first name and clicks the command button
the form gets submitted and the entered first name is set into the model using the setter-method
when executing the command button-action Seam-bijection takes place and injects the value for the firstName stored in "some" context. Since it is not defined anywhere, null is injected.
So if you need the injection (for any case), you should put the correct value in the contest at any place. If not, just remove the #In annotation.
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>
...