0

我在带有primefaces的jsf中使用datalist,我面临的问题是所选对象的支持bean类字段没有更新到datalist的选定行,它总是给出空对象。这是代码

查看文件 :

`<?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){

    }

    }

}

4

2 回答 2

1

您应该将 setPropertyActionListener 与 action 一起使用。在调用您的操作之前调用侦听器。似乎 setPropertyActionListener 在 actionListener 之后被调用。

更改actionListener="#{tableBean.printView}"action="#{tableBean.printView}"

和方法

public void printView() {
    try{
        System.out.print("Selected Person "+getSelectedJob.getName());
    }catch(Exception e){

    }

    }

请参阅此内容以更好地了解要使用的内容,

http://balusc.blogspot.com/2006/06/communication-in-jsf.html

于 2013-03-01T01:34:49.753 回答
-1

您可以像这样使用数据表选择

<p:dataList value="#{tableBean.getList()}" selection="#{tableBean.selectedJob}"  var="job" id="cars" 
            paginator="true" rows="5" effectSpeed="fast"
            paginatorTemplate="{PreviousPageLink} {CurrentPageReport} {NextPageLink} {RowsPerPageDropdown}"
            rowsPerPageTemplate="5" type="none">
于 2013-02-28T21:30:30.397 回答