0

My Ui is like attached image The problem what I am facing is On tree node selection my Backend bean is getting selected data but not updating right panel form with selected node data:
One another thing I have noticed that after node selection if I do a page refresh it's reflecting the selected node data
Details:
[1] I am working on a screen where employee and company are represented as a treeTable where company name is parent and employees are child node.

employeeList.xhtml:

<h:form id="employeeListForm">
    <p:treeTable id="empTree" widgetVar="empTree"
        value="#{employee.rootEmployeeNode}" var="item"
        selection="#{employee.selectedEmployeeNode}"
        selectionMode="single" rendered="#{employee.filteredEmployees== null}">
        <p:ajax event="select" listener="#{employee.onEmployeeNodeSelect}"
            update=":employeeEditForm">
        </p:ajax>
        <p:column headerText="#{o:translate('Name')}" priority="1">
            <h:outputText value="#{item.name}" title="#{item.name}"></h:outputText>
        </p:column>
        <p:column headerText="#{o:translate('Description')}" priority="2">
            <h:outputText value="#{item.description}" title="#{item.description}"></h:outputText>
        </p:column> 
    </p:treeTable>
<h:form>

On selection of TreeNode I am displaying the employee details in the right panel which is employeeEditForm And my employeeEditForm.xhtml is:

<ui:composition ...>    
    <h:form id="employeeEditForm">
        <!-- form components to display employee details -->                        
    </h:form>
</ui:composition>

Note: Please help me to understand how to deal with this.

  • 2
    Does this answer your question? [refresh a in jsf](https://stackoverflow.com/questions/31382067/refresh-a-uidefine-in-jsf) – Kukeltje Jun 24 '20 at 16:10
  • As per you suggestion, I given a Id to and in Ajax update using that ID . Still same issue. One aother thing I have noticed that after node selection if I do page refresh it's reflecting the selected node data –  Jun 24 '20 at 17:30
  • `ui:define` is not a jsf 'component'. `h:`'s are... did you read the duplicate? And the link in my answer/ – Kukeltje Jun 24 '20 at 17:54
  • I am a learner and I misunderstood the concept of **ui:define** and JSF components. But still, my issue is not resolved, I tried to update my employeeEditForm directly using **update=":employeeEditForm"**. Maybe I need to take some rest and think about it. –  Jun 24 '20 at 18:46
  • What you should always do is create a [mcve]. Always. See https://stackoverflow.com/questions/62523627/login-not-forwarding-correctly-with-customformauth-and-oform why... (unrelated issue but relevant to the [mcve] thing. Your form is not visible anywhere so it could be lots of things... – Kukeltje Jun 24 '20 at 18:58
  • @Kukeltje Just now I added more details let me know if Backed bean details required. –  Jun 25 '20 at 05:37
  • it is not about details, it is about [mcve]. Way to much code in there... remove superfluous buttons, try without the layout, reduce the defines/inserts/... (to none!?) reduce the includes... etc... – Kukeltje Jun 25 '20 at 06:44
  • @Kukeltje reduced to have minimal codes. From next time will ask questions with minimal code. –  Jun 25 '20 at 07:24
  • @Kukeltje I have done a temporary fix using javascript to update and I am calling this function onsuccess of **** –  Jun 25 '20 at 07:47
  • It is not about pure minimal either... it is about [mcve]... you should not apply this temporary fix... Take a step back and investigate the real problem. It most likely is not difficult, but due to the overload of code it was not easily detectable – Kukeltje Jun 25 '20 at 08:34

2 Answers2

1

You reference the name of a ui:define

<ui:define name="mainContent">
    <ui:include src="..." />
</ui:define>

in the p:ajax update attribute

<p:ajax event="select" listener="..." update=":mainContent,:employeeEditForm" />

That is not how it works (and in development mode you would most likely have gotten an error). You should update something that has an id attribute and is a jsf component (of which the ui:* ones are not

But there are other things unclear,

See also

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
-1

I have done a temporary fix using javascript, I created a function to just reload my employeeEditForm:

  <script type="text/javascript">
      function updateEmployeeEditForm() {
          $( "#employeeEditForm" ).load(window.location.href + " #employeeEditForm" ); 
    } 
</script>

And this function I am calling onsuccess like:

<p:ajax event="select" listener="#{employee.onEmployeeNodeSelect}" update=":employeeEditForm" onsuccess="updateEmployeeEditForm()">