我在使用jsf中的datalist和primefaces時,遇到問題支持所選對象的bean類字段沒有更新到選定的datalist行,它始終給出空對象。下面是代碼選中的行不在數據列表中選中JSF
視圖文件:
`<?xml version="1.0"?>`
<f:view xmlns="http://www.w3.org/1999/xhtml"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head />
<h:body>
<h:form>
<p:dataList value="#{tableBean.getList()}" var="job" id="cars"
paginator="true" rows="5" effectSpeed="fast"
paginatorTemplate="{PreviousPageLink} {CurrentPageReport} {NextPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5" type="none">
<f:facet name="header">
Applicants List
</f:facet>
<p:column>
<div style="width: 200px">
<h:outputText value="Name:" style="margin-left:10px" />
<h:outputText value="#{job.name}" style="margin-left:10px" />
<br />
<h:outputText value="Applied for:" style="margin-left:10px" />
<h:outputText value="#{job.jobtitle}" style="margin-left:10px" />
<br />
<h:outputText value="Degree:" style="margin-left:10px" />
<h:outputText value="#{job.degree}" style="margin-left:10px" />
<br />
<h:outputText value="Experience:" style="margin-left:10px" />
<h:outputText value="#{job.experience}" style="margin-left:10px" />
<br />
<h:outputText value="Contact:" style="margin-left:10px" />
<h:outputText value="#{job.contact}" style="margin-left:10px" />
<br />
<h:commandLink value="Call for Interview" style="margin-left:10px"></h:commandLink>
</div>
<br/>
<p:commandButton icon="ui-icon-search"
actionListener="#{tableBean.printView}" title="View Detail">
<f:setPropertyActionListener value="#{job}"
target="#{tableBean.selectedJob}" />
</p:commandButton>
<p:separator id="separator" />
</p:column>
</p:dataList>
</h:form>
</h:body>
</f:view>
表bean類:
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.bean.ViewScoped;
import javax.faces.event.ActionEvent;
import DAO.JobApplicationDao;
import DTO.JobApplicationDto;
@ManagedBean
@ViewScoped
public class TableBean implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
public JobApplicationDto selectedJob;
public TableBean() {
}
public List<JobApplicationDto> getList() {
List<JobApplicationDto> joblist = new ArrayList<JobApplicationDto>();
JobApplicationDao dao = new JobApplicationDao();
joblist =dao.getDroppedCv();
return joblist;
}
public JobApplicationDto getSelectedJob() {
return selectedJob;
}
public void setSelectedJob(JobApplicationDto selectedJob) {
this.selectedJob = selectedJob;
}
public void printView(ActionEvent event) {
try{
System.out.print("Selected Person "+getSelectedJob.getName());
}catch(Exception e){
}
}
}
首先,你是什麼意思與選擇?點擊'p:commandButton'? – 2013-02-28 21:35:35