【问题标题】:Exception when using ajax event on custom selectOneRadio在自定义 selectOneRadio 上使用 ajax 事件时出现异常
【发布时间】:2014-02-25 14:26:18
【问题描述】:

我正在尝试使用带有自定义布局的 selectOneRadio,如下面的最后一个示例所示:http://www.primefaces.org/showcase/ui/selectOneRadio.jsf

<p:selectOneRadio id="customRadio" layout="custom"
                  value="#{myBB.queryType}">
    <f:selectItem itemValue="A"/>
    <f:selectItem itemValue="B"/>
    <f:selectItem itemValue="C"/>
    <p:ajax process="@this" update="queryOptions"/>
</p:selectOneRadio>
<p:panelGrid columns="3" id="queryOptions">
    <p:radioButton id="option1" for="customRadio" itemIndex="0"/>
    <p:radioButton id="option2" for="customRadio" itemIndex="1"/>
    <p:radioButton id="option3" for="customRadio" itemIndex="2"/>
    <p:inputText value="#{myBB.queryType}"/>
</p:panelGrid>

我需要自定义布局,因为queryOptions panelGrid 中还有其他组件需要根据所选单选按钮进行更新。 backingbean 中的值在点击时正确更新,但我得到了这个奇怪的异常:

java.lang.NullPointerException
at org.primefaces.component.radiobutton.RadioButtonRenderer.encodeMarkup(RadioButtonRenderer.java:48)
at org.primefaces.component.radiobutton.RadioButtonRenderer.encodeEnd(RadioButtonRenderer.java:38)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1903)
at org.primefaces.component.panelgrid.PanelGridRenderer.encodeDynamicBody(PanelGridRenderer.java:92)
at org.primefaces.component.panelgrid.PanelGridRenderer.encodeBody(PanelGridRenderer.java:60)
at org.primefaces.component.panelgrid.PanelGridRenderer.encodeEnd(PanelGridRenderer.java:49)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1903)
at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:559)
at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1729)

可能是什么原因造成的?

我正在使用 Primefaces 4.0 和 Mojarra 2.2.4

【问题讨论】:

    标签: ajax jsf primefaces


    【解决方案1】:

    我可以看到您将 p:radioButton 放入 ajax 更新 panelGrid 中。

    这样您将更新p:radioButton,而不更新customeRadio(“所有者”)。

    你可以通过两种方式解决这个问题:

    首先:更新与单选按钮相关的 p:selectOneRadio

    <p:ajax process="@this" update="queryOptions @this"/>
    

    第二:将radioButtons放在更新的容器之外。

    <p:radioButton id="option1" for="customRadio" itemIndex="0"/>
    <p:radioButton id="option2" for="customRadio" itemIndex="1"/>
    <p:radioButton id="option3" for="customRadio" itemIndex="2"/>
    <p:panelGrid columns="3" id="queryOptions">
    
    </p:panelGrid>
    

    希望这会有所帮助。

    【讨论】:

    • 谢谢。当我更新共同的父母时,我不再遇到异常。但我有另一个问题。 queryOptions 面板中的值没有更新(我已经编辑了帖子,inputText 只更改了页面刷新时的值)。有什么想法吗?
    • 当然不会更新,因为ajax的进程是@this,你可能还需要处理radioButtons...例如:&lt;p:ajax process="@this queryOptions" update="queryOptions @this"/&gt;。因为基本上radioButtons和inputtext都是在网格中渲染的,并没有被处理,所以值没有更新!
    • 嗯...这个组件让我有点困惑。谢谢!最后一个问题。当我有&lt;p:ajax process="@this queryOptions" update="queryOptions @this"/&gt; 时,更新有效,但我只能选择一次。然后我必须刷新以进行另一个选择。没有例外。也许这对您来说也很容易:)
    • 事实上这是非常奇怪的行为。正如我测试过的,在更新后如何不调用组件的脚本(以创建 PrimeFaces 小部件)。所以在这种情况下,我必须将 panelGroup 放在 selectOneRadio 和 panelGrid 周围 .. 然后在更新中我更新 panelGroup ......这样脚本将被称为“奇怪”
    • 这很奇怪。它仅在我将其包含在公共面板(queryPanel)中并像这样定义 ajax 事件时才有效:&lt;p:ajax process="queryOptions @this" update="queryPanel"/&gt;。非常感谢。我希望我能给你更多的积分:)
    猜你喜欢
    • 2017-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-21
    • 1970-01-01
    • 2021-03-06
    • 2012-10-17
    • 1970-01-01
    相关资源
    最近更新 更多