jsf-2 - p :tabView: direct link to tab

标签 jsf-2 primefaces tabview

我想要一个链接来打开 p:tabView 的特定选项卡。我试过这个链接但是

它不工作(第一个选项卡打开):/jsf/.....#tabView:tabA

这是我的 TabView:

  <p:tabView id="tabView">        
            <p:tab id="tabb" title="B">
            </p:tab>    
        <p:tab id="tabA" title="A">
        </p:tab>            
 </p:tabView>

任何帮助将不胜感激!

最佳答案

您可以按照 PrimeFaces 文档中的说明使用 javascript 调用小部件。 为 tabView 指定一个小部件名称并使用 .select(tabIndex) 更改选项卡

如果您从另一个页面重定向,您可以传递一个请求参数(例如../url?tabIndex=0)来决定哪个选项卡将被激活,从 url 参数中获取变量并再次激活该选项卡使用客户端 api(javascript 调用)。

<p:tabView id="tabView" widgetVar="myTabExample">        
          </p:tab>
        <p:tab id="tabb" title="B">
         </p:tab>   
        <p:tab id="tabA" title="A">
        </p:tab>            
 </p:tabView>

<script>
   myTabExample.select(0);
</script>

我还添加了一个带有get参数的例子

 <p:tabView id="tabView" widgetVar="myTabExample">        
              </p:tab>
            <p:tab id="tabb" title="B">
             </p:tab>   
            <p:tab id="tabA" title="A">
            </p:tab>            
     </p:tabView>

    <script>
    //function to parse get parameters from url
    //taken from http://stackoverflow.com/questions/831030/how-to-get-get-request-parameters-in-javascript
    function get(name){
        if (name=(new RegExp('[?&]'+encodeURIComponent(name)+'= ([^&]*)')).exec(location.search))
        return decodeURIComponent(name[1]);
     }

    myTabExample.select(get("tabIndex"));
</script>

关于jsf-2 - p :tabView: direct link to tab,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21676328/

相关文章:

jsf - p :commandButton in composite component 的操作和操作监听器

java - 截断 p :dataTable and exporting the table with the full text 中的大文本值

java - Android在底部导航栏中禁用缩放效果

java - Apache MyFaces JSF2.0 bug : getStateHelper(). put 没有保存任何内容?

Primefaces 对要在页脚中显示的特定列求和

jsf-2 - 重置PrimeFaces DataTable状态(过滤器,排序,分页)

primefaces - tabview 的事件索引未自动更新

android - 从选项卡 Activity 中打开另一个 Activity

java - 上传 .pdf、.doc 或 .docx 时出现 HTTP 错误。使用 primefaces 上传工具上传文件

java - JSF p :commandLink and p:ajax have different behavior in update