【发布时间】:2017-04-30 12:13:42
【问题描述】:
我试图通过调用 JavaScript 中的按钮将值从表单 a 传递到 JSF 中的 bean,但由于某种原因它不起作用。请看:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<head>
<title>Dropdown List</title>
</head>
<body>
<select id="mySelect" onchange="myFunction()">
<h:outputText value="#{helloWorld.getResultSet1()}" escape="false" />
<f:attribute name="action" value="1" />
</select>
<br />
<h:form id="formId">
<h:inputHidden id="x" value="#{helloWorld.text}" />
<h:commandButton id = "x1" value="submit" action="#{helloWorld.submit}" />
</h:form>
<select id="mySelect1">
</select>
<script>
var x1 = document.getElementById("mySelect1");
x1.style.display = 'none';
function myFunction() {
var x = document.getElementById("mySelect").value;
document.getElementById("formId:x").value = x;
document.getElementById("formId").submit();
x1.style.display = 'block';
}
</script>
</body>
</html>
什么可能导致问题?也许我做错了什么?
【问题讨论】:
-
请按照您的其他问题和答案中的评论... “这真的不是在 JSF 中制作下拉菜单的方法。我建议阅读一些 JSF 初学者指南,甚至HTML 初学者指南可能会有所帮助(例如,您的代码中没有 这样的结构只会导致更多问题...
-
出于这个原因(对不起)我否决了这个问题。这种代码不应该在任何地方用作示例......它使用 jsf 的方式非常错误,并且“规避”了使 jsf 变得很棒的功能。如果其他人开始以这种方式实现,他们需要为 csrf 添加外部库,添加额外的代码以将验证消息和样式放在正确的输入上,然后在错误出现时开始“指责/反对”JSF...
标签: javascript jsf jsf-2