0

我有以下情况:

有一个JSF页面:

<h:form id="form">

            <!-- MENU SHOULD GOES HERE -->
            <p:commandButton action="#{bean.sched.addWeek}" value="Add week" update="weeksTab" />

            <p:tabView id="weeksTab" value="#{bean.sched.weekList}" var="week" >

                <p:tab title="#{week.name}" >

                    <!-- THIS BUTTONS SHOULD BE IN MENU -->
                    <p:commandButton action="#{week.addDay}" value="Add day" update="weeksTab" />
                    <p:commandButton action="#{bean.sched.removeWeek(week)}" value="Remove week" update="weeksTab" />

                    <p:tabView id="daysTab" value="#{week.dayList}" var="day" >
                        <p:tab title="#{day.name}">

                        <!-- THIS BUTTON SHOULD BE IN MENU -->
                        <p:commandButton action="#{week.removeDay(day)}" value="Remove day" update="weeksTab" />

                        <!-- PROCESSING DAY : ADDING MEETINGS, ROUTINES ETC.
                            THOSE FUNCTIONS SHOULD BE ALSO AVAILABLE
                            IN MENU -->

                        </p:tab>
                    </p:tabView>
                </p:tab>
            </p:tabView>

我想将所有操作控件(例如添加/删除/编辑周、天和用户的每日活动按钮)放在页面顶部的菜单中。问题是如何传递给 p:tabView 内部管理的外部标签变量?有可能吗?我在 h:form 中添加这样的东西:

<p:toolbar>
                <p:toolbarGroup align="left">
                    <p:commandButton
                        onclick="jQuery('#hiddenAddWeekButton').click();return false;"
                        value="Add week" icon="ui-icon-circle-plus" ajax="false" />

                </p:toolbarGroup>
            </p:toolbar>

            <p:commandButton id="hiddenAddWeekButton"
                action="#{bean.sched.addWeek}" value="add week"
                update="weeksTab" style="display:none" />

但它仍然无法正常工作..

4

1 回答 1

1

尝试这样的事情

隐藏你的内部按钮

<p:commandButton id="myHiddenButton" action="#{week.removeDay(day)}" value="Remove day" update="weeksTab" style="display:none"/>

而不是在选项卡上方放置新按钮

<p:commandButton value="Remove day" onclick="jQuery('#weeksTab\\:myHiddenButton').click();return false;" />

要确定为隐藏按钮生成的正确 ID,只需在浏览器中查看源代码,我认为它应该类似于 weekTab:myHiddenButton (使用 \:) 来逃避:


更新

由于它位于选项卡中,您应该尝试使用带有选择器的结尾,就像这样

<p:commandButton value="Remove day" onclick="myJsFunctionThatSitsInMyJsFile();return false;" />

在哪里myJsFunctionThatSitsInMyJsFile

如下

function myJsFunctionThatSitsInMyJsFile(){
    jQuery('input[id$="hiddenAddDayButton"]:visible').click(); //added visible selector , so the only button that being visible , should be clicked
}
于 2012-08-15T18:07:13.567 回答