从单选按钮更新复选框

发布于 2025-01-03 14:13:03 字数 1926 浏览 1 评论 0原文

我正在尝试使用以下代码将 ajax 行为添加到 selectoneradio:

xhtml:

<h:selectOneRadio id="metalA" converter="metalConverter" value="#{backingBean.metal.metalCode">
    <f:selectItems value="#{backingBean.metalCodeRadio}" />
    <f:ajax listener="#{backingBean.updateMenu}" event="click" execute="metalA" render="metalTypeMenuA"/>
</h:selectOneRadio>

<p:outputPanel id="panelA">
    <h:selectOneMenu id="metalTypeMenuA" converter="metalConverter" value="#{backingBean.order.metal}" rendered="#{teklifIslemleriBean.selectedITip == 1}">
            <f:selectItems value="#{backingBean.metalDetailsMenu}" />
        </h:selectOneMenu>
</p:outputPanel>

backing bean:

MetalCode selectedMK = null;

public void updateMenu(AjaxBehaviorEvent event) {            

        System.out.println("Entered to updateMenu method");

        if (metal.getMetalKod()!= null) {
            electedMK = aMetal.getMetalCode();            
        }        

        if (selectedMK != null) {
            // metalTypeMenuA Combobox
            List<Metal> metalList = aService.getAccToMetalCode(null, selectedMK);
            System.out.println("MetalList:" + metalList.size());
            metalTypeMenuA.clear();
            for (Metal m : metalList) {
                metalTypeMenuA.add(new SelectItem(m, "No:" + m.getMetalNo() +  " ,Weight: " + m.getWeight();
            }
        }
    }

但是它甚至没有进入 updateMenu 方法。我尝试选择、更改等而不是单击。我还尝试放置一个包装面板并更新它而不是复选框,但仍然不好。上面的代码有什么问题?是否可以通过更改单选按钮来更新复选框?提前致谢。

JSF 2.0 Primefaces 2.2.1

编辑: 我添加了以下

<h:message for="metalA" id="messaged"/>

<f:ajax listener="#{backingBean.updateMenu}" event="click" execute="metalKoduA" execute="metalA" render="messaged orderPG2"/> 

orderPG2 是复选框的包装器。但我仍然可以在 h:message 中收到任何错误消息或发生任何 ajax 行为。

I am trying to add ajax behavior to selectoneradio with this code:

xhtml:

<h:selectOneRadio id="metalA" converter="metalConverter" value="#{backingBean.metal.metalCode">
    <f:selectItems value="#{backingBean.metalCodeRadio}" />
    <f:ajax listener="#{backingBean.updateMenu}" event="click" execute="metalA" render="metalTypeMenuA"/>
</h:selectOneRadio>

<p:outputPanel id="panelA">
    <h:selectOneMenu id="metalTypeMenuA" converter="metalConverter" value="#{backingBean.order.metal}" rendered="#{teklifIslemleriBean.selectedITip == 1}">
            <f:selectItems value="#{backingBean.metalDetailsMenu}" />
        </h:selectOneMenu>
</p:outputPanel>

backing bean:

MetalCode selectedMK = null;

public void updateMenu(AjaxBehaviorEvent event) {            

        System.out.println("Entered to updateMenu method");

        if (metal.getMetalKod()!= null) {
            electedMK = aMetal.getMetalCode();            
        }        

        if (selectedMK != null) {
            // metalTypeMenuA Combobox
            List<Metal> metalList = aService.getAccToMetalCode(null, selectedMK);
            System.out.println("MetalList:" + metalList.size());
            metalTypeMenuA.clear();
            for (Metal m : metalList) {
                metalTypeMenuA.add(new SelectItem(m, "No:" + m.getMetalNo() +  " ,Weight: " + m.getWeight();
            }
        }
    }

However it does not even enter to the updateMenu method. instead of click I tried select, change, etc. I also tried to put a wrapper panel and update it instead of checkbox, still no good. What is wrong with above code? Is updating a checkbox with a change in radiobutton doable? Thanks in advance.

JSF 2.0 Primefaces 2.2.1

EDIT:
I added following

<h:message for="metalA" id="messaged"/>

<f:ajax listener="#{backingBean.updateMenu}" event="click" execute="metalKoduA" execute="metalA" render="messaged orderPG2"/> 

orderPG2 is a wrapper around checkbox. But still I can get any error message in h:message or any ajax behavior is happening.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

离线来电— 2025-01-10 14:13:03

render 属性不应该指向由 有条件地在服务器端渲染的组件呈现 属性。让它指向总是渲染的最近的父级。

<f:ajax listener="#{backingBean.updateMenu}" render="panelA" />

(请注意,我删除了 event="click"execute="metalA",因为它们已经是默认值)

如果仍然不行工作,那么您需要阅读服务器日志以查找任何丢失的面孔消息。重大变化,您将看到 验证错误:“值无效“ 或者可能是转换错误。为了防止在 ajax 渲染期间丢失这些消息,请确保您以正确的方式使用 和/或 您还将它们包含在 render 中。

<h:selectOneRadio id="metalA" ...>
    ...
    <f:ajax ... render="metalAmessage panelA" />
</h:selectOneRadio>
<h:message id="metalAmessage" for="metalA" />

The render attribute of <f:ajax> should not point to a component which is by itself conditionally server-side rendered by rendered attribtue. Let it point to the closest parent which is always rendered instead.

<f:ajax listener="#{backingBean.updateMenu}" render="panelA" />

(note that I removed event="click" and execute="metalA" as those are the defaults already)

If that still doesn't work, then you'd need to read the server logs for any missing faces messages. Big change that you'll see a Validation Error: "Value is not valid" or perhaps a conversion error. To prevent those messages from being missed during ajax rendering, ensure that you're using <h:message> and/or <h:messages> the right way and that you also include them in the render of the <f:ajax>.

<h:selectOneRadio id="metalA" ...>
    ...
    <f:ajax ... render="metalAmessage panelA" />
</h:selectOneRadio>
<h:message id="metalAmessage" for="metalA" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文