我正在尝试在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 */
以及以下豆类
@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'.
我重建,重写,没有解决方案。我无法找到解决方案。任何人都可以帮助我吗?
答案 0 :(得分:0)
要看到吸气剂和制定者会很好。只是在黑暗中拍摄:在属性中使用下划线不符合Java Bean cnovention。我相信这也可能是你问题的根源。我相信如果你摆弄套管,你可以解决它。我强烈建议您将该属性重命名为groupName并具有setGroupName和getGroupName,并使用g.groupName作为表达式。