commandButton issue in JSF

丶灬走出姿态 提交于 2019-12-11 17:39:51

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!