JSF Ajax仅被第一次调用 [英] JSF Ajax called only 1st time

查看:124
本文介绍了JSF Ajax仅被第一次调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在JSF2中,我有一个像这样的XHTML:

In JSF2 I have an XHTML like this:

<h:form id="myForm">
...
    <c:forEach items="#{myController.header}" var="hd" varStatus="count">
         #{hd}
         <h:selectOneMenu value="#{myController.type[count.index]}" id="formtype" >
                 <f:selectItem itemValue="Nop" itemLabel="Nop" />
                 <f:selectItem itemValue="Yep" itemLabel="Yep" />
                 <f:ajax render="@form" />
          </h:selectOneMenu>
          #{myController.type[count.index]}
          <h:selectBooleanCheckbox value="#myController.valid[count.index]}" id="valid">
                 <f:ajax render="@form"/>
          </h:selectBooleanCheckbox> 
          #{myController.valid[count.index]}
     </c:forEach>
...
</h:form>

我的托管bean有:

private String[] type;
private boolean[] valid;

在第一次加载命名的bean时初始化(type = new String[...];并为每个位置分配一个值).

which I initialise (type = new String[...]; and assign a value to each position) when the named bean is 1st loaded.

如果我修改组合框或复选框,有效,则在托管bean中更改了该值,并且在JSF页面中打印(呈现)了新值.但是只有第一次.接下来的更改根本不会修改任何内容.奇怪的是,因为我在其他应用程序中具有类似的代码并且运行良好,所以我做错了一些东西,但找不到它.我的模板有一个h:header,并且我在JS控制台或TomEE中看不到任何日志(我只看到.INFO - The start() method was called on component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/myApp]] after start() had already been called. The second call will be ignored,但我认为这无关).我尝试添加execute="@this"/execute="@form"和其他失败,并检查

If I modify the combo or the check box, it works, the value is changed in the managed bean and the new value gets printed (rendered) in the JSF page. But only the 1st time. Next changes do not modify anything at all. It is strange because I have similar code in other apps and works fine, so I am doing something incorrectly but cannot find it. My template has a h:header and I cannot see any logs in the JS console or in TomEE (I only see .INFO - The start() method was called on component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/myApp]] after start() had already been called. The second call will be ignored but I think it is unrelated). I have tried to add execute="@this"/execute="@form" and others unsuccessfully, and check all points of this post but nothing seems to apply to me.

我没有看到什么错误?

编辑

@Named(value = "myController")
@ViewScoped
public class MyController implements Serializable {
...

我的模板中也有一个<h:messages globalOnly="true" showDetail="true" showSummary="true" />.

推荐答案

我想我终于明白了!

感谢两件事:

  1. 中的消息中添加了一个id,然后使用<f:ajax render="@form msg".....这导致出现错误j_idt1: Validation Error: Value is required.

  1. Point 3 in BalusC answer. I added an id to my message in the template <h:messages id="msg" and then use <f:ajax render="@form msg"..... This made an error j_idt1: Validation Error: Value is required to appear.

然后我可以在这篇文章:将所需的参数从true更改为<f:viewParam required="#{!facesContext.postback}".在我的其他应用程序中,这不是必需的,因为required是"false",因为可以使用参数或不使用参数来调用它.当使用参数调用它时,它之所以起作用是因为通过巧合,页面可以在没有它的情况下被调用.

Then I could find the solution in this post: to change the required parameter from true to <f:viewParam required="#{!facesContext.postback}". This was not required in my other apps because required was "false", since it could be called with parameter or without it. When it was called with a parameter, it worked because by serendipity the page could be called without it.

这篇关于JSF Ajax仅被第一次调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆