0

I'm working with Primefaces 5.3.

First, I implemented functionality to change visibility of a p:selectOneMenu depending on the value of a p:selectBooleanCheckbox according to this post:

Enabling and disabling components via select checkbox

This works so far, if I use the h:form.

Next, I wanted to update the values in the bean, as chosen in the p:selectOneMenu. This is where my question starts: Even if i use p:ajax to explicitly call a listener, it won't get called. This is my code:

 <h:panelGrid>
            <p:selectOneMenu value="#{schedulerCDIBean.selectedParentTask}" var="parentTask"  id="taskDependence" disabled="#{task.dependsOn != 'true'}">

                <p:ajax  event="change" listener="#{schedulerCDIBean.taskToAddListener}"/>

                <f:selectItems id="taskDependenceItems" value="#{schedulerCDIBean.taskWebDataObjectList}"   var="item" itemLabel="#{item.taskName}" 
                itemValue="#{item}"  />

               <p:column>
                   <h:outputText value="#{parentTask}"/>
               </p:column>

    </p:selectOneMenu>
</h:panelGrid>

And here is how I enable/disable the selectOneMenu:

<p:selectBooleanCheckbox id="dependsOnTask" value="#{task.dependsOn}" itemLabel="Depends On">       
        <p:ajax update="taskDependence" process="@this"/>
</p:selectBooleanCheckbox>

All this lives inside a p:tab of the p:accordionPanel where 'task' is the var of my DataObject-List.

As mentioned by @BalusC in this post: commandLink/commandButton/ajax backing bean action/listener method not invoked (Possible Causes: 2),

"You cannot nest multiple UIForm components in each other."

So, if i remove the h:form directive, the call to the listener in the bean works. But now, the value of the p:selectBooleanCheckbox is always set to 'false', and thus the component is not being updated to visible.

I found a post here, where OP had the same problem and solved it by adding the h:form directive.

EDIT: My 'form' is a ui:composition and starts like this <ui:composition template="/templates/pages/mainPage.xhtml">, where mainPage.xhtml contains h:head and includes the 'header.xhtml' by using ui:include, and there is a h:form. But this h:form is already closed before, so the problem isn't here.

Well, I don't want to go the way with adding the h:form again, as it leads to unspecified behaviour. But what am I doing wrong, if my p:selectBooleanCheckbox values are not being set correctly?

Thank you for your help!

UPDATE

The problem was not the h:form, as it actually wasn't nested. Now I'm just still stuck with the listeners for the p:selectOneMenu, as they aren't being called. I also tried setting partialSubmit="true" on the <p:ajax />, which did not lead to a solution so far.

Community
  • 1
  • 1
danny
  • 358
  • 2
  • 14
  • Do you have setter/getters on `selectedParentTask`? How does your listener method `taskToAddListener` look like? Have you tried to use a `p:remoteCommand`? – chaeschuechli Jul 18 '16 at 14:06
  • @chaeschuechli Yes, I've got the getter/setter and the listener's signature looks like this: `public void taskToAddListener(AjaxBehaviorEvent event)`. But the problem is with the p:selectBooleanCheckbox (task.dependsOn), where the value is always set to 'false'. It's not with the selectedParentTask anymore since I got rid of the h:form. I just tried the following approach with p:remoteCommand ` `, which did not work either. Thanks for your help – danny Jul 18 '16 at 14:21
  • In your tag inner selectBooleanCheckbox you have to call a listener method who updates the boolean value. – chaeschuechli Jul 18 '16 at 14:39
  • Thanks for your comment. I added a `` inside my selectBooleanCheckbox, and the called listener looks like this: `public void myListener(){ System.out.println("state is: " + editingTask.isDependsOn()); }`. The output is still always "state is: false". – danny Jul 18 '16 at 15:07
  • 1
    A completly different approach (because i faced it a few minutes ago in my project): Seems your items are of complex object type, so the missing converter could be the possible issue. I noticed, not providing a propper converter does not raise any exceptions but faces error messages. So try to add a to your page to see if any conversion error is raised. If so, add a propper converter to your selectOneMenu. – irieill Jul 19 '16 at 13:41
  • @irieill I already stumbled across the converter-thing today and now I'm about to write one. Thank you very much for this hint, I'll let you know if it works! And thanks for the idea with the ``, there actually was an error, that I wasn't able to see before. – danny Jul 19 '16 at 15:05

2 Answers2

2

Thanks for your help, guys. With your help I fixed the problem.

Just as if someone else experiences similar problems, here a few things to check:

  1. Check @BalusC's answer here, as also mentioned in @irieill's answer.
  2. Check if you're having equals() and hashCode() of the object you're willing to show in the selectOneMenu.

The solution for my situation actually was mentioned in @irieill's comment:

[..]Not providing a proper converter does not raise any exceptions but faces error messages. So try to add a <p:growl autoUpdate="true" /> to your page to see if any conversion error is raised. If so, add a propper converter to your selectOneMenu.

I think, that's also what @BalusC said at point 3 of his list of possible causes.

See also: How to write a custom converter for <p:pickList>, Custom converter in JSF 2.0, PrimeFaces ShowCase: SelectOneMenu

Community
  • 1
  • 1
danny
  • 358
  • 2
  • 14
0

As mentioned by @BalusC in this post: commandLink/commandButton/ajax backing bean action/listener method not invoked

Also note point 1. You must enclose your input components with a <h:form /> tag.

Well, I don't want to go the way with adding the h:form again, as it leads to unspecified behaviour.

As i understand, you are misusing the tag or you do not understand how to use it. Just enclose your whole page (or at least all input components) in one <h:form /> tag and it should work.

Can you please update your question with the page code also containing the lines where you placed the <h:form /> tag(s).

Community
  • 1
  • 1
irieill
  • 1,203
  • 10
  • 32