通过选择复选框启用和禁用组件

发布于 2024-11-25 12:02:55 字数 632 浏览 3 评论 0原文

我有组件,我正在尝试禁用下面的 panelGrid。

<h:selectBooleanCheckbox id="checkboxId" value="#{bean.checked}">
    <p:ajax update="panelId" event="click"/>                                    
</h:selectBooleanCheckbox>
<h:panelGrid id="panelId" rendered="#{!bean.checked}">
    <h:outputLabel>some text</h:outputLabel>
    <h:outputLabel>#registrationBB.registrationModel.homeAddress.actualAddressMathWithRegistration}</h:outputLabel>
</h:panelGrid>

因此,单击复选框不会产生任何效果。检查指示器甚至不会出现在复选框组件上,并且值 bean:checked 不会发送到服务器。 我也尝试使用。检查指示器出现,但面板未刷新

如何通过复选框使用更新?

I have component and I'm trying disable panelGrid below.

<h:selectBooleanCheckbox id="checkboxId" value="#{bean.checked}">
    <p:ajax update="panelId" event="click"/>                                    
</h:selectBooleanCheckbox>
<h:panelGrid id="panelId" rendered="#{!bean.checked}">
    <h:outputLabel>some text</h:outputLabel>
    <h:outputLabel>#registrationBB.registrationModel.homeAddress.actualAddressMathWithRegistration}</h:outputLabel>
</h:panelGrid>

As a result the clicking on checkbox doesn't take no effect. The check indicator doesn't even appear on checkbox component and value bean:checked doesn't sent to the server.
I tried to use also. Check indicator appeared but the panel is not refreshed

How to use update via checkbox right?

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

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

发布评论

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

评论(2

听你说爱我 2024-12-02 12:02:55

下面的示例是我要工作的内容:

<h:form>
    <h:selectBooleanCheckbox id="checkboxId" value="#{indexBean.checked}" >
        <p:ajax event="change" update="panelId" />
    </h:selectBooleanCheckbox>

    <h:panelGrid id="panelId" style="border:solid 1px black;" >
        <h:outputLabel rendered="#{!indexBean.checked}" >some text</h:outputLabel>
        <h:outputText rendered="#{!indexBean.checked}" value="some text 2" />
    </h:panelGrid>
</h:form>

我必须将 事件从 click 更改为 Change 才能使复选框正常工作。另一个问题是,如果您不渲染 ,则无法找到要更新的 id,因此您希望将渲染的属性移动到 < 内的组件;h:panelGrid> 但仍更新

The example below is what I got to work:

<h:form>
    <h:selectBooleanCheckbox id="checkboxId" value="#{indexBean.checked}" >
        <p:ajax event="change" update="panelId" />
    </h:selectBooleanCheckbox>

    <h:panelGrid id="panelId" style="border:solid 1px black;" >
        <h:outputLabel rendered="#{!indexBean.checked}" >some text</h:outputLabel>
        <h:outputText rendered="#{!indexBean.checked}" value="some text 2" />
    </h:panelGrid>
</h:form>

I had to change the <p:ajax> event from click to change to get the checkbox working. The other issue is if you don't render the <h:panelGrid> the id can not be found to update, so you want to move the rendered attribute to the components inside your <h:panelGrid> but still update the <h:panelGrid>.

谎言月老 2024-12-02 12:02:55

略有变化。您的支持 bean 字段不必是布尔值。如果你有一个带有 fields: 的支持 bean,

private List<SelectItem> myStringList;
private String myString;

那么你可以在表单加载之前像这样初始化 myStringList:

myStringList = Arrays.asList(new SelectItem("one", "The Number One"),
                new SelectItem("two", "The number two")
        );

那么你可以这样做:

<h:form>
    <p:selectOneRadio id="ctlSearchType" value="#{mybean.myString}"  layout="grid" columns="3">
       <f:selectItems value="#{mybean.myStringList}" />
       <p:ajax event="change" update="ctlone,ctltwo"/>
    </p:selectOneRadio>

    <h:panelGrid id="panelId" style="border:solid 1px black;" >
       <p:outputLabel for="ctlone" value="Field one:"/>
       <p:inputText value="#{mybean.whatever}" id="ctlone" size="8" maxlength="10" disabled="#{mybean.myString eq 'one'}"/>
       <p:outputLabel for="ctltwo" value="Field two:"/>
       <p:inputText value="#{mybean.whatevertwo}" id="ctltwo" size="8" maxlength="10" disabled="#{mybean.myString eq 'two'}"/>                         
    </h:panelGrid>
</h:form>

A slight variation. Your backing bean field doesn't have to be a boolean. If you had a backing bean with fields:

private List<SelectItem> myStringList;
private String myString;

then you initialize myStringList like this before the form load:

myStringList = Arrays.asList(new SelectItem("one", "The Number One"),
                new SelectItem("two", "The number two")
        );

then you could do this:

<h:form>
    <p:selectOneRadio id="ctlSearchType" value="#{mybean.myString}"  layout="grid" columns="3">
       <f:selectItems value="#{mybean.myStringList}" />
       <p:ajax event="change" update="ctlone,ctltwo"/>
    </p:selectOneRadio>

    <h:panelGrid id="panelId" style="border:solid 1px black;" >
       <p:outputLabel for="ctlone" value="Field one:"/>
       <p:inputText value="#{mybean.whatever}" id="ctlone" size="8" maxlength="10" disabled="#{mybean.myString eq 'one'}"/>
       <p:outputLabel for="ctltwo" value="Field two:"/>
       <p:inputText value="#{mybean.whatevertwo}" id="ctltwo" size="8" maxlength="10" disabled="#{mybean.myString eq 'two'}"/>                         
    </h:panelGrid>
</h:form>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文