Icefaces 菜单栏处理

发布于 2024-11-04 07:09:52 字数 1640 浏览 1 评论 0原文

以下是我的主页:

<h:body styleClass="ice-skin-rime"> 
   <h:form id="form"> 
      <ice:menuBar orientation="#{menuBar.orientation}"> 
         <ice:menuItem value="HRM" id="hrm"> 
            <ice:menuItem id="myPage" value="MyPage" 
               actionListener="#{a.listener}" 
               action="#{a.param}"> 
               <f:param name="myParam" value="myPage"/> 
            </ice:menuItem> 
         </ice:menuItem> 
      </ice:menuBar> 
   </h:form> 
</h:body> 

以下是我的 bean 类

import javax.faces.component.UIComponent; 
import javax.faces.context.FacesContext; 
import javax.faces.event.ActionEvent; 
import java.util.Map; 

public class a
{ 
   private String param; 
   private String orientation = "horizontal"; 

   public String getParam() 
   { 
      return param; 
   } 

   public void setParam(String param)
   { 
      this.param = param; 
   } 

   public void listener(ActionEvent e) 
   { 
      FacesContext facesContext = FacesContext.getCurrentInstance(); 
      Map params = facesContext.getExternalContext().getRequestParameterMap(); 

      String myParam = (String) params.get("myParam"); 
      if (myParam != null && myParam.length() > 0) 
      { 
         setParam(myParam); 
      } 
      else 
      { 
         setParam("not defined"); 
      } 
   } 

   public String getOrientation() 
   { 
      return orientation; 
   }

   public void setOrientation(String orientation) 
   { 
         this.orientation = orientation; 
   } 
} 

谁能告诉我如何处理菜单项的操作事件?

Following is my home page:

<h:body styleClass="ice-skin-rime"> 
   <h:form id="form"> 
      <ice:menuBar orientation="#{menuBar.orientation}"> 
         <ice:menuItem value="HRM" id="hrm"> 
            <ice:menuItem id="myPage" value="MyPage" 
               actionListener="#{a.listener}" 
               action="#{a.param}"> 
               <f:param name="myParam" value="myPage"/> 
            </ice:menuItem> 
         </ice:menuItem> 
      </ice:menuBar> 
   </h:form> 
</h:body> 

Following is my bean class

import javax.faces.component.UIComponent; 
import javax.faces.context.FacesContext; 
import javax.faces.event.ActionEvent; 
import java.util.Map; 

public class a
{ 
   private String param; 
   private String orientation = "horizontal"; 

   public String getParam() 
   { 
      return param; 
   } 

   public void setParam(String param)
   { 
      this.param = param; 
   } 

   public void listener(ActionEvent e) 
   { 
      FacesContext facesContext = FacesContext.getCurrentInstance(); 
      Map params = facesContext.getExternalContext().getRequestParameterMap(); 

      String myParam = (String) params.get("myParam"); 
      if (myParam != null && myParam.length() > 0) 
      { 
         setParam(myParam); 
      } 
      else 
      { 
         setParam("not defined"); 
      } 
   } 

   public String getOrientation() 
   { 
      return orientation; 
   }

   public void setOrientation(String orientation) 
   { 
         this.orientation = orientation; 
   } 
} 

Can anyone please tell me how to handle action event of menu item?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

踏月而来 2024-11-11 07:09:52

首先,您似乎不清楚使用 action()actionListener() 之间的区别。当您想要返回导航规则的内容时,您需要使用 action()。当您不想返回任何内容但希望更新页面上的某些组件时,可以使用 actionListener()

从您的代码来看,您似乎不打算导航到任何其他页面,因此从ice:menuItem 组件中取出 action() 方法。

<ice:menuItem id="myPage" value="MyPage" 
               actionListener="#{a.listener}" > 
               <f:param name="myParam" value="myPage"/> 
            </ice:menuItem> 

我假设您在 faces-config.xml 中将 a 定义为托管 bean。

First of all it looks like you are not clear on the distinction between using the action() vs actionListener() . You want to use action() when you want to return something for navigation rules. You use actionListener() when you want to return nothing but wish to update certain components on your page.

From your code it looks like you are not planning on navigating to any other page so take out the action() method from your ice:menuItem component.

<ice:menuItem id="myPage" value="MyPage" 
               actionListener="#{a.listener}" > 
               <f:param name="myParam" value="myPage"/> 
            </ice:menuItem> 

I am assuming you have a defined in your faces-config.xml as a managed bean.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文