JSF View- returning null on actions do not update the view

怎甘沉沦 提交于 2019-12-23 22:17:06

问题


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;

            }
}

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>

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


回答1:


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;

        }
}


来源:https://stackoverflow.com/questions/23470315/jsf-view-returning-null-on-actions-do-not-update-the-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!