尝试构建一个简单的JSF应用程序。我不知道的是,用什么机制来触发页面重新加载。我试过了
<h:selectOneMenu
id="ChallengesListBox"
onchange="submit()"
valueChangeListener="#{bean.projectselected}">
<f:selectItems value="#{bean.projectnames}"/>
</h:selectOneMenu>
<h:commandButton value="submit" action="#{bean.submit}" />
与
public String submit() {
this.description.setRendered(true);
return null;
}
但这没有效果。 bean方法
public String submit()
保持不变,正如我在调试模式中看到的那样。
答案 0 :(得分:0)
这与导航无关。导致bean操作方法未被调用的原因有很多。你可以在这个答案中找到它们:commandButton/commandLink/ajax action/listener method not invoked or input value not updated
我暂停你只是没有<h:form>
,或者你在表单中有多个按钮(然后在submit()
上调用第一个按钮),或者按钮是单独的在处理表单提交期间没有rendered
。
无关,这种JSF 1.x风格的方法非常笨拙。由于您显然已经使用JSF 2.x,我建议使用以下更简单的方法:
<h:selectOneMenu value="#{bean.projectname}">
<f:selectItems value="#{bean.projectnames}" />
<f:ajax render="somepanel" />
</h:selectOneMenu>
<h:panelGroup id="somepanel">
<h:outputText value="#{bean.description}" rendered="#{not empty bean.projectname}" />
</h:panelGroup>
(根据下拉列表的选择,每当#{bean.description}
不为空/空时,这将呈现#{bean.projectname}
值
确保删除支持bean的所有binding
属性。每当@ViewScoped
中有输入/按钮组件时,也要确保bean为<h:panelGroup id="somepanel">
。