将 JSF bean 绑定到包含的 JSF
我对这个已经束手无策了。我是 JSF 的新手,所以这可能是我对很多东西的误解。
<ui:composition>
<f:view>
<tr:form>
<ui:fragment rendered="#{param['type'] eq 'myType'}">
<ui:include src="/home/myPage.jspx" />
</ui:fragment>
......
我向页面传递某种类型,它显示表单的某些字段/标准,并且 bean 支持这一切,因为只有一次搜索。
在 myPage.jspx 中,我有:
action="#{MyBean.submitForm}"
不起作用,尽管 onsubmit="alert('hi');"确实作为表单元素的属性。
我想最令人困惑的是它
valueChangeListener="#{MyBean.stateChanged}"
在 myPage.jspx 中的字段上起作用
为什么该操作(按钮的属性)不起作用?
I'm at the end of my rope with this one. I'm new to JSF so this is probably my misunderstanding of a lot of stuff.
<ui:composition>
<f:view>
<tr:form>
<ui:fragment rendered="#{param['type'] eq 'myType'}">
<ui:include src="/home/myPage.jspx" />
</ui:fragment>
......
I pass the page a certain type, it display's certain fields/criteria for a form and a bean backs it all because there is a single search.
Within myPage.jspx I have:
action="#{MyBean.submitForm}"
does not work, although a onsubmit="alert('hi');" does work as an attribute of the form element.
I guess what's most confusing is that
valueChangeListener="#{MyBean.stateChanged}"
does work on a field in the myPage.jspx
Why does the action (attribute of a button) not work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在处理表单提交期间,如果按钮或其父组件之一未
渲染
,则不会调用按钮的操作。您需要确保在处理表单提交期间rendered
属性的计算结果与显示表单时的计算结果相同。在您的情况下,您取决于名称为type
的请求参数的值。在这种特殊情况下,您可以通过嵌套在命令按钮中的
保留请求参数type
来解决问题:或者,如果您使用JSF 2.0,将bean放置在视图范围中并通过
在托管bean中设置type
参数也可以解决这个问题。另请参阅:
During processing of the form submit, if the button or one of its parent components is not
rendered
, then the button's action won't be invoked. You need to make sure that therendered
attribute evaluates the same during processing of the form submit as it did when the form was displayed. In your case, you're depending on the value of a request parameter with the nametype
.In this particular case, you could solve the problem by retaining the request parameter
type
by a<f:param>
nested in the command button:Or, if you're using JSF 2.0, placing the bean in the view scope and setting the
type
parameter in the managed bean by<f:viewParam>
can also solve it.See also: