Richfaces: a4j support (action, actionListener) for an inputText inside a dataTable
I have a JSP page in which the user must be allowed to edit data from a column and, when the form is submitted, update the respective table in database. Number of rows from this table is variable.
For the editable info field I have the following code snippet (let's name it Block A) in a JSP page:
<h:inputText value="#{myBackingBean.theFieldValue}" >
<a4j:support event="onchange" actionListener="#{myBackingBean.theActionListener}" action="#{myBackingBean.theAction}"/>
</h:inputText>
The following code snippet (let's name it Block B) is from the backing bean:
public String theAction() {
String outcome = null;
System.out.println("the action method was invoked");
return outcome;
}
public void theActionListener(ActionEvent actionEvent) {
System.out.println("the action listener method was invoked");
}
As you can see, whenever these methods are invoked that is printed to console output.
My problem is: When I put Block A inside the following block (a single inputText component in the form):
<h:form id="myForm">
(...)
here I put Block A
(...)
</h:form>
The Block B is invoked without problem. But, if instead I put the Block A inside a rich:dataTable component as I need it (multiple inputText components in the form) in order to store each row's inputText value to database (here is where I need to invoke action and/or actionListener methods):
<h:form id="myForm">
<rich:dataTable id="myDataTable" value="#{myBackingBean.myObjectList}" var="item" binding="#{myBackingBean.myObjectHtmlDataTable}" rendered="#{!empty myBackin开发者_运维知识库gBean.myObjectList}" rows="20">
(...)
<rich:column>
here I put Block A
</rich:column>
(...)
</rich:dataTable>
</h:form>
in this case, the Block B is never reached.
I'm working with JSF 1.2, and RichFaces 3.3.3, all needed beans and navigation rules are correctly configured. All needed getters and setters are in their respective classes.
Please could you give me some advice to make my code to work properly? Thanks in advance.
I test your code and it works very fine. Both the action methods can run.
It may due to other components in your form have errors when processed on the server such that the bean 's methods cannot run .
You can try to limit the server only processes the changed <h:inputText>
using <a4j:region>
.If the action methods can then be called , it could be confirmed that it is due to other components in your form.
<rich:column>
<a4j:region>
<h:inputText value="#{myBackingBean.theFieldValue}" >
<a4j:support event="onchange" actionListener="#{myBackingBean.theActionListener}" action="#{myBackingBean.theAction}"/>
</h:inputText>
</a4j:region>
</rich:column>
If your <h:form>
has the onsubmit()
event handler , please also make sure it returns true in order to submit the form.
精彩评论