0

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.

I am using JBoss 7.1.1 with PF5.2.

Thank you in advance for your time.

<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>


LEK
  • 83
  • 2
  • 11

1 Answers1

0

Extracted from this @BalusC answer:

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).

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 .

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" ...

I hope this will be added in PF 5.3!

EDIT:

I will clarify. You have two alternatives:

  1. Use PF 5.2 and refresh all the table instead of only the current row field, if your requisites allow it. This is possible using <p:ajax update=":form1:maintabView:mainTable" ....

  2. 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>
    

    The backing bean:

    @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);   
        }       
    }
    
Community
  • 1
  • 1
Javier Haro
  • 1,255
  • 9
  • 14
  • How do you implement Mojarra with JBoss? Thanks for your reply. – LEK Sep 03 '15 at 20:48
  • The process to add Mojarra 2.2.5+ to JBoss 7.1.1 server is not simple. I also had JBoss installed in my laptop and finally I chose to install Wildfly 9 wich include Mojarra 2.2.11. – Javier Haro Sep 03 '15 at 22:39
  • I have installed Wildfly9 containing Mojarra 2.2.11 as suggested but the problem persists. ` – LEK Sep 05 '15 at 11:54
  • You are welcome. If the answer helped you to resolve the issue, please accept it. To mark an answer as accepted, click on the check mark beside the answer to toggle it from hollow to green. – Javier Haro Oct 12 '15 at 20:55
  • I tried but as I've less than 15 reputation it's not accepted. – LEK Nov 09 '15 at 21:21