我在尝试显示位于MySql DB中的名为“Element”的类的字段位置时遇到问题。我必须使用SelectionOneMenu来显示字段Element.Location中包含的所有值。当我在我的服务器上运行xhtml页面时,选择菜单中的Glassfish会显示一个字符串:“elementmanagementDTO.elementDTO@3231313”。我不知道这意味着什么。我会把所涉及的课程放在这里。
我有xhtml
页面:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Add a Default Package</title>
</h:head>
<h:body>
<h:form>
<p:panel header="DefaultPackage Form">
<h:panelGrid columns="3" id="regGrid">
<h:outputLabel for="Name">Name:</h:outputLabel>
<p:inputText id="Name" value="#{addDefaultPackageBean.defpackDTO.Name}" />
<p:message for="Name" />
<h:outputLabel for="location">Location:</h:outputLabel>
<p:inputText id="location" value="#{addDefaultPackageBean.defpackDTO.location}" />
<p:message for="location" />
<h:selectOneMenu value="#{addDefaultPackageBean.name}">
<f:selectItems value="#{addDefaultPackageBean.elelis}" var="ElementDTO" itemValue="#{ElementDTO.location}" itemlabel="#{ElementDTO.location}"/>
</h:selectOneMenu>
</h:panelGrid>
<p:commandButton value="Add" update="regGrid" action="#{addDefaultPackage.add()}" />
</p:panel>
</h:form>
</h:body>
</html>
动态网络项目中的我的bean页面:
package beans;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import elementManagement.ElementMgr;
import elementManagementDTO.ElementDTO;
import DefaultPackageManagement.DefaultPackageMgr;
import DefaultPackageManagementDTO.DefaultPackageDTO;
@ManagedBean(name="addDefaultPackageBean") //come viene richiamato
@RequestScoped
public class AddDefaultPackageBean {
@EJB
private DefaultPackageMgr defpackMgr;
private DefaultPackageDTO defpackDTO;
private List<ElementDTO> elelis;
private String name;
@EJB
private ElementMgr elemMgr;
public AddDefaultPackageBean() {
//defpackDTO = new DefaultPackageDTO();
}
@PostConstruct
public void init()
{
setElelis(elemMgr.getAllElements());
}
public String add() {
defpackMgr.save(defpackDTO);
return "home?faces-redirect=true";
}
public List<ElementDTO> getElelis() {
return elelis;
}
public void setElelis(List<ElementDTO> elelis) {
this.elelis = elelis;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public DefaultPackageDTO getDefpackDTO() {
return defpackDTO;
}
public void setDefpackDTO(DefaultPackageDTO defpackDTO) {
this.defpackDTO = defpackDTO;
}
}
ElementmanagementDTO.elementDTO类:
package elementManagementDTO;
import java.util.Date;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.validator.constraints.NotEmpty;
public class ElementDTO {
@NotEmpty
private int cost;
@NotEmpty
private String description;
@NotEmpty
@Temporal(TemporalType.DATE)
private Date endingDate;
@NotEmpty
private String location;
@NotEmpty
@Temporal(TemporalType.DATE)
private Date startingDate;
@NotEmpty
private String type;
@NotEmpty
private String name;
//@Pattern(regexp="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?",
// message="invalid email")
public int getCost() {
return cost;
}
public void setCost(int cost) {
this.cost = cost;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Date getStartingDate() {
return startingDate;
}
public void setStartingDate(Date startingDate) {
this.startingDate = startingDate;
}
public Date getEndingDate() {
return endingDate;
}
public void setEndingDate(Date endingDate) {
this.endingDate = endingDate;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
我的managerbean函数,位于ejb中,具有从elementDTO中的查询转换模型中的元素的范围:
public List<ElementDTO> getAllElements() {
List<Element> ele=new ArrayList<Element>();
ele=em.createNamedQuery(Element.FIND_ALL, Element.class)
.getResultList();
ElementDTO eleDTO;
List<ElementDTO> elementDTO=new ArrayList<ElementDTO>();
for(Element e:ele)
{
eleDTO= convertToDTO(e);
elementDTO.add(eleDTO);
}
return elementDTO;
}
我的查询位于模型中:
@NamedQuery(name="Element.findAll", query="SELECT e FROM Element e")
和managerbean中使用的字符串:
public static final String FIND_ALL = "Element.findAll";
答案 0 :(得分:2)
elementmanagementDTO.elementDTO@3231313是JVM中的the initial memory address of the object。
我只能看到你的itemlabel
selectItems应该有一个大写 L itemLabel
<f:selectItems value="#{addDefaultPackageBean.elelis}"
var="ElementDTO" itemValue="#{ElementDTO.location}"
itemLabel="#{ElementDTO.location}"/>