Jsf 使用后构造时,Primefaces选取列表始终为空

Jsf 使用后构造时,Primefaces选取列表始终为空,jsf,jsf-2,primefaces,postconstruct,picklist,Jsf,Jsf 2,Primefaces,Postconstruct,Picklist,我下面的代码不起作用,我正在使用primefaces选取列表和postconstruct注释对带有try-catch块的init方法进行注释。 不管我的picklistbean是空的,我尝试了所有的方法让它工作,但是没有一个有效。 有没有人能给我提供一个清单的工作示例,或者在我的代码中我遗漏了什么? 我在这个问题上坚持了这么久,如果有人帮助我,我会很高兴的 import java.io.Serializable; import java.util.ArrayList; import java.u

我下面的代码不起作用,我正在使用primefaces选取列表和postconstruct注释对带有try-catch块的init方法进行注释。 不管我的picklistbean是空的,我尝试了所有的方法让它工作,但是没有一个有效。 有没有人能给我提供一个清单的工作示例,或者在我的代码中我遗漏了什么? 我在这个问题上坚持了这么久,如果有人帮助我,我会很高兴的

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

import org.primefaces.event.TransferEvent;
import org.primefaces.model.DualListModel;
import org.springframework.beans.factory.annotation.Autowired;


@ManagedBean(name = "pickListBeanTani")
@ViewScoped
public class PickListBeanTani implements Serializable {

/**
 * 
 */
private static final long serialVersionUID = 1L;

private DualListModel<TrvrTani> tanis;

@ManagedProperty(value = "#{TrvrTaniDAO}")
private TrvrTaniDAO tanidao;

public TrvrTaniDAO getTanidao() {
    return tanidao;
}


public void setTanidao(TrvrTaniDAO tanidao) {
    this.tanidao = tanidao;
}


private List<TrvrTani> sourcetani;
private List<TrvrTani> targettani;

@PostConstruct
public void init(){

    try {
        sourcetani = new ArrayList<TrvrTani>();
        targettani = new ArrayList<TrvrTani>();

        tanidao = new TrvrTaniDAO();
        List<TrvrTani> taniList = tanidao.findAll();
        System.out.println("tanılist" +taniList);
        for (TrvrTani tani : taniList) {
            sourcetani.add(new TrvrTani(tani.getTaniid(), tani.getTaniadi(), tani
                    .getTanikodu()));
        }

        tanis = new DualListModel<TrvrTani>(sourcetani, targettani);

    } catch (Exception e) {
        throw e;
    }

}


public List<TrvrTani> getSourcetani() {
    return sourcetani;
}

public void setSourcetani(List<TrvrTani> sourcetani) {
    this.sourcetani = sourcetani;
}

public List<TrvrTani> getTargettani() {
    return targettani;
}

public void setTargettani(List<TrvrTani> targettani) {
    this.targettani = targettani;
}

public DualListModel<TrvrTani> getTanis() {
    return tanis;
}

public void setTanis(DualListModel<TrvrTani> tanis) {
    this.tanis = tanis;
}


public void onTransferTani(TransferEvent event) {
    StringBuilder builder = new StringBuilder();
    for (Object item : event.getItems()) {
        builder.append(((TrvrTani) item).getTaniadi()).append("<br />");

        int tanisize = tanis.getTarget().size();
        System.out.println(" ************target*************  : "
                + tanis.getTarget().size());
        for (int h = 0; h < tanisize; h++) {

            /* elemanin adi, id si ve kodu */
            String taniadi = tanis.getTarget().get(h).getTaniadi();
            System.out.println(" ************taniadi1*************  : "
                    + taniadi);
            Long taniidp = tanis.getTarget().get(h).getTaniid();
            System.out.println(" ************taniid2*************  : "
                    + taniidp);
            String tanikodu = tanis.getTarget().get(h).getTanikodu();
            System.out.println(" ************tanikodu3*************  : "
                    + tanikodu);
        }

    }

    FacesMessage msgtani = new FacesMessage();
    msgtani.setSeverity(FacesMessage.SEVERITY_INFO);
    msgtani.setSummary("Tanı Eklendi");
    msgtani.setDetail(builder.toString());

    FacesContext.getCurrentInstance().addMessage(null, msgtani);
}
}
import java.io.Serializable;
导入java.util.ArrayList;
导入java.util.List;
导入javax.annotation.PostConstruct;
导入javax.faces.application.FacesMessage;
导入javax.faces.bean.ManagedBean;
导入javax.faces.bean.ViewScoped;
导入javax.faces.context.FacesContext;
导入org.primefaces.event.transfervent;
导入org.primefaces.model.DualListModel;
导入org.springframework.beans.factory.annotation.Autowired;
@ManagedBean(name=“pickListBeanTani”)
@视域
公共类PickListBeanTani实现可序列化{
/**
* 
*/
私有静态最终长serialVersionUID=1L;
私有二元列表模型;
@ManagedProperty(value=“#{TrvrTaniDAO}”)
私人TrvrTaniDAO tanidao;
公共TrvrTaniDAO GETANIDAO(){
返回塔尼多;
}
塞塔尼多公共空间(TrvrTaniDAO tanidao){
this.tanidao=tanidao;
}
私人名单;
特格塔尼私人名单;
@施工后
公共void init(){
试一试{
sourcetani=newarraylist();
targettani=新的ArrayList();
tanidao=新TrvrTaniDAO();
List taniList=tanidao.findAll();
系统输出println(“tanılist”+taniList);
for(TrvrTani-tani:taniList){
添加(新的TrvrTani(tani.gettanid(),tani.getTaniadi(),tani
.getTanikodu());
}
tanis=新的DualListModel(sourcetani,targettani);
}捕获(例外e){
投掷e;
}
}
公共列表getSourcetani(){
返回源塔尼;
}
公共无效设置源代码(列表源代码){
this.sourcetani=sourcetani;
}
公共列表getTargettani(){
返回塔吉塔尼;
}
公共无效setTargettani(列出targettani){
this.targettani=targettani;
}
公共双列表模型getTanis(){
返回塔尼斯;
}
公共无效设置(双列表模式设置){
this.tanis=tanis;
}
公共无效onTransferTani(转让事件){
StringBuilder=新的StringBuilder();
对于(对象项:event.getItems()){
builder.append(((TrvrTani)item.getTaniadi()).append(
); int-tanisize=tanis.getTarget().size(); System.out.println(“*************目标*******************:” +tanis.getTarget().size()); for(inth=0;h
在PostContract中,dao类不会注入bean中。如果要初始化bean中的某些内容,请尝试preRenderView

也不要使用
tanidao=new TrvrTaniDAO()。TaniDao应该由spring使用
自动连线
注入

编辑

另外,如果您应该向TrvrTaniDAO注入jsf托管属性

@ManagedProperty(value = "#{TrvrTaniDAO}")
private TrvrTaniDAO tanidao;

移除tanidao后=新TrvrTaniDAO();现在我得到了taniListIt的nullpointerexception是正常的,因为TaniDao不是由spring注入的。您的自动连线注释没有设置TaniDao的值。如何集成jsf和spring?您是否尝试过preRender。如果自动连线设置了TaniDao的值,preRender将起作用。我在下面写到另一个bean,但我收到一个错误消息:HTTP状态500-无法为托管bean用户OS
@ManagedProperty(“pickListBeanTani}”)私有pickListBeanTani pickListBeanTani设置属性pickListBeanTani;public void setPickListBeanTani(PickListBeanTani PickListBeanTani){this.PickListBeanTani=PickListBeanTani;}
jsf ile spring contextlerini haberleştiğinden emi misi?Chunkümuhtemelen ikisi entegre edilmemiş.applicationcontext.xml dosyasında beanleri tanımladım ayrıca faces-config.xml dosyasına org.springframework.web.jsf.el.SpringBeanFacesELResolver yazdımŞu an tekıkıntımanagedproperty Injectememem