当使用dynamic=“true”时在 p:tabView 上,其他选项卡不会打开,并且不会调用第一个选项卡中的命令链接

发布于 2024-12-22 10:32:25 字数 5843 浏览 1 评论 0原文

我正在使用 JSF 2.0 和 PrimeFaces 3.0 M3。当我在 上设置 dynamic="false" 时,它工作正常。但是当我将其设置为 true 时,只有当前活动的选项卡才起作用。其他选项卡不运行。在第一个选项卡中,我在数据表中有一个命令链接,但这也不起作用。

下面是我的 tabletabview.xhtml

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.prime.com.tr/ui"
    xmlns:ui="http://java.sun.com/jsf/facelets">
    <h:head>
    </h:head>
    <h:body>
        <f:view>
            <h:form>
                <p:growl id="growl" showDetail="true" />
                <p:tabView cache="false"  dynamic="true" activeIndex=0 >
                    <p:ajax event="tabChange" listener="ActivityController.onChange"/>
                    <p:tab title="Search Results 1">
                        <p:dataTable var="dataItem" value="#{ActivityController.dataList}">
                            <p:column>
                                <p:panel style="font-size:12px;width:600px">
                                    <f:facet name="header">
                                        <h:outputText value="#{dataItem.activityname}" />
                                    </f:facet>
                                    <div style="background-color: #DEB887;">
                                        <h:outputText value="Location:" style="color:#FF0000;"></h:outputText>
                                        <h:outputText value="#{dataItem.address}" />
                                        <br></br>
                                    </div>
                                    <div style="background-color: #DEB887;">
                                        <h:outputText value="Start Date:" style="color:#FF0000;"></h:outputText>
                                        <h:outputText value="#{dataItem.startingdate}" />
                                        <br></br>
                                    </div>
                                    <div style="background-color: #DEB887;">
                                        <h:outputText value="Start Date:" style="color:#FF0000;"></h:outputText>
                                        <h:outputText value="#{dataItem.endingdate}" />
                                    </div>
                                    <div style="background-color: #DEB887;">
                                        <h:outputText value="Description:" style="color:#FF0000;"></h:outputText>
                                        <h:outputText value="#{dataItem.description}" />
                                        <br></br>
                                    </div>
                                    <p:commandLink action="#{ActivityController.editDataItem}">
                                        <div style="display: none">
                                            <h:outputText value="#{dataItem.activityname}" />
                                        </div>
                                        <h:outputText value="more....."></h:outputText>
                                        <f:setPropertyActionListener target="#{ActivityController.dataItem}" value="#{dataItem}" />
                                    </p:commandLink>
                                </p:panel>
                            </p:column>
                        </p:dataTable>
                    </p:tab>
                    <p:tab title="Search Results 2">
                        <p:panel style="width:600px;height:600px">
                            <p:schedule id="sche" value="#{searchController.eventModel}"
                                editable="true" draggable="false" resizable="false"
                                widgetVar="myschedule">
                                <p:ajax event="eventSelect"
                                    listener="#{searchController.onEventSelect}" update="red"
                                    process="@this" />
                            </p:schedule>
                        </p:panel>
                    </p:tab>
                    <p:tab id="gmap" title="Search Results 3">
                        <ui:include src="/locationpointers.xhtml"></ui:include>
                    </p:tab>
                </p:tabView>
            </h:form>
        </f:view>
    </h:body>
</html>

这是我的 ActivityController.java 的相关部分

public List<ActivityRegBean> getDataList() {
    return dataList;
}

public void setDataList(List<ActivityRegBean> dataList){
    this.dataList=dataList;
}

private ActivityRegBean dataItem;
private HtmlInputHidden dataItemId = new HtmlInputHidden() ;


public String editDataItem() throws IOException {
    FacesContext context = FacesContext.getCurrentInstance();  
    System.out.println(dataItem.activityname);
    dataItemId.setValue(dataItem.activityid);
    System.out.println(dataItem.activityid);
    retfromtable(dataItem.activityname);
    return "edit"; // Navigation case.
}

public void onChange(TabChangeEvent event) { 
    System.out.println("tab id = " + event.getTab().getId());
}

ActivityRegBean 有一个 getter 和 setter。

如何在 上使用 dynamic="true" 而不会出现问题?

I am using JSF 2.0 with PrimeFaces 3.0 M3. When I set dynamic="false" on <p:tabView>, then it works fine. But when I set it to true, then only the currently active tab works. Other tabs does not run. In the 1st tab I have a command link in a data table, this is also not working.

Below is my tabletabview.xhtml:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.prime.com.tr/ui"
    xmlns:ui="http://java.sun.com/jsf/facelets">
    <h:head>
    </h:head>
    <h:body>
        <f:view>
            <h:form>
                <p:growl id="growl" showDetail="true" />
                <p:tabView cache="false"  dynamic="true" activeIndex=0 >
                    <p:ajax event="tabChange" listener="ActivityController.onChange"/>
                    <p:tab title="Search Results 1">
                        <p:dataTable var="dataItem" value="#{ActivityController.dataList}">
                            <p:column>
                                <p:panel style="font-size:12px;width:600px">
                                    <f:facet name="header">
                                        <h:outputText value="#{dataItem.activityname}" />
                                    </f:facet>
                                    <div style="background-color: #DEB887;">
                                        <h:outputText value="Location:" style="color:#FF0000;"></h:outputText>
                                        <h:outputText value="#{dataItem.address}" />
                                        <br></br>
                                    </div>
                                    <div style="background-color: #DEB887;">
                                        <h:outputText value="Start Date:" style="color:#FF0000;"></h:outputText>
                                        <h:outputText value="#{dataItem.startingdate}" />
                                        <br></br>
                                    </div>
                                    <div style="background-color: #DEB887;">
                                        <h:outputText value="Start Date:" style="color:#FF0000;"></h:outputText>
                                        <h:outputText value="#{dataItem.endingdate}" />
                                    </div>
                                    <div style="background-color: #DEB887;">
                                        <h:outputText value="Description:" style="color:#FF0000;"></h:outputText>
                                        <h:outputText value="#{dataItem.description}" />
                                        <br></br>
                                    </div>
                                    <p:commandLink action="#{ActivityController.editDataItem}">
                                        <div style="display: none">
                                            <h:outputText value="#{dataItem.activityname}" />
                                        </div>
                                        <h:outputText value="more....."></h:outputText>
                                        <f:setPropertyActionListener target="#{ActivityController.dataItem}" value="#{dataItem}" />
                                    </p:commandLink>
                                </p:panel>
                            </p:column>
                        </p:dataTable>
                    </p:tab>
                    <p:tab title="Search Results 2">
                        <p:panel style="width:600px;height:600px">
                            <p:schedule id="sche" value="#{searchController.eventModel}"
                                editable="true" draggable="false" resizable="false"
                                widgetVar="myschedule">
                                <p:ajax event="eventSelect"
                                    listener="#{searchController.onEventSelect}" update="red"
                                    process="@this" />
                            </p:schedule>
                        </p:panel>
                    </p:tab>
                    <p:tab id="gmap" title="Search Results 3">
                        <ui:include src="/locationpointers.xhtml"></ui:include>
                    </p:tab>
                </p:tabView>
            </h:form>
        </f:view>
    </h:body>
</html>

This is the relevant part of my ActivityController.java

public List<ActivityRegBean> getDataList() {
    return dataList;
}

public void setDataList(List<ActivityRegBean> dataList){
    this.dataList=dataList;
}

private ActivityRegBean dataItem;
private HtmlInputHidden dataItemId = new HtmlInputHidden() ;


public String editDataItem() throws IOException {
    FacesContext context = FacesContext.getCurrentInstance();  
    System.out.println(dataItem.activityname);
    dataItemId.setValue(dataItem.activityid);
    System.out.println(dataItem.activityid);
    retfromtable(dataItem.activityname);
    return "edit"; // Navigation case.
}

public void onChange(TabChangeEvent event) { 
    System.out.println("tab id = " + event.getTab().getId());
}

The ActivityRegBean has a getter and setter.

How can I use dynamic="true" on the <p:tabView> without problems?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

与君绝 2024-12-29 10:32:25

你能尝试这个而不是 p:ajax

<p:tabView cache="false"  dynamic="true" tabChangeListener="#{ActivityController.onChange}" onTabChangeUpdate="growl">

我注意到你正在使用 xmlns:p="http://primefaces.prime.com.tr/ui" 。它适用于 primefaces 2.2,如果您确实使用 primefaces 3,那么它会抱怨该命名空间不存在标记库。对于 PF3,您应该使用 xmlns:p="http://primefaces.org/ui" 。也许你应该清理你的工作目录。

Can you try this instead of p:ajax

<p:tabView cache="false"  dynamic="true" tabChangeListener="#{ActivityController.onChange}" onTabChangeUpdate="growl">

I have noticed that you are using xmlns:p="http://primefaces.prime.com.tr/ui" . It is for primefaces 2.2 and if you are indeed using primefaces 3, then it will complain about no taglibrary exists for that namespace. for PF3 you should be using xmlns:p="http://primefaces.org/ui" . may be you should clean your work directory.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文