[jboss-user] [JBoss Seam] - Re: setActionListener(???); with iceFaces
PatrickMadden
do-not-reply at jboss.com
Thu Jan 4 00:09:15 EST 2007
Here is what I ended up doing to get it to work - right now I do get calls on the backend when I click a menu. After spelunking many forums it was mentioned that you should just use a regular managed bean and sure enough it worked for me.
Here is my backing bean:
| package com.clooster.web.ejb.session;
|
| import java.util.ArrayList;
| import java.util.List;
|
| import javax.ejb.Stateless;
| import javax.faces.component.UIViewRoot;
| import javax.faces.context.FacesContext;
| import javax.faces.el.EvaluationException;
| import javax.faces.el.MethodBinding;
| import javax.faces.el.MethodNotFoundException;
| //import javax.faces.event.AbortProcessingException;
| import javax.faces.event.ActionEvent;
| //import javax.faces.event.ActionListener;
|
| import org.hibernate.validator.Valid;
| import org.jboss.seam.annotations.In;
| import org.jboss.seam.annotations.Logger;
| import org.jboss.seam.annotations.Name;
| import org.jboss.seam.annotations.Scope;
| import org.jboss.seam.log.Log;
| import org.jboss.seam.ScopeType;
|
| import com.clooster.web.ejb.entity.ClUsers;
| import com.icesoft.faces.component.menubar.MenuItemBase;
| import com.icesoft.faces.component.menubar.MenuItem;
| //import com.icesoft.faces.component.menubar.MenuItemSeparator;
|
| //@Stateless
| //@Name("flashMenu")
| //@Scope(ScopeType.SESSION)
| //@LoggedIn
| public class FlashSearchMenuBean implements FlashSearchMenu
| {
| //@Logger
| //Log log;
|
| //@In
| //private FacesContext facesContext;
|
| //@In @Valid
| //private ClUsers user;
|
| // records which menu item fired the event
| private String actionFired;
|
| // records the param value for the menu item which fired the event
| private String param;
|
| // orientation of the menubar ("horizontal" or "vertical")
| private String orientation = "horizontal";
|
| private List<MenuItemBase> menu = null;
|
| /**
| *
| *
| */
| public FlashSearchMenuBean()
| {
| System.out.println("FlashSearchMenuBean() Constructor");
| }
|
| public void actionListener(ActionEvent e)
| {
| System.out.println("FlashSearchMenuBean action event" + e.toString());
| }
|
| //add additional action methods
|
| /**
| * Get the orientation of the menu ("horizontal" or "vertical")
| *
| * @return the orientation of the menu
| */
| public String getOrientation() {
| return orientation;
| }
|
| /**
| * Set the orientation of the menu ("horizontal" or "vertical").
| *
| * @param orientation the new orientation of the menu
| */
| public void setOrientation(String orientation) {
| this.orientation = orientation;
| }
|
| /**
| * Get the param value for the menu item which fired the event.
| *
| * @return the param value
| */
| public String getParam() {
| return param;
| }
|
| /**
| * Set the param value.
| */
| public void setParam(String param) {
| this.param = param;
| }
|
| /**
| * Get the modified ID of the fired action.
| *
| * @return the modified ID
| */
| public String getActionFired() {
| return actionFired;
| }
|
| public String switchOrientation()
| {
| if (this.getOrientation().equals("horizontal"))
| this.setOrientation("vertical");
| else
| this.setOrientation("horizontal");
|
| return "success";
| }
|
| public List<MenuItemBase> getMenuItems()
| {
| if (this.menu == null)
| {
| FacesContext context = FacesContext.getCurrentInstance();
| UIViewRoot uiViewRoot = context.getViewRoot();
|
| menu = new ArrayList<MenuItemBase>();
|
| MenuItem fileMenu = new MenuItem();
| fileMenu.setValue("File");
| fileMenu.setId(uiViewRoot.createUniqueId());
|
| MenuItem newMenu = new MenuItem();
| newMenu.setValue("New");
| newMenu.setId(uiViewRoot.createUniqueId());
|
| newMenu.setIcon("img/menu/new.gif");
| newMenu.setActionListener(this.createMethodBinding("actionListener"));
|
| MenuItem closeMenu = new MenuItem();
| closeMenu.setValue("Close");
| closeMenu.setId(uiViewRoot.createUniqueId());
| //newMenu.setIcon("/img/menu/new.gif");
| closeMenu.setActionListener(this.createMethodBinding("actionListener"));
|
| MenuItem saveMenu = new MenuItem();
| saveMenu.setValue("Save");
| saveMenu.setId(uiViewRoot.createUniqueId());
| saveMenu.setIcon("img/menu/save.gif");
| saveMenu.setActionListener(this.createMethodBinding("actionListener"));
|
| MenuItem printMenu = new MenuItem();
| printMenu.setValue("Print");
| printMenu.setId(uiViewRoot.createUniqueId());
| printMenu.setIcon("img/menu/print.gif");
| printMenu.setActionListener(this.createMethodBinding("actionListener"));
|
| fileMenu.getChildren().add(newMenu);
| fileMenu.getChildren().add(closeMenu);
| fileMenu.getChildren().add(saveMenu);
| fileMenu.getChildren().add(printMenu);
|
| MenuItem viewMenu = new MenuItem();
| viewMenu.setValue("View");
| viewMenu.setId(uiViewRoot.createUniqueId());
|
| MenuItem zoomInMenu = new MenuItem();
| zoomInMenu.setValue("Zoom In");
| zoomInMenu.setId(uiViewRoot.createUniqueId());
| zoomInMenu.setIcon("img/menu/zoomin.gif");
| zoomInMenu.setActionListener(this.createMethodBinding("actionListener"));
|
| MenuItem zoomOutMenu = new MenuItem();
| zoomOutMenu.setValue("Zoom Out");
| zoomOutMenu.setId(uiViewRoot.createUniqueId());
| zoomOutMenu.setIcon("img/menu/zoomout.gif");
| zoomOutMenu.setActionListener(this.createMethodBinding("actionListener"));
|
| MenuItem zoomActualSizeMenu = new MenuItem();
| zoomActualSizeMenu.setValue("Actual Size");
| zoomActualSizeMenu.setId(uiViewRoot.createUniqueId());
| zoomActualSizeMenu.setIcon("img/menu/actualsize.gif");
| zoomActualSizeMenu.setActionListener(this.createMethodBinding("actionListener"));
|
| MenuItem zoomFitInWindowMenu = new MenuItem();
| zoomFitInWindowMenu.setValue("Fit In Window");
| zoomFitInWindowMenu.setId(uiViewRoot.createUniqueId());
| zoomFitInWindowMenu.setIcon("img/menu/fitinwindow.gif");
| zoomFitInWindowMenu.setActionListener(this.createMethodBinding("actionListener"));
|
| viewMenu.getChildren().add(zoomInMenu);
| viewMenu.getChildren().add(zoomOutMenu);
| viewMenu.getChildren().add(zoomActualSizeMenu);
| viewMenu.getChildren().add(zoomFitInWindowMenu);
|
| menu.add(fileMenu);
| //menu.add(new MenuItemSeparator());
| menu.add(viewMenu);
| }
| return menu;
| }
|
| MethodBinding createMethodBinding(String method)
| {
| Class[] args = {ActionEvent.class};
| MethodBinding mb = FacesContext.getCurrentInstance().getApplication().createMethodBinding("#{flashMenu." + method + "}", args);
| return mb;
|
| }
| }
|
I apologize for some of the commented out code but I was just trying to get it to work.
Next is my portion of the faces-config.xml
| <managed-bean>
| <managed-bean-name>flashMenu</managed-bean-name>
| <managed-bean-class>com.clooster.web.ejb.session.FlashSearchMenuBean</managed-bean-class>
| <managed-bean-scope>session</managed-bean-scope>
| </managed-bean>
|
Hope this helps,
PVM
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3997828#3997828
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3997828
More information about the jboss-user
mailing list