【问题标题】:Same method of the managed bean getting called twice托管 bean 的相同方法被调用两次
【发布时间】:2012-12-31 09:48:23
【问题描述】:

我正在使用 JSF1.2 开发分页逻辑,在此过程中,我有 4 个链接,分别对应于结果的第一页、上一页、下一页和最后一页。我在“搜索”页面中输入搜索条件,然后单击“提交”以获取一些记录。我有一个与每条记录对应的查看链接,可以查看完整的详细信息。所以我有两个托管 bean,一个用于搜索/分页功能,另一个用于查看完整的记录详细信息。

那有什么问题呢?

当我搜索记录时,分页工作完全正常。但是,当我查看记录的详细信息并返回搜索页面时,我发现每次单击下一步按钮时,next() 方法都会被调用两次。

有什么解决办法吗?

The code is as follows:-

Inside search:-
 <h:commandLink value="#{msg['heading.nextLink']}"
                                            binding="#{searchRoutesForView.nextLink}" 
                                            actionListener="#{searchRoutesForView.next}">
                                        </h:commandLink>

Inside SearchManagedbean:-

public void next(ActionEvent actionEvent) {

        if ((pointer + noOfRecordsToBeDisplayed) >= readConfig.length) {
            readRoutingResponse.setReadConfig(Arrays.copyOfRange(readConfig,
                    pointer, readConfig.length));
            pointer = readConfig.length;
            System.out.println("pointer inside next =" + pointer);
            setOrDisableLinks(false, false, true, true);
        } else {
            readRoutingResponse.setReadConfig(Arrays.copyOfRange(readConfig,
                    pointer, pointer + noOfRecordsToBeDisplayed));
            pointer += noOfRecordsToBeDisplayed;
            System.out.println("pointer inside next -- else =" + pointer);
            setOrDisableLinks(false, false, false, false);
        }
    }

【问题讨论】:

  • 您能从您的 xhtml 中显示更多代码吗?特别是如果您的 h:commandLink 周围有一个条件,并且您的 searchRoutesForView 在哪个范围内

标签: jsf jsf-1.2


【解决方案1】:

请查看lifecyle of JSF

下面的方法可能不是最好的..

public void next(ActionEvent actionEvent)
{
   if((pointer + noOfRecordsToBeDisplayed) >= readConfig.length) && (isVisitedOnce == false))
     {
        visitedOnce = true //set one boolean indicating this method is already visited 
      }
}

如果 bean 在请求范围内,这将不起作用。

【讨论】:

    猜你喜欢
    • 2012-12-26
    • 2013-01-24
    • 1970-01-01
    • 2011-02-16
    • 1970-01-01
    • 1970-01-01
    • 2012-03-26
    • 1970-01-01
    • 2021-11-04
    相关资源
    最近更新 更多