【问题标题】:selectedIndex attribute of panelTabbedPane in JSF not workingJSF 中 panelTabbedPane 的 selectedIndex 属性不起作用
【发布时间】:2012-09-15 04:51:53
【问题描述】:

JSP 代码

<t:panelTabbedPane align="left"  serverSideTabSwitch="false" styleClass="tabbedPane" 
            activeTabStyleClass="activeTab" inactiveTabStyleClass="inactiveTab" width="100%" cellpadding="0"
            cellspacing="0" tabContentStyleClass="tabContent" style="margin-top:0px;text-align:center"
            selectedIndex="#{myBB.selectedTab}">

/************ *************** ****************强>/

支持 Bean 代码:

private int selectedIndex;



    public int getSelectedIndex() {
        System.out.println("getter of selectedIndexis called "+selectedIndex);
        return selectedIndex;
    }

    public void setSelectedIndex(int selectedIndex) {
        System.out.println("Setter of selectedIndexis called "+selectedIndex);
        this.selectedIndex= selectedIndex;
    }

支持 bean 属于会话范围。 当我在屏幕中更改 panelTab 并单击提交按钮时,始终显示默认面板。我检查了控制台以从 selectedIndex 的设置器中找到 sysout。但在控制台中它没有被打印,这意味着(我想) selectedIndex 没有被发布到服务器。我使用的是 JSF 1.1 版。任何人都可以建议如何使这项工作?

【问题讨论】:

  • System.out.println("请求映射"+FacesContext.getCurrentInstance().getExternalContext().getRequestMap()); System.out.println("请求参数映射"+FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap());我试过这个来查找 selectedIndex 是否被发布到服务器。即使在这个也没有这样的参数。
  • 您的t:panelTabbedPane h:form 中吗?将提交按钮方法放在该bean中并尝试System.out.println(selectedIndex);
  • @Daniel 是的,t:panelTabbedPane 和提交按钮都是同一个表单。整个页面也只有一个表单
  • System.out.println(selectedIndex); 正在打印什么?

标签: jsf tomahawk


【解决方案1】:

对于任何可能遇到此问题的人:

您需要设置 serverSideTabSwitch="true" 并使用 tabChangeListener,否则选项卡切换(和已知的选项卡索引)完全在客户端完成。

【讨论】:

    【解决方案2】:

    根据docsselectedIndex 是要使用的默认选项卡索引,而不是当前实际选择的选项卡索引。

    话虽如此,您可以使用&lt;t:tabChangeListener&gt; 来选择当前选择的标签。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-03
      • 1970-01-01
      • 2011-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多