Ajax 如何激活通过单击菜单栏上的菜单项打开的上次打开的选项卡?
我创建了一个web应用程序。这里我使用prime face选项卡和ajax。 当我点击菜单栏上的菜单项时,它会打开一个新的选项卡。但激活第一个打开的选项卡。我想激活上次打开的选项卡。 我的代码在这里: 用于菜单栏和输出选项卡Ajax 如何激活通过单击菜单栏上的菜单项打开的上次打开的选项卡?,ajax,jsf-2,primefaces,Ajax,Jsf 2,Primefaces,我创建了一个web应用程序。这里我使用prime face选项卡和ajax。 当我点击菜单栏上的菜单项时,它会打开一个新的选项卡。但激活第一个打开的选项卡。我想激活上次打开的选项卡。 我的代码在这里: 用于菜单栏和输出选项卡 <h:form id="menu"> <p:menubar autoDisplay="true"> <p:submenu id="student" label
<h:form id="menu">
<p:menubar autoDisplay="true">
<p:submenu id="student" label="Student">
<p:menuitem id="studentAdmission" value="Student Admission" action="#{ajaxBean.editAction}" ajax="true" update=":outputForm">
<f:setPropertyActionListener target="#{ajaxBean.action}" value="StudentAdmission" />
</p:menuitem>
<p:menuitem id="studentList" value="Student Profile" action="#{ajaxBean.editAction}" ajax="true" update=":outputForm">
<f:setPropertyActionListener target="#{ajaxBean.action}" value="StudentProfile" />
</p:menuitem>
</p:submenu>
<p:submenu id="registration" label="Registration">
<p:menuitem id="registrationAdd" value="Subject Registration" action="#{ajaxBean.editAction}" ajax="true" update=":outputForm">
<f:setPropertyActionListener target="#{ajaxBean.action}" value="SubjectRegistration"/>
</p:menuitem>
<p:menuitem id="registrationList" value="List of Registration" action="#{ajaxBean.editAction}" ajax="true" update=":outputForm">
<f:setPropertyActionListener target="#{ajaxBean.action}" value="RegistrationList" />
</p:menuitem>
</p:submenu>
</p:menubar>
</h:form>
<h:form id="outputForm">
<p:tabView id="outputTab">
<p:ajax event="tabClose" listener="#{ajaxBean.closeTab}"/>
<c:forEach items="#{ajaxBean.chcekItem}" var="item" varStatus="loop">
<p:tab id="#{item}" title="#{item}" closable="true">
<ui:include src="#{bundle[item]}"/>
</p:tab>
</c:forEach>
</p:tabView>
</h:form>
菜单umanagedbean.java
package com.ajax;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import org.primefaces.event.TabCloseEvent;
/**
*
* @author DELL
*/
@ManagedBean(name = "ajaxBean")
@SessionScoped
public class AjaxBean implements Serializable {
public AjaxBean() {
}
private boolean input;
private List<String> chcekItem = new ArrayList<String>();
public void setAction(String action) {
input = true;
if (getChcekItem().isEmpty()) {
getChcekItem().add(action);
System.out.println("The item " + action + " is Successfully Added to array");
} else {
for (String abce : getChcekItem()) {
if (abce.equals(action)) {
System.out.println(abce + "=" + action);
input = false;
//We can jump out of the loop here since we already found a matching value
break;
}
}
if (input) {
getChcekItem().add(action);
System.out.println("The item " + action + " is Successfully Added to array");
} else {
System.out.println("The item " + action + " is Exist");
}
}
}
private String close;
public void closeTab(TabCloseEvent closeAction) {
close = closeAction.getTab().getId();
for (String abce : getChcekItem()) {
if (abce.equals(close)) {
System.out.println(close + " is remove from Array");
getChcekItem().remove(abce);
//We can jump out of the loop here since we already found a matching value
break;
}
}
}
public String editAction() {
return null;
}
/**
* @return the arrJavaTechnologies
*/
/**
* @return the chcekItem
*/
public List<String> getChcekItem() {
return chcekItem;
}
/**
* @param chcekItem the chcekItem to set
*/
public void setChcekItem(ArrayList<String> chcekItem) {
this.chcekItem = chcekItem;
}
/**
* @return the input
*/
public boolean isInput() {
return input;
}
/**
* @param input the input to set
*/
public void setInput(boolean input) {
this.input = input;
}
/**
* @return the menuaction
*/
package com.ajax;
public class Item {
public Item() {
}
private String value;
public Item(String value) {
this.value = value;
}
public void setValue(String value) {
this.value = value;
}
public String getValue() {
return value;
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.ajax;
import java.util.ArrayList;
import java.util.Iterator;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
/**
*
* @author DELL
*/
@ManagedBean(name = "menuManagedBean")
@SessionScoped
public class MenuManagedBean {
/** Creates a new instance of MenuManagedBean */
public MenuManagedBean() {
}
private String menuItems;
private ArrayList<String> menuId=new ArrayList<String>();
public void tabGenerate(String event){
this.menuItems=event;
getMenuId().add(event);
Iterator iterator=getMenuId().iterator();
while(iterator.hasNext()){
System.out.println("Items : " +iterator.next());
}
}
/**
* @return the menuId
*/
public ArrayList<String> getMenuId() {
return menuId;
}
/**
* @param menuId the menuId to set
*/
public void setMenuId(ArrayList<String> menuId) {
this.menuId = menuId;
}
}
/*
*要更改此模板,请选择工具|模板
*然后在编辑器中打开模板。
*/
包com.ajax;
导入java.util.ArrayList;
导入java.util.Iterator;
导入javax.faces.bean.ManagedBean;
导入javax.faces.bean.SessionScoped;
/**
*
*@作者戴尔
*/
@ManagedBean(name=“menumagedbean”)
@会议范围
公共类menumagedbean{
/**创建MenumagedBean的新实例*/
公共菜单umanagedbean(){
}
私有字符串菜单项;
private ArrayList menuId=new ArrayList();
公共无效选项卡生成(字符串事件){
this.menuItems=事件;
getMenuId().add(事件);
迭代器迭代器=getMenuId().Iterator();
while(iterator.hasNext()){
System.out.println(“Items:+iterator.next());
}
}
/**
*@returnthemenuid
*/
公共ArrayList getMenuId(){
返回menuId;
}
/**
*@param menuId要设置的menuId
*/
public void setMenuId(ArrayList menuId){
this.menuId=menuId;
}
}
请在此主题上帮助我。您在jsf页面中添加了flow命令:
<p:tabView id="outputTab" activeIndex="#{ajaxBean.count}">
更改ajaxBean.java流:
@ManagedBean(name = "ajaxBean")
@SessionScoped
public class AjaxBean implements Serializable {
public AjaxBean() {
}
private boolean input;
private List<String> chcekItem = new ArrayList<String>();
private int count;
public void setAction(String action) {
input = true;
if (getChcekItem().isEmpty()) {
count++;
getChcekItem().add(action);
System.out.println("The item " + action + " is Successfully Added to array");
} else {
for (String abce : getChcekItem()) {
if (abce.equals(action)) {
System.out.println(abce + "=" + action);
input = false;
//We can jump out of the loop here since we already found a matching value
break;
}
}
if (input) {
count++;
getChcekItem().add(action);
System.out.println("The item " + action + " is Successfully Added to array");
} else {
System.out.println("The item " + action + " is Exist");
}
}
}
private String close;
public void closeTab(TabCloseEvent closeAction) {
close = closeAction.getTab().getId();
for (String abce : getChcekItem()) {
if (abce.equals(close)) {
count--;
System.out.println(close + " is remove from Array");
getChcekItem().remove(abce);
//We can jump out of the loop here since we already found a matching value
break;
}
}
}
public String editAction() {
return null;
}
public List<String> getChcekItem() {
return chcekItem;
}
public void setChcekItem(ArrayList<String> chcekItem) {
this.chcekItem = chcekItem;
}
public boolean isInput() {
return input;
}
public void setInput(boolean input) {
this.input = input;
}
public int getCount() {
return count-1;
}
public void setCount(int count) {
this.count = count;
}
}
@ManagedBean(name=“ajaxBean”)
@会议范围
公共类AjaxBean实现了可序列化{
公共AjaxBean(){
}
私有布尔输入;
私有列表chcekItem=newarraylist();
私人整数计数;
公共void设置操作(字符串操作){
输入=真;
if(getChcekItem().isEmpty()){
计数++;
getChcekItem().add(操作);
System.out.println(“项“+action+”已成功添加到数组”);
}否则{
for(字符串abce:getChcekItem()){
if(abce.equals(action)){
系统输出打印项次(abce+“=”+动作);
输入=假;
//我们可以在这里跳出循环,因为我们已经找到了匹配的值
打破
}
}
如果(输入){
计数++;
getChcekItem().add(操作);
System.out.println(“项“+action+”已成功添加到数组”);
}否则{
System.out.println(“项“+操作+”存在”);
}
}
}
私人字符串关闭;
公共无效关闭选项卡(TabCloseEvent closeAction){
close=closeAction.getTab().getId();
for(字符串abce:getChcekItem()){
如果(近似等于(闭合)){
计数--;
System.out.println(close+“从数组中删除”);
getChcekItem().remove(abce);
//我们可以在这里跳出循环,因为我们已经找到了匹配的值
打破
}
}
}
公共字符串editAction(){
返回null;
}
公共列表getChcekItem(){
返回chcekItem;
}
公共void setChcekItem(ArrayList chcekItem){
this.chcekItem=chcekItem;
}
公共布尔值isInput(){
返回输入;
}
公共void setInput(布尔输入){
这个输入=输入;
}
public int getCount(){
返回计数-1;
}
公共无效集合计数(整数计数){
this.count=计数;
}
}