cell or row update inside PF subTable

前端 未结 1 1375
轮回少年
轮回少年 2021-01-26 17:15

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

相关标签:
1条回答
  • 2021-01-26 17:19

    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);   
          }       
      }
      
    0 讨论(0)
提交回复
热议问题