I am failing to render data which is surely in a database. All my DAO methods working and tested. Perhaps it is not important but anyway: I am using Primefaces, Java ee 6, glassfish 3.1.
Here is error: /edit.xhtml #59,45 value="#{b.orderNum}": The class 'com.boatmanagement.domain.BoatOrder' does not have the property 'orderNum'.
My domain class.
#Entity
#Table(name="BOAT_ORDR_TB")
public class BoatOrder implements Serializable
{
#Id
#GeneratedValue
#Column(name="ORDER_PK")
private int orderId;
#Column(name="ORDER_NUM")
private String orderNum;
#Temporal(TemporalType.DATE)
#Column(name="ORDER_DATE")
private Date orderDate;
public int getBoatOrderId() {
return orderId;
}
public void setBoatOrderId(int orderId) {
this.orderId = orderId;
}
public String getBoatOrderNum() {
return orderNum;
}
public void setBoatOrderNum(String orderNum) {
this.orderNum = orderNum;
}
public Date getBoatOrderDate() {
return orderDate;
}
public void setBoatOrderDate(Date orderDate) {
this.orderDate = orderDate;
}
}
Here is part of my JSF page.
<h:form class="displayTable">
<p:dataTable id="boatTable" autoUpdate="true"
var="b" value="#{filterbean.btOrderlist}">
<p:column headerText="res. num" width="50">
<h:outputText value="#{b.orderNum}" />
</p:column>
<p:column headerText="Date" width="50">
<h:outputText value="#{b.orderDate}" />
</p:column>
<p:column headerText="Yacht name" width="100">
<h:outputText value="" />
</p:column>
</p:dataTable>
</h:form>
</ui:define>
The presence of the property is basically determined by the presence of the public getter method which is named according the Javabeans specification. So the property of orderNum basically requires a public getter with the name getOrderNum() (and for input components also a public setter with the name of setOrderNum()).
You don't have them. You gave them different names. Fix the method names in the class, or the property name in EL.
As an aside, knowing this is 8 years old, I found an issue when dealing with Boolean/boolean values.
Assuming I have an object member "active", Eclipse creates a getter as isActive(), not getActive(). JBOSS/Tomcat seem to not recognize this getter. I have not tried this in Glassfish, but I'm posting it in case someone else finds this issue...
Related
I am getting the following error when I put the value attribute in the selectOneMenu value="#{customer.customerType}":
javax.el.PropertyNotFoundException: Target Unreachable, identifier 'customer' resolved to null
PickList:
<p:pickList id="customersPL" itemLabel="#{customer.id}"
itemValue="#{customer}" responsive="true"
value="#{bean.customersList}" var="customer">
<o:converter converterId="omnifaces.ListConverter"
list="#{bean.customersListSource}" />
<p:ajax event="transfer" listener="#{bean.onTransfer}" />
<p:column>
<h:outputText value="#{customer.name}" />
</p:column>
<p:column>
<p:selectOneMenu converter="omnifaces.SelectItemsConverter"
id="customerType" value="#{customer.customerType}">
<f:selectItems itemLabel="#{customerType.name}"
itemValue="#{customerType}"
value="#{bean.customerTypesList}"
var="customerType" />
</p:selectOneMenu>
</p:column>
</p:pickList>
Bean:
private CustomerType[] customerTypesList = CustomerType.values();
CustomerType Enum:
public static enum CustomerType {
WHOLESALE("W", "Wholesale"), RETAIL("R", "Retail");
private String id;
private String name;
TipoCliente(String id, String name) {
this.id = id;
this.name = name;
}
public String getId() {
return id;
}
public String getName() {
return name;
}
}
Picklists in general are not intended to contain input 'controls'. So the p:pickList was never designed to contain inputs like h\p:selectonemenu or even plain h\p:inputTexts. So it does not work like you expect it to and that is just unfortunate. Redesigning your ui is the only thing to do.
I had this exception in selecting a single row:
javax.faces.FacesException: DataModel must implement org.primefaces.model.SelectableDataModel when selection is enabled or you need to define rowKey attribute
Here is the table:
<h:form>
<p:dataTable id="books" value="#{myCardBean.booksList}" var="book" selectionMode="single"
selection="#{myCardBean.selectedBook}" rowKey="book.id">
<p:ajax event="rowSelect" listener="#{myCardBean.onRowSelect}"/>
<p:ajax event="rowUnselect" listener="#{myCardBean.onRowUnselect}"/>
<p:column>
<f:facet name="header">Book ID</f:facet>
<h:outputText value="#{book.id}"/>
</p:column>
<p:column>
<f:facet name="header">Title</f:facet>
<h:outputText value="#{book.title}"/>
</p:column>
</p:dataTable>
</h:form>
And this is myCardBean :
#ManagedBean
#ViewScoped
#Component
public class MyCardBean implements Serializable {
#Autowired
private BookDao bookDao;
private List<Book> booksList;
private Book selectedBook;
#PostConstruct
public void init() {
userCard();
}
#Transactional
public List<Book> userCard() {
booksList = bookDao.findAllBooks();
System.out.println("all Books size: " + booksList.size() + " books list type: " + booksList); // 3 , list of Object
return booksList;
}
public void onRowSelect(SelectEvent event) {
System.out.println("row selected, " + event.getObject());
}
public void onRowUnselect(UnselectEvent event) {
}
//getter/setter for selectedBook and bookList
And this is Book model class:
public class Book implements Serializable {
#Id
#GeneratedValue
private Integer id;
#Column(nullable = false)
private String title;
//...
I defined rowKey and Selection and selectionMode in datatable
I have no idea why should i got this error?!
should id be String instead of Integer?
Your rowkey is (again) defined wrong. It should be #{book.id} as can be seen in the PrimeFaces showcase. Not sure it is the only error, but I stopped reading further when I encountered this one.
Please investigate more yourself. StackOverflow is not a free training or consultancy site
I have a RoleStatus enum which is as being a property of Role entity mapped to an integer in the DB (but that part is irrelevant). I'd like to present a List<Role> in a <p:dataTable> in which one column should have a <h:selectOneMenu> for the RoleStatus property of the Role entity. How can I implement this with or without OmniFaces?
Here's the enum:
public enum RoleStatus {
ACTIVE(1, "Active"),
DISABLE(2, "Disable");
private final int intStatus;
private final String status;
private RoleStatus(int intStatus, String status) {
this.intStatus = intStatus;
this.status = status;
}
public int getIntStatus() {
return status;
}
public String getStatus() {
return status;
}
}
Here's the backing bean:
#ManagedBean
#ViewScoped
public class RoleController {
private List<Role> roles;
#ManagedProperty("#{roleService}")
private IRoleService roleService;
#PostConstruct
public void init() {
roles = roleService.getRoles();
}
public List<Role> getRoles() {
return roles;
}
}
Finally, the data table where I'd like to have a <h:selectOneMenu> for the RoleStatus property of Role entity, showing all available enum values as select item options.
<h:form id="roleForm">
<p:dataTable value="#{roleController.roles}" var="role">
<p:column>
<h:outputText value="#{role.roleid}" />
</p:column>
<p:column>
<h:inputText value="#{role.role}" />
</p:column>
<p:column>
<h:inputText value="#{role.description}" />
</p:column>
<p:column>
<h:selectOneMenu value="#{role.roleStatus}">
<!-- How??? -->
</h:selectOneMenu>
</p:column>
</p:dataTable>
</h:form>
How can I achieve this? Do I need the OmniFaces SelectItemsConverter?
You don't need a converter. JSF has already a builtin enum converter.
Without OmniFaces, here's how you could provide the enum values as available items of <h:selectOneMenu>:
Add this method to RoleController:
public RoleStatus[] getRoleStatuses() {
return RoleStatus.values();
}
This way, all enum values are available by #{roleController.roleStatuses}.
Then use this dropdown:
<h:selectOneMenu value="#{role.roleStatus}">
<f:selectItems value="#{roleController.roleStatuses}" var="roleStatus"
itemValue="#{roleStatus}" itemLabel="#{roleStatus.status}" />
</h:selectOneMenu>
Note: as those values are static/applicationwide, it doesn't hurt to move the method to a separate #ApplicationScoped bean.
With OmniFaces, you could remove the additional getter and just import the enum directly via <o:importConstants>:
Add this somewhere in top of your template (assuming that it's in com.example package):
<o:importConstants type="com.example.RoleStatus" />
This way, the enum class itself is available by #{RoleStatus} (note the capitalization!).
Then use this dropdown:
<h:selectOneMenu value="#{role.roleStatus}">
<f:selectItems value="#{RoleStatus.values()}" var="roleStatus"
itemValue="#{roleStatus}" itemLabel="#{roleStatus.status}" />
</h:selectOneMenu>
I have a <p:dataTable> as follows.
<p:dataTable var="row" value="#{testManagedBean.list}">
<p:column>
<h:outputText value="#{row.subCatId}"/>
</p:column>
<p:column>
<p:commandLink process="#this">
<h:outputText value="#{row.subCatName}"/>
<f:setPropertyActionListener target="#{testManagedBean.subCatName}" value="#{row.subCatName}"/>
</p:commandLink>
</p:column>
</p:dataTable>
The corresponding RequestScoped managed bean is as follows.
#ManagedBean
#RequestScoped
public final class TestManagedBean
{
#EJB
private final TestBeanLocal testService=null;
private List<SubCategory>list;
private String subCatName;
#PostConstruct
private void init()
{
list=testService.getSubCategoryList();
}
public List<SubCategory> getList() {
return list;
}
public String getSubCatName() {
return subCatName;
}
public void setSubCatName(String subCatName) {
System.out.println("setSubCatName() called : "+subCatName);
this.subCatName = subCatName;
}
}
When <p:commandLink> inside <p:dataTable> is clicked, the corresponding setter method associated with <f:setProperyActionListener> (setSubCatName()) is called and the value is correctly set to the target property which is subCatName in this managed bean.
I have avoided many things like paging to have a minimal example.
Now, I need to populate this <p:dataTable> lazily. I'm changing this <p:dataTable> and the corresponding managed bean as follows.
<p:dataTable var="row" value="#{testManagedBean}" lazy="true" rows="10" rowIndexVar="rowIndex">
<p:column>
<h:outputText value="#{row.subCatId}"/>
</p:column>
<p:column>
<p:commandLink process="#this">
<h:outputText value="#{row.subCatName}"/>
<f:setPropertyActionListener target="#{testManagedBean.subCatName}" value="#{row.subCatName}"/>
</p:commandLink>
</p:column>
</p:dataTable>
And the associated JSF managed is given below.
#ManagedBean
#RequestScoped
public final class TestManagedBean extends LazyDataModel<SubCategory> implements Serializable
{
#EJB
private final TestBeanLocal testService=null;
private String subCatName;
private static final long serialVersionUID = 1L;
public String getSubCatName() {
return subCatName;
}
public void setSubCatName(String subCatName) {
System.out.println("setSubCatName() called : "+subCatName);
this.subCatName = subCatName;
}
#Override
public List<SubCategory> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, String> filters)
{
setRowCount(4); //Just an example. Otherwise, fetch from the database.
return testService.getSubCategoryList(first, pageSize, sortField, sortOrder, filters);
}
}
Now, when <p:commandLink> inside <p:dataTable> is clicked, the corresponding setter method associated with <f:setProperyActionListener> (setSubCatName()) is not invoked.
The setSubCatName() is only invoked, when the managed bean is decorated with a broader scope like #ViewScoped (in case of lazy is set to true)
Why doesn't <f:setPropertyActionListener> work with a request scoped managed managed bean, when a <p:dataTable> (also true for <p:dataGrid>) is lazily loaded?
Is it mandatory to designate a managed bean with a broader than a request scope in such cases?
yes it is mandatory because the underlying model has to be the same instance. even if it has the same values it won't work.
like you, i've met this behavior: primefaces datatable lazy loading and commandbutton per row
This question already has answers here:
How to dynamically add JSF components
(3 answers)
Closed 7 years ago.
I want to add dynamically input fields. Like
Is there a good component in PF on how to add such a component?
Pls give me a hint on how you would develop it, cause I have no clue at the moment.
I really appreciate your answer.
My technology stack:
Hibernate: 4.0.1.Final
Spring: 3.1.1.RELEASE
Primefaces: 3.5
jsf-version: 2.2.0-m08
PrimefacesMobile-version: 0.9.3
Apache Tomcat/7.0.12
Maybe the following piece of code can help you out, I'm afraid there's not a component for this (at least to my knowledge):
HTML
<h:form>
<ui:repeat value=#{bean.values}
var="value">
<h:inputText value="#{value}" />
<br />
</ui:repeat>
<h:commandButton value="Extend">
<f:ajax listener="#{bean.extend}"
process="#form"
render="#form" />
</h:commandButton>
<h:commandButton action="#{bean.submit}"
value="Save" />
</h:form>
BEAN
#ManagedBean
#ViewScoped
public class Bean {
private List<String> values;
#PostConstruct
public void init() {
values = new ArrayList();
values.add("");
}
public void submit() {
// save values in database
}
public void extend() {
values.add("");
}
public void setValues(List<String> values) {
this.values = values;
}
public List<String> getValues() {
return values;
}
}