使用 Javascript 更改 Primefaces p:steps activeIndex? [英] Change Primefaces p:steps activeIndex with Javascript?
本文介绍了使用 Javascript 更改 Primefaces p:steps activeIndex?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在考虑使用 p:steps
组件
I'm considering using the p:steps
component
<p:steps activeIndex="1" styleClass="custom" readonly="false">
<p:menuitem value="Personal" url="#"/>
<p:menuitem value="Seat Selection" url="#"/>
<p:menuitem value="Payment" url="#"/>
<p:menuitem value="Confirmation" url="#"/>
</p:steps>
如何使用 Javascript 更改 activeIndex?
how can I change activeIndex with Javascript?
推荐答案
通常,您应该能够使用 JavaScript API 和使用 widgetVar
属性来执行此操作.但是,当我使用 widgetVar="stepsVar"
时,小部件是未知的(JavaScript 控制台):
Normally you should be able to do so using the JavaScript API and using the widgetVar
attribute. However, when I use widgetVar="stepsVar"
, the widget is unknown (JavaScript console):
> PF('stepsVar')
Widget for var 'stepsVar' not available!
所以,恐怕您需要某种解决方法.例如,将索引保存在托管 bean 中并使用 更新它远程命令
.
So, you need some kind of workaround I'm afraid. For example, keep the index in a managed bean and update it using a remoteCommand
.
<p:remoteCommand name="setStepIndex"
action="#{yourBean.setStepIndexByRemoteCommand}"
update="steps"/>
<p:steps id="steps"
activeIndex="#{yourBean.stepIndex}">
<p:menuitem value="Personal" />
<p:menuitem value="Seat Selection" />
<p:menuitem value="Payment" />
<p:menuitem value="Confirmation" />
</p:steps>
<button onclick="setStepIndex([{name:'index', value:2}]);return false">Test</button>
豆
private int stepIndex;
public int getStepIndex()
{
return stepIndex;
}
public void setStepIndexByRemoteCommand()
{
FacesContext context = FacesContext.getCurrentInstance();
Map<String, String> map = context.getExternalContext().getRequestParameterMap();
String indexString = map.get("index");
stepIndex = Integer.valueOf(indexString);
}
另见
- 从 JavaScript 向 p:remoteCommand 传递参数
这篇关于使用 Javascript 更改 Primefaces p:steps activeIndex?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文