我从PostConstruct注释的init方法得到警告 [英] I'm getting warning from PostConstruct annotated init method

查看:302
本文介绍了我从PostConstruct注释的init方法得到警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从@PostConstruct注释的init方法收到此警告

I'm getting this warning from @PostConstruct annotated init method

Nis 18,2014 2:46:10 PM com.sun.faces.vendor.WebContainerInjectionProvider getAnnotatedMethodForMethodArr 警告:JSF1047:标有"javax.annotation.PostConstruct"注释的方法"public void com.revir.managed.bean.PickListBean.init()抛出java.lang.Exception"无法声明任何已检查的异常.此方法将被忽略.

Nis 18, 2014 2:46:10 PM com.sun.faces.vendor.WebContainerInjectionProvider getAnnotatedMethodForMethodArr WARNING: JSF1047: Method 'public void com.revir.managed.bean.PickListBean.init() throws java.lang.Exception' marked with the 'javax.annotation.PostConstruct' annotation cannot declare any checked exceptions. This method will be ignored.

所以我的方法被忽略了,我该怎么做才能解决此问题?

So my method is ignored, what do I have to do to fix this problem ?

package com.revir.managed.bean;

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 = "pickListBean")
@ViewScoped
public class PickListBean implements Serializable {

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

private DualListModel<TrvrTani> tanis;

private DualListModel<TrvrIlac> ilacs;


int tanisize = 0;
String taniadi = null;
Long taniidp = null;
public Long getTaniidp() {
    return taniidp;
}

public void setTaniidp(Long taniidp) {
    this.taniidp = taniidp;
}

String tanikodu = null;

@Autowired(required=false)
private TrvrTaniDAO tanidao;

public TrvrTaniDAO getTanidao() {
    return tanidao;
}

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

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

List<TrvrIlac> sourceilac;
List<TrvrIlac> targetilac;

@PostConstruct
public void init(){
    try {
        sourcetani = new ArrayList<TrvrTani>();
        targettani = new ArrayList<TrvrTani>();

        tanidao = new TrvrTaniDAO();
        List<TrvrTani> taniList = tanidao.findAll();
        for (TrvrTani tani : taniList) {
            Long taniid = tani.getTaniid();
            sourcetani.add(new TrvrTani(taniid, tani.getTaniadi(), tani
                    .getTanikodu()));
        }

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

        sourceilac = new ArrayList<TrvrIlac>();
        targetilac = new ArrayList<TrvrIlac>();

        ilacdao = new TrvrIlacDAO();
        List<TrvrIlac> ilacList = ilacdao.findAll();
        for (TrvrIlac ilac : ilacList) {
            sourceilac.add(new TrvrIlac(ilac.getIlacid(), ilac.getIlacad(),
                    ilac.getBarkod(), null));
        }

        ilacs = new DualListModel<TrvrIlac>(sourceilac, targetilac);
    } catch (Exception e) {
        System.out.println("Hata mesajı : " +e);
        throw e;
    }
}


public DualListModel<TrvrIlac> getIlacs() {
    return ilacs;
}

public void setIlacs(DualListModel<TrvrIlac> ilacs) {
    this.ilacs = ilacs;
}

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 />");

        targetlist(tanisize, taniadi, taniidp, tanikodu);

    }

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

    FacesContext.getCurrentInstance().addMessage(null, msgtani);
}

public void targetlist(int tanisize, String taniadi, Long taniidp,
        String tanikodu) {

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

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

public void onTransferIlac(TransferEvent event) {
    StringBuilder builder = new StringBuilder();
    for (Object item : event.getItems()) {
        builder.append(((TrvrIlac) item).getIlacad()).append("<br />");
    }

    FacesMessage msgilac = new FacesMessage();
    msgilac.setSeverity(FacesMessage.SEVERITY_INFO);
    msgilac.setSummary("İlaç Eklendi");
    msgilac.setDetail(builder.toString());

    FacesContext.getCurrentInstance().addMessage(null, msgilac);
}
}

推荐答案

从init方法中删除throws Exception.使用try catch可以防止引发任何异常.删除异常声明后,编译器将向您显示可能抛出的任何异常,因此请在此处添加try catch.

Remove the throws Exception from the init method. Use try catch to prevent any exception from being thrown. Once you remove the exception declaration, the compiler will show you of any exceptions that may be thrown, so add try catch there.

这篇关于我从PostConstruct注释的init方法得到警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆