gpt4 book ai didi

java - 警告 :/index. xhtml @22,110 目标 ="#{menuTab.action}": Error writing 'action' on type com. menu.MenuTab

转载 作者:行者123 更新时间:2023-12-01 05:16:12 25 4
gpt4 key购买 nike

我有以下 JSF View 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>

以及以下托管 bean MenuTab.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)

最佳答案

javax.el.ELException: /index.xhtml @22,110 target="#{menuTab.action}": Error writing 'action' on type com.menu.MenuTab

这意味着表达式#{menuTab.action}后面的setter方法抛出了异常。在堆栈跟踪中进一步查找该异常,然后根据异常中提供的信息相应地修复代码。

快速浏览一下 setAction() 代码表明最可能的原因是 NoSuchElementException,因为您正在调用 Iterator#next() 在循环内两次。每次调用 next() 时,它都会移动到下一个元素。它不会像您预期的那样返回“当前”元素。

删除以下行:

System.out.println("aaaaaaaaaaa=====" + idvalu.next());

或者至少将其分配给一个变量

String next = idvalu.next();
System.out.println("aaaaaaaaaaa=====" + next);

if (next.equals(value)) {
// ...

关于java - 警告 :/index. xhtml @22,110 目标 ="#{menuTab.action}": Error writing 'action' on type com. menu.MenuTab,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11176519/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com