我知道这听起来可能是一个基本问题,但我很难弄清楚这一点。
首先,我有这样的形式:
<h:form>
<h:inputText value="#{movies.name}"/>
<a4j:commandButton id="mybutton" value="Modify" immediate="true" action="#{movies.testModify}"/>
</h:form>
我想从电影 bean 的 testModify() 方法中捕获输入文本的值。
我的问题是 testModify 根本没有被调用。我注意到的奇怪行为是,当我删除 h:form 标记时,该方法确实被调用,但我仍然不知道如何从输入文本中获取值。
据我所知, a4j:commandButton 需要 h:form 才能正常工作。
任何帮助将不胜感激!
I know it maybe sounds a basic question but I'm having a hard time figuring this out.
First of all I have this form:
<h:form>
<h:inputText value="#{movies.name}"/>
<a4j:commandButton id="mybutton" value="Modify" immediate="true" action="#{movies.testModify}"/>
</h:form>
I want to catch the value from the input text from within my testModify() method from movies bean.
My problem is that testModify doesn't get called at all. The odd behaviour that I noticed is that when I remove h:form tag the method does get called but I still don't know how to get the value from my input text.
From what I've read, a4j:commandButton needs h:form for it to work properly.
Any help will be highly appreciated!
发布评论
评论(2)
使用
h:commandButton
而不是a4j:commandButton
。第一个是将提交表单的标准 JSF 按钮,后者执行 ajax 请求。Use an
h:commandButton
instead of ana4j:commandButton
. The first is the standard JSF button that will submit your form, the latter performs an ajax request.首先,正如 Markos Fragkakis 所说,使用基本的 而不是 ajaxified
,就像您的情况一样,您没有兴趣在此处使用 Ajax 操作。其次,删除此按钮上的
immediate="true"
属性。使用此属性意味着默认 ActionListener 应立即执行(即在请求处理生命周期的“应用请求值”阶段),而不是等到“调用应用程序”阶段。如果您对 Java bean 的操作仍未被调用,则可能在
Invoke Application
JSF 生命周期 阶段。添加
将显示可能的问题:First of all, as stated by Markos Fragkakis, use a basic
<h:commandButton>
instead of an ajaxified<a4j:commandButton>
, as in your case, you have no interest of using an Ajax action here.Second, remove the
immediate="true"
attribute on this button. Using this attribute means that the default ActionListener should be executed immediately (i.e. duringApply Request Values
phase of the request processing lifecycle), rather than waiting until theInvoke Application
phase.If your action on Java bean is still not called, maybe something wrong happend before the
Invoke Application
JSF lifecycle phase. Adding a<h:messages>
will display the possible issues: