Hello Jacob:

I used this component about a year and I'm not an expert in Tap related technologies so, some questions I cannot response and that I'm going to answer is based on my very little experience, the probability to find better solutions are big. Then:

jake123 escribió:
Hi,
I am building my first application using tapestry 4 and I am trying to use
the component JSCookMenu but I run into some issues.
1) When I build up my sub-menues I need 3 attributes in my directLink (Name,
ItemType, IdValue). I tried this code:

               if (currentArticle != null) {
                        BasicJSCookMenuItem currentSubMenu = new 
BasicJSCookMenuItem(new Object[]
                                {currentArticle.getName(), 
ItemType.TYPE_ARTICLE,
currentArticle.getArticleId()}); currentMenu.addItem(currentSubMenu);
                }

from this I get a org.apache.tapestry.BindingException like this:
Exception invoking listener method onNavigate of component defaultHome: No
listener method named 'onNavigate' suitable for 3 listener parameters found
in [EMAIL PROTECTED]

and the following org.apache.hivemind.ApplicationRuntimeException :
No listener method named 'onNavigate' suitable for 3 listener parameters
found in [EMAIL PROTECTED]
And my listener method look like this now:

       /**
         * This is called when one of the menu items is clicked
         */
        public void onNavigate(IRequestCycle cycle, Object[] value){
                System.out.println("HomeAction: MenuItem value = " + value[0] + " : 
" +
value[1] + " : " + value[2]);
                setDisplayedArticleId((Long) value[2]);
        }


My html page with the component look like this:
...
<body  jwcid="@Body" class="branch" >
 <span jwcid="@menu:JSCookMenu" source="ognl:menuModel"
value="ognl:menuItem" theme="SmartGreen" position="hbr">

      <!-- I had to add the 'b' in the a href posting so the text could be
displayed, so please ignore the 'b' -->
<ab href="#" jwcid="[EMAIL PROTECTED]"
listener="listener:onNavigate" parameters="ognl:menuItem.value" >
          <span jwcid="@Insert" value="ognl:menuItem.value"/>
</ab> </span>
...

This was my HTML part, using the props jar (a library), but you can get the caption from JSCookMenuItem properties

<span jwcid="@menu:JSCookMenu" source="ognl:menuModel" value="ognl:menuItem" theme="Office2003" contentRenderer="ognl:itemRenderer" position="hbr">
   <a href="#" jwcid="[EMAIL PROTECTED]"
listener="listener:onMenuAction" parameters="ognl:menuItem.value" >
     <span jwcid="[EMAIL PROTECTED]" value="prop:captionMenu" />
   </a>
 </span>


I had something like this and I resolve it as in somewhere I read, this is the .java code I use related with that component

   @InjectState("model")
   public abstract ArrayList<IJSCookMenuItem> getModel();

   /**
    * The menu model provided by the java code
    * must be an instance of Iterable<IJSCookMenuItem>
    */
   public Iterable<IJSCookMenuItem> getMenuModel(){
       return getModel();
   }

   /**
* The 'menuItem' property referenced in the bindings. It provides the actual
    * rendered item of the model
    */
   public abstract IJSCookMenuItem getMenuItem();
/**
    * construct a IMenuItemRenderer instance that is used to choose the
    * renderer component for a given item
    * In this example the items value
    * is an Array of the items name (String) and the type (ItemType)
    * See the contruction of the model in the pageBeginRender method
    */
   private IMenuItemRenderer itemRenderer = new IMenuItemRenderer(){
       public IComponent render(IJSCookMenuItem item) {
String value = ((TMenuItem)(((BasicJSCookMenuItem)item).getValue())).getCodAccion();
           if (getUser().tienePermiso(value)){
               return getValidContentRenderer();
           }
           else return null;
       }

   };

The onNavigate event is:

   public void onMenuAction(IRequestCycle cycle, Object value){
if (((TMenuItem)value).getQryEntry() != null && ((TMenuItem)value).getQryEntry() != ""){
           try{
               setMenuAction(((TMenuItem)value).getQryEntry());
               ... doing something
           }
           catch (Exception ex){
               ValidationDelegate delegate = getDelegate();
               delegate.setFormComponent(null);
               delegate.record(ex.getMessage(), null);
           }
       }
       else return;
   }

this is how I build the Menu

   protected BasicJSCookMenuItem addMenuItem(String caption, IAsset icon){
BasicJSCookMenuItem MnuConsultas = new BasicJSCookMenuItem(caption, icon);
       return MnuConsultas;
   }


   protected void RenderJSMenu(){
if(getModel().size() == 0){ BasicJSCookMenuItem mnuConsultas = new BasicJSCookMenuItem(new TMenuItem("Consultas", "7000", null));
           getModel().add(mnuConsultas);
BasicJSCookMenuItem mnuConsultasPresupuesto = new BasicJSCookMenuItem(new TMenuItem("Presupuesto", "7001", null));
               mnuConsultas.addItem(mnuConsultasPresupuesto);
BasicJSCookMenuItem mnuConsultasPresupuestoApropiacion = new BasicJSCookMenuItem(new TMenuItem("Apropiación", "7001", null)); mnuConsultasPresupuesto.addItem(mnuConsultasPresupuestoApropiacion);

... more menu items

BasicJSCookMenuItem mnuAyuda = new BasicJSCookMenuItem(new TMenuItem("Ayuda", null));
           getModel().add(mnuAyuda);
mnuAyuda.addItem(new BasicJSCookMenuItem(new TMenuItem("Temas...", null)));
               mnuAyuda.addItem(IJSCookMenuItem.MENU_SEPARATOR);
mnuAyuda.addItem(new BasicJSCookMenuItem(new TMenuItem("Acerca de...", null)));
       }
   }

   public void pageBeginRender(PageEvent arg0) {
       RenderJSMenu();
   }


... this part is very tedious and should be done more dynamically and based on some kind of configuration, but it was my first approach with the advantage that you can control which items can be visible or disabled at first instance, depending the user or some other things, but the maintability is by far less than desirable.

2) My subMenu display the address to the object instead of the menuItem
name: [LJava.lang.object;@46007 instad of ex. "Mutual Funds"
How do I solve this?

With the code above I solve it, because I don´t get the object itself but its caption (see @Insert component)

3) What is the best way of handling what content that will be displayed in
my website area 3? Do I store the ItemType and idValue as a parameter in the
.class file as private members or can I work with public abstract Long
getIdvalue()  and public void setIdValue(Long idValue)? After I set the
values... do how do I reload the page so I can read in the new article?

4) I want to display the content in area C (region). I will be able to
display two different kind of content (article, articleList) therefor I need
the ItemType, I need the idValue for accessing the right article or
articleList, and ofcourse I need the menuItem name displayed right. Is it
possible to submit my 3 attributes? It look like it is doable becouse it is
a object[] where I can add the attributes... so where is the error?

       ________________
      |                           |
      |         A                |
      -----------------------------
      |      |                    |
      |      |                    |
      |  B  |         C         |
      |      |                    |
      |      |                    |
      -----------------------------

If you work with frames, this component AFAIK cannot help you too much, because (at least until I use it) cannot redirect to another frame (but maybe was because I overlooked something and I don't remember now if I tried using an URL including the target or not) and the menu appear as if were under the next frame, so, you have to "hack" or modify the component to achieve that behavior, this was the reason why I use another solutions and after tacos.

5) What happens if javascript is turned of in the browser? I guess that
nothing will be shown where the menu would be, so my question is Are there
any backup plan to handle this case?

The menu appears but as a table with links, not as a menu, how to handle this? Well, as far as you can do into <noscript> section, but usually in that section you see messages inviting to enable javascript or update the browser.
Really thankful for your answers
Jacob

I hope that some of this information can help you some.
--



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to