Question

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

Was it helpful?

Solution

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;

        }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top