私は次のJSFビューを持っていますindex.xhtml
:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:p="http://primefaces.org/ui"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<ui:composition template="template.xhtml">
<ui:define name="top">
Menu
</ui:define>
<ui:define name="content">
<h:form>
<p:menubar>
<p:submenu label="Admin">
<p:submenu label="User">
<p:menuitem value="Add User" ajax="true">
<f:setPropertyActionListener target="#{menuTab.action}" value="StudentAdd"/>
</p:menuitem>
<p:menuitem value="Edit User" ajax="true">
<f:setPropertyActionListener target="#{menuTab.action}" value="StudentEdit"/>
</p:menuitem>
</p:submenu>
</p:submenu>
</p:menubar>
</h:form>
<p:tabView>
<c:forEach items="#{menuTab.listOfObjs}" var="item" varStatus="loop">
<p:tab title="#{menuTab.value}" closable="true"/>
</c:forEach>
</p:tabView>
</ui:define>
</ui:composition>
そして、次のマネージドBeanMenuTab.java
package com.menu;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean(name="menuTab")
@SessionScoped
public class MenuTab implements Serializable {
/** Creates a new instance of MenuTest */
public MenuTab() {
}
private String action;
private String value;
private List<String> listOfObjs = new ArrayList();
public String getAction() {
return action;
}
public void setAction(String action) {
this.action = action;
addValue(action);
}
//--------------------------------------
public void addValue(String act) {
if (listOfObjs.isEmpty()) {
setValue(act);
getListOfObjs().add(getValue());
System.out.println("First Data add First Data add First Data add::::::::::::::::" + value);
}
Iterator idvalu = listOfObjs.iterator();
while (idvalu.hasNext()) {
System.out.println("aaaaaaaaaaa=====" + idvalu.next());
value=act;
if (idvalu.next().equals(value)) {
System.out.println("Data Alrady Exite Data =====" + value);
}
else {
setValue(act);
getListOfObjs().add(getValue());
System.out.println("bbbbbbbbbbbbbbb=====" + value);
}
}
}
/**
* @return the listOfObjs
*/
public List<String> getListOfObjs() {
return listOfObjs;
}
/**
* @param listOfObjs the listOfObjs to set
*/
public void setListOfObjs(List<String> listOfObjs) {
this.listOfObjs = listOfObjs;
}
/**
* @return the value
*/
public String getValue() {
return value;
}
/**
* @param value the value to set
*/
public void setValue(String value) {
this.value = value;
}
}
[ユーザーの追加]メニューをクリックすると、Tomcatはこのマッサージを表示します。
aaaaaaaaaaa=====StudentAdd
Jun 24, 2012 3:30:04 PM com.sun.faces.lifecycle.InvokeApplicationPhase execute
WARNING: /index.xhtml @22,110 target="#{menuTab.action}": Error writing 'action' on type com.menu.MenuTab
javax.el.ELException: /index.xhtml @22,110 target="#{menuTab.action}": Error writing 'action' on type com.menu.MenuTab
at com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:139)
at com.sun.faces.facelets.tag.jsf.core.SetPropertyActionListenerHandler$SetPropertyListener.processAction(SetPropertyActionListenerHandler.java:206)