2011-10-19 182 views
0

为什么#{uImanager.select}从未更新?Ajax更新不起作用

<p:panel id="EditDetailsPanel" header="Edit Details"> 
    <h:panelGrid columns="2" cellpadding="5"> 
     <h:outputLabel value="Simple :" /> 
     <h:selectOneMenu value="#{uImanager.select}"> 
      <f:selectItem itemValue="val1" itemLabel="Coffee1" /> 
      <f:selectItem itemValue="val2" itemLabel="Coffee2" /> 
      <f:selectItem itemValue="val3" itemLabel="Coffee3" />         
     </h:selectOneMenu> 
    </h:panelGrid> 
    <p:commandButton value="Submit" update="EditDetailsForm:EditDetailsPanel"/> 
    #{uImanager.select} 
</p:panel> 

它指向一个private String Select;与一个getter和setter。它在会话范围的托管bean中定义。

回答

1

因为你update属性可能指向无效的客户端ID。如果你注意的服务器日志,那么你应该已经看到像下面这样从PrimeFaces:

INFO: Cannot find component with identifier "EditDetailsForm:EditDetailsPanel" in view. 

由于<p:panel>相同UINamingContainer父为<p:commandButton>本身(至少,根据里面的代码,其到目前为止,你已经张贴),你可以指定其相对客户端ID:或者,如果您在指定的绝对委托人身份证坚持,那么你需要用:前缀它

<p:commandButton value="Submit" update="EditDetailsPanel"/> 

<p:commandButton value="Submit" update=":EditDetailsForm:EditDetailsPanel"/> 

请注意,这只是工作,如果该<h:form>确实本身没有其他UINamingContainer父。在浏览器中打开该页面,单击右键,然后选择查看源文件来计算生成的HTML元素ID。最后你需要拿这个值,前面加上:

+0

这不是problem.this代码与ID =“EditDetailsForm” –

+0

这不应该的问题的形式。相对客户端ID被解析为当前的'UINamingContainer'父项。如果你真的坚持指定冗长和绝对的客户端ID,那么你需要用':'作为前缀。但我不明白这有什么用处。只需使用我在答案中提到的值即可。 – BalusC

+0

我更新了答案,以更好地解释这个问题。 – BalusC