How to invoke a method with Openfaces/JSF without rendering page?

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-05 09:28:51

问题


I am trying to invoke a Save method in a bean with Openfaces 3. While Firefox is not rendering the page, Internet Explorer does.

I'm currently using this code lines:

<o:commandLink value="Save" action="#{beanX.save}">
  <h:graphicImage url="/images/save_48.png" />
</o:commandLink>

but I was trying o:ajax as well:

<o:commandLink value="Save" action="#{beanX.save}">
  <h:graphicImage url="/images/save_48.png" />
  <o:ajax event="click" render="@none" />
</o:commandLink>

Any ideas?


I've found a way to deal with using standard JSF components. Any ideas how to solve this issue with o:commandLink?


回答1:


You can use <f:ajax> and render attribute in jsf2.0

<h:form> 
      <h:inputText value="#{managedBean.val1}" > 
         <f:ajax event="keyup" render="result" listener="#{managedBean.someThingToDoListener}"/> 
      </h:inputText> 
      <h:inputText value="#{managedBean.val2}" > 
        <f:ajax event="keyup" render="result" listener="#{managedBean.someThingToDoListener}"/> 
      </h:inputText> 

      <h:outputText id="result" value="#{managedBean.result}"/>
</h:form>

@ManagedBean(name = "managedBean") 
public class Bean { 
   private String val1; // getter and setter 
   private String val2; // getter and setter 
   private String res; // getter and setter 
   ... 

   public void someThingToDoListener(AjaxBehaviorEvent event) { 
       //res = some processing
    }

}

Also See

  • how-to-update-a-value-displayed-in-the-page-without-refreshing
  • JSF2: Ajax in JSF – using f:ajax tag



回答2:


Thank you Jigar Joshi. You've given me the key hint. It works with this code lines:

<h:commandLink value="Save">
  <h:graphicImage url="/images/save_48.png" />
  <f:ajax event="click" render="@none" listener="#{beanX.save}" />
</h:commandLink>

I've been to this website before, I was not thinking in assuming that o:commandLink might not be able to handle this, might be a bug?

Using h:commandLink instead of o:commandLink and f:ajax with the listener attribute solved my problem.



来源:https://stackoverflow.com/questions/6128065/how-to-invoke-a-method-with-openfaces-jsf-without-rendering-page

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