1

When i try to pass a f:ajax inside my composite component all my listener parameters are resolved to null.

<c:forEach var="paragraph" items="#{Chapiter.paragraphList}"> 
  <c:forEach var="field" items="#{paragraph.fieldList}"> 
    <util:inputNumber type="double" value="#{field.value}" decimal="2"> 
        <f:ajax listener="#{myean.doSomething(field, paragraph)}"> 
        </f:ajax>
    </util:inputNumber>
  </c:forEach> 
</c:forEach>

of course i had added a client behavior to my composite component like this

the listener method is invoked on blur event but my arguments "field" and "paragraph" have always null value.

I think that the variables are not accessible from the composite component.

I have tried to pass the both variables to the composite component via a composite attribute but i dont thik that it is a clean solution.

is there a right way to do this?

Thanks for your attention.

Yassir
  • 23
  • 6

2 Answers2

0

If you want to pass arguments as strings you need to write it like this:

<f:ajax listener="#{myean.doSomething('arg1', 'arg2')}">

Otherwise it will expect arg1 and arg2 to be defined variables. I assume that you have your function defined as accepting 2 Strings as parameters.

Also- are you sure that your listener executes? How are you trying to get these values. Please share the code.

bjedrzejewski
  • 2,378
  • 2
  • 25
  • 46
  • Hello jedrus07, thank you for your answer My arguments are not string but complex objects. and their values cannot be hardly coded. I run my app in debug mode and i am sure that my listener executes but it always get an NullPointerException. when i check my arguments values they are always resolved as null. I think the problem is that the two variables arg1 and arg2 are not reachable from the composite component. I am wondering if there is a way to pass them as parameter to the composite components without creating new composite-attributes. – Yassir Mar 11 '13 at 09:51
  • i have resolved this issue by creating a HashMap composite attribute which will contain all my parameters `` that i way i have always to build a hashMap containing both arguments arg1 and arg2. ` ` I am not sure that this is the clean way to do it. Can you please tell me if there is another solution – Yassir Mar 11 '13 at 10:00
  • If arg1 and arg2 are not accessible already, then you need to create them and this make your solution the only way to go (as far as I know). How did you originaly obtain arg1 and arg2 (if at all?) – bjedrzejewski Mar 11 '13 at 11:02
  • Following a sample code: ` ` My argument actually are field and paragraph and i need to use them while invoking my listener. – Yassir Mar 11 '13 at 11:42
  • c:forEach causes a lot of headache to people. I suggest to google problems with it and think about building it without using the c:forEach (if possible). Could you also add all this information to your question? You will have much greater chance of a good answer by doing that and then we can delete these comments. – bjedrzejewski Mar 11 '13 at 13:16
0

The <c:forEach> runs during view build time and therefore the paragraph and field variables are only available during view build time. They are not available during component tree visit nor during view render time. The ajax action listener method is determined during a JSF component tree visit, not during view build time and hence the parameters will always resolve null.

If you replace <c:forEach> by <ui:repeat> (and ensure that you're using the newest Mojarra version wherein all peculiar <ui:repeat> issues are been resolved), and put the bean in the view scope while keeping the getters free of business logic, then it should work fine.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thank you. i just tested your solution. At first my listener was not firing but after updating Mojarra version to the latest one it works perfectly. – Yassir Mar 22 '13 at 11:17