问题
Brief intro about my requirement.
I have an empty JSF dataTable.
Now, when I click on a button, it should fill the empty datatable with data.
<h:commandButton value="Search" action="#{myBean.searchresults}" />
Problem:
When I click on the button, it populates the data to the dataTable but instantly shows me the same page when I load my application first time (refresh the page).
I want the page to not refresh itself and show the populated data.
I am stuck in this issue for the last 2 days.
Kindly provide your advice.
Thanks in advance!
Thanks, Lee
回答1:
So you want an asynchronous submit and a partial render? There the <f:ajax> tag is for.
You can specify the submit context in execute attribute and the to-be-updated client IDs in render attribute.
E.g.
<h:form>
<h:inputText value="#{bean.query}" />
<h:commandButton value="Search" action="#{bean.search}">
<f:ajax execute="@form" render=":results" />
</h:commandButton>
</h:form>
<h:panelGroup id="results">
<h:dataTable value="#{bean.results}" rendered="#{not empty bean.results}">
...
</h:dataTable>
</h:panelGroup>
with
public void search() {
results = service.find(query);
}
回答2:
do you have some navigation logic returned by searchresults ?
If not,
Make searchresults a void method
public void searchresults(){
//logic here
}
and add f:ajax to button
<h:commandButton value="Search" action="#{myBean.searchresults}" >
<f:ajax execute="@form" render="@form"/>
</h:commandButton>
来源:https://stackoverflow.com/questions/9803951/commandbutton-issue-in-jsf