我有以下情况:
有一个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" />
但它仍无法正常工作..
答案 0 :(得分: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
}