Richfaces:更改组件的“渲染”方式a4j 的属性值:extendDataTable 中的支持

发布于 2024-09-28 18:45:58 字数 3150 浏览 2 评论 0原文

我尝试将 richfaces ExtendedDataTable 与 a4j:support 一起使用来更改 rich:panel 的“渲染”属性值,但它不起作用。

这是我的 JSF 页面的一部分,其中包含 rich:extendedDataTable 和 rich:panel:

<h:form id="tabForm">
<rich:extendedDataTable id="myTable" width="500px" height="250px"
value="#{extDataTableBean.extList}" var="dataRow"
selection="#{extDataTableBean.selection}" selectionMode="single">
    <rich:column>
        <f:facet name="header"><h:outputText value="ID" /></f:facet>
        <h:outputText value="#{dataRow.id}"></h:outputText>
    </rich:column>
    <rich:column>
        <f:facet name="header"><h:outputText value="Name" /></f:facet>
        <h:outputText value="#{dataRow.name}"></h:outputText>
    </rich:column>
    <a4j:support id="myTableTakeSelection" action="#{extDataTableBean.takeSelection}" event="onselectionchange" reRender="pane" />
</rich:extendedDataTable>
</h:form>
<rich:panel id="pane" rendered="#{extDataTableBean.showPane}">
<h:form id="secForm">
    <h:outputText value="ID : " />
    <h:inputText id="inTextID"  value="#{extDataTableBean.idFd}" />
    <br/>
    <h:outputText value="Name : " />
    <h:inputText id="inTextName" value="#{extDataTableBean.nameFd}" />
</h:form>
</rich:panel>

rich:panel 'rendered' 属性的默认值为 false(在支持 bean 中设置)。我想要实现的是,当选择 ExtendedDataTable 中的一行时,其值将更改为 true,以便它在 GUI 中可见。

这是我的支持 bean 的一部分:

/* Constructor */
public ExtDataTableBean(){
    setShowPane(false); // default to false
    loadDataList();
}

/* Load some test data into extendedDataTable */
public void loadDataList(){
    extList = new ArrayList<MyData>();
    MyData e1 = new MyData();
    e1.setId(1);
    e1.setName("name 1");
    extList.add(e1);
    MyData e2 = new MyData();
    e2.setId(2);
    e2.setName("name 2");
    extList.add(e2);
}

public String takeSelection(){
    Iterator iterator = getSelection().getKeys();
    Object key = null;
    while(iterator.hasNext()){
        key = iterator.next();
    }
    /* set the values of inputText with value from selected row */
    setIdFd(extList.get(Integer.parseInt(key.toString())).getId());
    setNameFd(extList.get(Integer.parseInt(key.toString())).getName());
    setShowPane(true);
    return null;
}

public List<MyData> getExtList() {
            /* Lazy loading */
    if(extList == null){
        loadDataList();
    }
    return extList;
}

在 takeSelection() 方法中,我使用 setShowPane(true) 将 rich:panel 'rendered' 属性的值更改为 true。问题很丰富:当选择一行时,面板在 GUI 中不可见。

我做了另一个简单的测试,添加 ah:commandButton 和 a4j:support 将 showPane 设置为 true,如下所示:

<h:commandButton id="cmdBtn" value="Show Pane">
    <a4j:support id="cmdBtnSupport" reRender="pane" action="#{extDataTableBean.dispPane}" event="onclick" />
</h:commandButton>

并在支持 bean: 中,

public String dispPane(){
    setShowPane(true);
    return null;
}

它按预期工作。单击按钮后,rich:panel 在 GUI 中可见。

我的代码中遗漏了什么?

I'm trying to use richfaces extendedDataTable with a4j:support to change a rich:panel's 'rendered' attribute's value but it's not working.

This is part of my JSF page that contains a rich:extendedDataTable and a rich:panel:

<h:form id="tabForm">
<rich:extendedDataTable id="myTable" width="500px" height="250px"
value="#{extDataTableBean.extList}" var="dataRow"
selection="#{extDataTableBean.selection}" selectionMode="single">
    <rich:column>
        <f:facet name="header"><h:outputText value="ID" /></f:facet>
        <h:outputText value="#{dataRow.id}"></h:outputText>
    </rich:column>
    <rich:column>
        <f:facet name="header"><h:outputText value="Name" /></f:facet>
        <h:outputText value="#{dataRow.name}"></h:outputText>
    </rich:column>
    <a4j:support id="myTableTakeSelection" action="#{extDataTableBean.takeSelection}" event="onselectionchange" reRender="pane" />
</rich:extendedDataTable>
</h:form>
<rich:panel id="pane" rendered="#{extDataTableBean.showPane}">
<h:form id="secForm">
    <h:outputText value="ID : " />
    <h:inputText id="inTextID"  value="#{extDataTableBean.idFd}" />
    <br/>
    <h:outputText value="Name : " />
    <h:inputText id="inTextName" value="#{extDataTableBean.nameFd}" />
</h:form>
</rich:panel>

The default value of rich:panel 'rendered' attribute is false (set in the backing bean). What I wanted to achieve is when a row in the extendedDataTable is selected, its value is changed to true so that it is visible in GUI.

And this is part of my backing bean:

/* Constructor */
public ExtDataTableBean(){
    setShowPane(false); // default to false
    loadDataList();
}

/* Load some test data into extendedDataTable */
public void loadDataList(){
    extList = new ArrayList<MyData>();
    MyData e1 = new MyData();
    e1.setId(1);
    e1.setName("name 1");
    extList.add(e1);
    MyData e2 = new MyData();
    e2.setId(2);
    e2.setName("name 2");
    extList.add(e2);
}

public String takeSelection(){
    Iterator iterator = getSelection().getKeys();
    Object key = null;
    while(iterator.hasNext()){
        key = iterator.next();
    }
    /* set the values of inputText with value from selected row */
    setIdFd(extList.get(Integer.parseInt(key.toString())).getId());
    setNameFd(extList.get(Integer.parseInt(key.toString())).getName());
    setShowPane(true);
    return null;
}

public List<MyData> getExtList() {
            /* Lazy loading */
    if(extList == null){
        loadDataList();
    }
    return extList;
}

In the takeSelection( ) method I have setShowPane(true) to change the value of rich:panel 'rendered' attribute to true. The problem is rich:panel is not visible in the GUI when a row is selected.

I did another simple test by adding a h:commandButton with a4j:support to set showPane to true, like this:

<h:commandButton id="cmdBtn" value="Show Pane">
    <a4j:support id="cmdBtnSupport" reRender="pane" action="#{extDataTableBean.dispPane}" event="onclick" />
</h:commandButton>

and in the backing bean:

public String dispPane(){
    setShowPane(true);
    return null;
}

and it is working as expected. rich:panel is visible in GUI after the button is clicked.

What did I miss in my code?

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

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

发布评论

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

评论(2

护你周全 2024-10-05 18:45:58

我想我从这个网站找到了问题的原因:
http://community.jboss.org/wiki/CommonAjaxRequestsProblems#conditionalRendering

摘录描述问题的部分:

客户端更新:

reRender 属性不应该指向条件渲染的元素,因为框架不知道在哪里添加之前不在 DOM 中的元素。此类组件的父级应该重新渲染。

因此,在我修改要重新渲染的部分并将其渲染绑定如下之后,它现在正在工作:

<rich:panel id="pane" >
    <h:form id="secForm" rendered="#{extDataTableBean.showPane}" >
        <h:outputText value="ID : " />
        <h:inputText id="inTextID"  value="#{extDataTableBean.idFd}" />
        <br/>
        <h:outputText value="Name : " />
        <h:inputText id="inTextName" value="#{extDataTableBean.nameFd}" />
    </h:form>
</rich:panel>

I think I found the cause of the problem from this website:
http://community.jboss.org/wiki/CommonAjaxRequestsProblems#conditionalRendering

An extract on the part that described the problem:

Client Side updates:

reRender attribute should not be pointed to conditionally rendered elements, because the framework has no idea where to add the element which wasn't in DOM before. Parents of such components should be reRendered instead.

So, after I modified the part to be rerendered and rendered binding to as follow then it is working now:

<rich:panel id="pane" >
    <h:form id="secForm" rendered="#{extDataTableBean.showPane}" >
        <h:outputText value="ID : " />
        <h:inputText id="inTextID"  value="#{extDataTableBean.idFd}" />
        <br/>
        <h:outputText value="Name : " />
        <h:inputText id="inTextName" value="#{extDataTableBean.nameFd}" />
    </h:form>
</rich:panel>
烂柯人 2024-10-05 18:45:58

开箱即用,支持 Ajax。无需添加 标记,该标记旨在为非 ajax JSF 组件带来 ajax 功能,例如

所以,试试这个:

<rich:extendedDataTable onselectionchange="#{extDataTableBean.takeSelection}">

祝你好运。

<rich:extendedDataTable> is Ajax-enabled out of the box. No need to add the <a4j:support> tag, which is intended to bring ajax functionality to non-ajax JSF components, such as <h:inputText>.

So, try this instead:

<rich:extendedDataTable onselectionchange="#{extDataTableBean.takeSelection}">

Good luck.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文