< p:ajax update =" ...> PF子表中的单元格或行更新 [英] <p:ajax update="...> cell or row update inside PF subTable

查看:101
本文介绍了< p:ajax update =" ...> PF子表中的单元格或行更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在JSF方面经验不足.我很难用<p:ajax update="response2" ...仅更新子表中动态响应列的特定单元格,当我用ajax选择单选按钮时,我想在其中插入简单的响应文本.我测试了太多的可能性,但没有成功.在我的问题中,ajax组件可以更新单元格或行:没关系.通过listener调用的方法有效:似乎问题在于ajax组件的用法.在我的问题子表用于标头显示,这是必需的.我已经看过很多关于这个主题的文章,但是对我没有帮助.

I have not many experiences with JSF. I have trouble to update only the cell specific to the dynamic response column inside a subtable with <p:ajax update="response2" ... where I'd like to insert a simple response text when radio button is selected with ajax. I have tested too many possibilities but not successful. In my problem the ajax component can update the cell or the row: it does not really matter. The method called via listener works: it seems like the issue is the ajax component usage. In my problem subTable is used for header display which is required. I have seen many posts on this subject but it did not help me.

我正在将JBoss 7.1.1与PF5.2一起使用.

I am using JBoss 7.1.1 with PF5.2.

提前感谢您的时间.

<h:body>

<h:form id="form1">

<p:tabView id="tabView1" prependId="false" >

<p:tab title="TAB1"  >

<p:dataTable id="mainTable" var="head" value="#{subTableView.headers}" editable="true" editMode="cell">

    <p:subTable id="subbTable" var="question" value="#{head.questions}" >

        <f:facet name="header">
            <h:outputText value="#{head.name}" />
        </f:facet>

        <p:column>
            <h:outputLabel value="#{question.question}" />
        </p:column>

        <p:column>              
            <p:selectOneRadio id="mainSelect" value="#{question.select1}">

                <f:selectItem itemLabel="Yes" itemValue="#{question.responseOfYes}" />
                <f:selectItem itemLabel="No" itemValue="#{question.responseOfNo}" />

                <p:ajax update="response2" process=":form1:tabView1:mainTable" 

                    listener="#{questionBean.saveAnswers(question.select1,question.id)}" />

            </p:selectOneRadio>

        </p:column> 


        <p:column id="colToUpdate">
                <h:outputText id="response2" value="#{question.select1}" binding="#{input2}" />
        </p:column>

    </p:subTable>

</p:dataTable>

</p:tab>

<p:tab title="TAB2">

</p:tab>

推荐答案

Extracted from this @BalusC answer:

但是,自Mojarra 2.2.5开始支持它(它只是停止对其进行验证;因此,您将再也不会遇到问题中提到的异常;稍后将计划进行另一个增强修复).

However, since Mojarra 2.2.5 the started to support it (it simply stopped validating it; thus you would never face the in the question mentioned exception anymore; another enhancement fix is planned for that later).

这仅在当前的MyFaces 2.2.7和PrimeFaces 5.2版本中不起作用.该支持可能会在将来的版本中提供.同时,最好的选择是更新迭代组件本身,或者更新一个迭代组件,以防不呈现HTML,例如.

This only doesn't work yet in current MyFaces 2.2.7 and PrimeFaces 5.2 versions. The support might come in the future versions. In the meanwhile, your best bet is to update the iterating component itself, or a parent in case it doesn't render HTML, like .

我在Mojarra 2.2.11中成功检查了它.如果您每次用户单击一个答案都可以更新所有问题,请使用:

I checked it in Mojarra 2.2.11 with success. If you are allowed to update all the questions each time user clicks an answer then use:

<p:ajax update=":form1:maintabView:mainTable" ...

我希望它将在PF 5.3中添加!

I hope this will be added in PF 5.3!

我会澄清.您有两种选择:

I will clarify. You have two alternatives:

  1. 如果需要,请使用PF 5.2并刷新所有表,而不是仅刷新当前行字段.可以使用<p:ajax update=":form1:maintabView:mainTable" ....

使用Mojarra 2.2.5+,因此,除了使用p:dataTable和p:subTable外,还应该只使用一个手动构建迭代结构 JSF标准组件,例如h:dataTable或ui:repeat.我成功地尝试了此代码.观察到我可以引用行元素 从命令组件.页面:

Use Mojarra 2.2.5+, so instead of using p:dataTable and p:subTable you should to manually build an iterative structure using only JSF standard components such as h:dataTable or ui:repeat. I tried this code with success. Observe that I can refer to a row element from the command component. The page:

<h:form id="form">
    <ui:repeat id="list" value="#{yourBean.lista}" var="item">
        <h:outputText id="item" value="#{item}" /><br/>
    </ui:repeat>

    <p:commandButton onclick="return false;" value="Prueba" render=":form:list:1:item" action="#{yourBean.updateSecond()}"/>

     <h:commandButton value="Update second item">
         <f:ajax render=":form:list:1:item" listener="#{yourBean.updateSecond()}"/>
    </h:commandButton>
</h:form>

后备豆:

@Named
@ViewScoped
public class yourBean implements Serializable{

    private static final long serialVersionUID = 1L;

    private List<Integer> lista = new ArrayList<>(); 
    public List<Integer> getLista() {
        return lista;
    }

    public void updateSecond(){
        this.lista.set(1, 9999);
    }

    @PostConstruct
    public void populateModel(){    
        lista = Arrays.asList(1,2,3,4,5,6,7,8,9);   
    }       
}

这篇关于&lt; p:ajax update =&quot; ...&gt; PF子表中的单元格或行更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆