简体   繁体   中英

f:ajax listener with arguments not working with composite component

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.

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.

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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM