JSF View-在操作上返回null不会更新视图 [英] JSF View- returning null on actions do not update the view

查看:103
本文介绍了JSF View-在操作上返回null不会更新视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了与我的问题相同的帖子 JSF ViewScope-在操作上返回null不会更新视图 但这对我没有用,因为我已经在另一页中使用了h:commandLink,并且效果很好,但在此页中却没有.

这是请求Bean

i have read the post that have same problem as mine JSF ViewScope - returning null on actions do not update the view but it haven't worked for me cause i already use the h:commandLink in another page and its works perfectly but in this page it doesn't .

this is the request Bean

public class AddSectionBean {
    public String delete(String id) {
                try {

                    HttpSession session = SessionUtil.getSession();
                    UserVO userVOCreater = (UserVO) session.getAttribute("userVO");

                    SectionsDao.getInstance().deleteSectionById(
                            Integer.parseInt(id));

                    LoggerVO loggerVO =new LoggerVO();
                    loggerVO.setUserid(userVOCreater.getId());
                    loggerVO.setLog("deleted Section Id:"+id);
                    LoggerDao.getInstance().insertLogger(loggerVO);

                } catch (Exception e) {
                    e.printStackTrace();
                    BundleMessages.getInstance().setMessage("error",
                            FacesMessage.SEVERITY_ERROR);
                    logger.error(e.getMessage(), e);

                }

                return null;

            }
}

并且该链接位于每个列的RichTable内

and the link is inside a richtable for every column

 <rich:column>
 <h:commandLink id="actualDelete" styleClass="delete_#{sectionsBean.datatableSections.rowIndex}" action ="#{addSectionBean.delete(s.id)}" />
 </rich:column>

请注意:我试图返回结果,而不是返回null,但是当我这样做时,我丢失了页面中的样式和脚本 ,请注意,脚本没有任何作用,因为我已经用它们对其进行了测试并获得了相同的结果

Note That: i tried to return the outcome instead of null but when i do that i lose the style and scripts in page , note that the scripts have no effect cause i have tested it with them and had the same result

推荐答案

通过将delete方法移至查看表的bean并在delete函数中再次调用数据库方法以重新加载表(即使重新加载表)也解决了该问题postConstruct函数

the problem solved by moving the delete method to the bean that view the table and calling the database method again inside the delete function to reload the table even its reloads in the postConstruct function

public class SectionsBean{
List<SectionVO> sectionsList = new ArrayList<SectionVO>();

    @PostConstruct
     public void postConstruct() {
        try {
        this.sectionsList = SectionsDao.getInstance().getSections();
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage(), e);

        }

    }
 public String delete(String id) {
            try {

                HttpSession session = SessionUtil.getSession();
                UserVO userVOCreater = (UserVO) session.getAttribute("userVO");

                SectionsDao.getInstance().deleteSectionById(
                        Integer.parseInt(id));

                LoggerVO loggerVO =new LoggerVO();
                loggerVO.setUserid(userVOCreater.getId());
                loggerVO.setLog("deleted Section Id:"+id);
                LoggerDao.getInstance().insertLogger(loggerVO);
//reload the database table
                this.sectionsList = SectionsDao.getInstance().getSections();
            } catch (Exception e) {
                e.printStackTrace();
                BundleMessages.getInstance().setMessage("error",
                        FacesMessage.SEVERITY_ERROR);
                logger.error(e.getMessage(), e);

            }
            BundleMessages.getInstance().setMessage("success",
                    FacesMessage.SEVERITY_INFO);
            System.out.println("calling delete id="+id);
            return null;

        }
}

这篇关于JSF View-在操作上返回null不会更新视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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