JSF: creating datatable based on user input text and gathering info from a perticular row selected by radio button

822 Views Asked by At

I have a page where I ask the user to input a value into a inputText box. Based on the entered value I create a datetable with information from my database. One of the columns in the datatable is a selectOneRadio therefore each row has its own radio button. The user should then be able to select one of the radio buttons and then click a commandbutton (which is the footer of the datatable) that will obtain which row is selected based on which radio button is selected. The problem that I am having is upon the button click the backing bean method isn't being called. This issue only happens when i create the table after going to the page. if i hard code a value to cause the datatable to exist at the creation of the page this problem does not happen. I'm not completely sure but I believe this problem is happening because the datatable rendered is initially set to false and for some reason this is effecting either the binding or the valueChangeListener some how.

This is the jsf

<h:panelGrid columns="3">
   <h:outputLabel for="searchByContrId" value="Company Code: " />
   <h:inputText id="searchByContrId" value="#{applContAdminB.searchContrId}">
   </h:inputText>
   <h:commandButton type="submit" value="Search" id="submitSearch" action="#{applContAdminB.getEmployeesByContrId}" />
</h:panelGrid>
<br />
<h:outputText rendered="#{applContAdminB.contrIdEntered}" value="Current Administrator: " />
<h:outputText value="#{applContAdminB.adminName}" />
<h:dataTable id="empTable" var="loc" rendered="#{applContAdminB.contrIdEntered}" value="#{applContAdminB.employeesListModel}" binding="#{applContAdminB.htmlDataTable}">
    <h:column>
       <h:selectOneRadio onclick="updateRadioButtons(this);" valueChangeListener="#{applContAdminB.setSelectedRow}">
          <f:selectItem itemValue="null" itemLabel="" />
       </h:selectOneRadio>
    </h:column>
    <h:column>
       <f:facet name="header">Employee Name</f:facet>
       <h:outputText value="#{loc.empName}" />
    </h:column>
    <h:column>
       <f:facet name="header">Employee Email</f:facet>
       <h:outputText value="#{loc.empEmail}" />
    </h:column>
    <h:column>
       <f:facet name="header">Status</f:facet>
       <h:outputText value="#{loc.userStatus}" />
    </h:column>
    <f:facet name="footer">
       <h:panelGrid columns="2">
          <h:commandButton type="submit" id="transferRights-submit" value="Transfer Rights" action="#{applContAdminB.adjustAdminUser}" />
       </h:panelGrid>
    </facet>
 </h:dataTable>
1

There are 1 best solutions below

0
On BEST ANSWER

you answered your own question. this is a weakness in using rendered with ajax. i had a similar issue with a navigation widget i had that toggled the attribute that rendered was bound to via ajax. no manner of magic i could muster would get the invisible panel to render while hiding the panel that was initially rendered. you might try just hiding the div via javascript and when your ajax returns twiddle the "display" attribute of the div(s) accordingly. that's how i solved it. it's unfortunate, but i could not find an alternate solution that was desirable. – him