【问题标题】:JSF <h:selectOneMenu> valueChangeListener does not workJSF <h:selectOneMenu> valueChangeListener 不起作用
【发布时间】:2012-07-25 16:17:36
【问题描述】:

你好,我有一个这样的jsp页面

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="f"  uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h"  uri="http://java.sun.com/jsf/html"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>title</title>
</head>
<body>
<f:view>
    <f:loadBundle basename="amdocs.gcreport.messages" var="msg" />
    <h:panelGrid columns="1">
        <h:outputLabel value="#{msg.environmens}"></h:outputLabel>
    </h:panelGrid>
    <h:panelGrid columns="1">
        <h:selectOneMenu id="selectEnv" value="#{gCAnalyzerController.envName}" onchange="submit();" valueChangeListener="#{gCAnalyzerController.envValueChange}" >
                <f:selectItems value="#{gCAnalyzerController.envs}" var="env" itemValue="#{env.name}"/>
        </h:selectOneMenu>  
    </h:panelGrid>
.
.
.

每当我更改此下拉列表框中的值时,都应在 bean 类中调用函数 envValueChange。但是,当在 IE 中运行这段代码时,出现异常“错误:预期对象”,当尝试在 google chrome 中调试时,出现以下异常。

未捕获的 ReferenceError: 未定义提交 GCAnalyzerView.jsp:15 改变

看起来 javascript submit() 没有在任何地方定义,所以页面无法加载它,谁能告诉我应该在哪里以及如何实现这个 javascript 方法?

【问题讨论】:

  • 请不要在问题中发布答案。在时间允许的情况下将其作为答案发布(并且确保不要在标题中添加“已解决”或其他内容,只需将答案标记为已接受)

标签: jsf selectonemenu valuechangelistener


【解决方案1】:

OP 的解决方案。

代码应该包含在提交的表单标签中。

<h:form>
    <h:panelGrid columns="1">
        <h:outputLabel value="#{msg.environmens}"></h:outputLabel>
    </h:panelGrid>
    <h:panelGrid columns="1">
        <h:selectOneMenu id="selectEnv" value="#{gCAnalyzerController.envName}" onchange="submit();" valueChangeListener="#{gCAnalyzerController.envValueChange}" >
                <f:selectItems value="#{gCAnalyzerController.envs}" var="env" itemValue="#{env.name}"/>
        </h:selectOneMenu>  
    </h:panelGrid>
</h:form>

【讨论】:

    猜你喜欢
    • 2012-11-20
    • 2011-12-18
    • 2011-09-16
    • 1970-01-01
    • 2013-06-06
    • 1970-01-01
    • 2014-06-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多