简体   繁体   中英

strange behaviour with jsf commandLink and f:ajax partial rendering

I have a page that displays a list of entities. On top, i have a search menu, that is hidden by default and rendered, if a flag is true . The flag is toggled by the following button:

<h:panelGroup layout="block" id="display_options" class="options">
    <h:commandLink 
        id="options_hidden"
        class="teaser_title left cursor_hand" 
        value="#{msgs.search}" action="#{magazineListBean.toggleOptions()}"
    >
        <f:ajax render="advanced_search_form"/>
    </h:commandLink>
</h:panelGroup>

this is the function in the backing bean:

public void toggleOptions() {
     if(showOptions){
          showOptions = false;
     }else{
          showOptions = true;
     }
}

The commandLink works as expected, it is however painfully slow. Apparently, the getter of the entitylist is being called several times (which is quite costly, as all of them are pulled from the database) before toggleOptions is being processed. The list is in a seperate form however. I do have a preRender() method, but it also never makes a call to the getter. Bottom line, i have NO clue what is happening here - am I missing something? Appreciate any hint, so please don't hesistate to comment. Will provide any further info needed. Thanks alot!

You've simply made a severe design mistake. You're performing business logic in a getter method. A getter method is intented to return (already-prepared) bean properties, not to perform business logic. Just don't do business logic in getter method and you're all set. Business logic should be performed in bean's @PostConstruct method, or in any action/event listener method.

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