我正在尝试在 glassfish-3.1.2 下开发一个应用程序。我有以下组实体:
@Entity
@NamedQueries({
@NamedQuery(name = Groups.FIND_BY_ID, query="SELECT g FROM Groups g WHERE g.id = :id"),
@NamedQuery(name = Groups.FIND_BY_NAME, query="SELECT g FROM Groups g WHERE g.group_name = :name"),
@NamedQuery(name = Groups.FIND_ALL, query="SELECT g FROM Groups g ORDER BY g.group_name")})
public class Groups implements Serializable {
public static final String FIND_ALL = "Groups.findAll";
public static final String FIND_BY_ID = "Groups.findById";
public static final String FIND_BY_NAME = "Groups.findByName";
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String group_name;
private String group_desc;
@ManyToMany(mappedBy = "UsersGroups")
private List<Users> user;
/* Follow setters and getters
和固件实体:
@Entity
@NamedQueries({
@NamedQuery(name = "findById", query="SELECT f FROM Firmware f WHERE f.id = :id"),
@NamedQuery(name = "findByType", query="SELECT f FROM Firmware f WHERE f.type = "type"),
@NamedQuery(name = "findAll", query="SELECT f FROM Firmware f ORDER BY f.type")})
public class Firmware implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String type;
/* Follow getters and setters */
和以下 Bean
@Stateless
@LocalBean
public class GroupsEJB {
@PersistenceContext private EntityManager em;
public Groups persist(Groups group) {
em.persist(group);
return group;
}
public Groups getById(Long id) {
TypedQuery<Groups> query = em.createNamedQuery("findById", Groups.class).setParameter("id", id);
return query.getSingleResult();
}
public List<Groups> getAllGroups() {
TypedQuery<Groups> query = em.createNamedQuery("findAll", Groups.class);
return query.getResultList();
}
public List<Groups> getByName(String name) {
TypedQuery<Groups> query = em.createNamedQuery("findByName", Groups.class).setParameter("group_name", name);
return query.getResultList();
}
}
@Stateless
@LocalBean
public class FirmwareEJB {
@PersistenceContext private EntityManager em;
/**
* Creates a new instance of FirmwareEJB
*/
public FirmwareEJB() {
}
public Firmware persist(Firmware firmware) {
em.persist(firmware);
return firmware;
}
public List<Firmware> getAllFirmware() {
TypedQuery<Firmware> query = em.createNamedQuery("findAll", Firmware.class);
return query.getResultList();
}
public List<Firmware> getByType(String type) {
TypedQuery<Firmware> query = em.createNamedQuery("findByType", Firmware.class).setParameter("type", type);
return query.getResultList();
}
public Firmware getById(Long id) {
TypedQuery<Firmware> query = em.createNamedQuery("findById", Firmware.class).setParameter("id", id);
return query.getSingleResult();
//Firmware f = em.find(Firmware.class, id);
//return f;
}
}
和以下控制器
@ManagedBean
@RequestScoped
public class GroupsController {
@EJB
private GroupsEJB groupsEJB;
private Groups group = new Groups();
private List<Groups> groupsList = new ArrayList<Groups>();
/**
* Creates a new instance of GroupsController
*/
public GroupsController() {
}
public String createGroup() {
return "createGroup.xhtml";
}
public String saveGroup() {
group = groupsEJB.persist(group);
groupsList = groupsEJB.getAllGroups();
return "listGroups.xhtml";
}
public String listGroups() {
groupsList = groupsEJB.getAllGroups();
return "listGroups.xhtml";
}
public Groups getGroup() {
return group;
}
public void setGroup(Groups group) {
this.group = group;
}
public List<Groups> getGroupsList() {
return groupsList;
}
public void setGroupsList(List<Groups> groupsList) {
this.groupsList = groupsList;
}
@ManagedBean
@RequestScoped
public class FirmwareController {
@EJB
private FirmwareEJB firmwareEJB;
private Firmware firmware = new Firmware();
private List<Firmware> firmwareList = new ArrayList<Firmware>();
/**
* Creates a new instance of FirmwareController
*/
public FirmwareController() {
}
public String newFirmware() {
return "newFirmware.xhtml";
}
public String saveFirmware() {
List type = firmwareEJB.getByType(firmware.getType());
if (!type.isEmpty()) {
addMessage("Firmware already exist.");
return "newFirmware.xhtml";
}
firmware = firmwareEJB.persist(firmware);
firmwareList = firmwareEJB.getAllFirmware();
return "listFirmware.xhtml";
}
public String listFirmware() {
firmwareList = firmwareEJB.getAllFirmware();
return "listFirmware.xhtml";
}
public String searchFirmware() {
return "searchFirmware.xhtml";
}
public String searchFirmwareById() {
Long id = firmware.getId();
Firmware f = firmwareEJB.getById(id);
addMessage("Firmware: " + f.getType());
return "searchFirmware.xhtml";
}
public List<Firmware> getFirmwareList() {
return firmwareList;
}
public void setFirmwareList(List<Firmware> firmwareList) {
this.firmwareList = firmwareList;
}
public Firmware getFirmware() {
return firmware;
}
public void setFirmware(Firmware firmware) {
this.firmware = firmware;
}
因此,当我使用以下 jsf 时:
<ui:composition template="./base.xhtml">
<ui:define name="content">
<h:dataTable value="${groupsController.groupsList}" var="g" >
<h:column>
<f:facet name="header">
<h:outputText value="Group Name" />
</f:facet>
<h:outputText value="${g.group_name}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Group Description" />
</f:facet>
<h:outputText value="${g.group_desc}" />
</h:column>
</h:dataTable>
</ui:define>
</ui:composition>
为了显示组列表,我获得
javax.el.PropertyNotFoundException: /listGroups.xhtml @25,65 value="${g.group_name}": The class 'entities.Firmware' does not have the property 'group_name'.
我重建,重写,没有解决方案。我无法找到解决方案。谁能帮我?