Thanks David, its still not entirely there though, we'll need to get some 
javascript code in there at some point to make the nested menus usable.  Also 
there was no support in the xsd for applying attributes (class, id, etc) to the 
nested ul element.

Regards
Scott

HotWax Media
http://www.hotwaxmedia.com
801.657.2909

----- Original Message -----
From: "David E Jones" <d...@me.com>
To: dev@ofbiz.apache.org
Cc: comm...@ofbiz.apache.org
Sent: Tuesday, June 16, 2009 6:04:12 PM (GMT+1000) Auto-Detected
Subject: Re: svn commit: r785077 - in 
/ofbiz/trunk/framework/widget/src/org/ofbiz/widget: html/HtmlMenuRenderer.java 
menu/ModelMenu.java menu/ModelMenuItem.java


Very cool Scott! I guess it's about time that this part of the  
original design was supported by the implementation... ;)

-David


On Jun 15, 2009, at 10:37 PM, lekt...@apache.org wrote:

> Author: lektran
> Date: Tue Jun 16 04:37:42 2009
> New Revision: 785077
>
> URL: http://svn.apache.org/viewvc?rev=785077&view=rev
> Log:
> Complete the partial support for nested menu items, e.g.
> <menu-item name="a" title="A">
>    <link target="aLink"></link>
>    <menu-item name="b" title="B">
>        <link target="bLink"/>
>    </menu-item>
> </menu-item>
> basically renders:
> <li>
>  <a href="aLink">A</a>
>  <ul>
>    <li>
>      <a href="bLink">B</a>
>    </li>
>  </ul>
> </li>
>
> Modified:
>    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/ 
> HtmlMenuRenderer.java
>    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ 
> ModelMenu.java
>    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ 
> ModelMenuItem.java
>
> Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/ 
> HtmlMenuRenderer.java
> URL: 
> http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlMenuRenderer.java?rev=785077&r1=785076&r2=785077&view=diff
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/ 
> HtmlMenuRenderer.java (original)
> +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/ 
> HtmlMenuRenderer.java Tue Jun 16 04:37:42 2009
> @@ -183,6 +183,24 @@
>         //if (Debug.infoOn()) Debug.logInfo("in  
> HtmlMenuRendererImage, link(0):" + link,"");
>         if (link != null) {
>             renderLink(writer, context, link);
> +        } else {
> +            String txt = menuItem.getTitle(context);
> +            StringUtil.SimpleEncoder simpleEncoder =  
> (StringUtil.SimpleEncoder) context.get("simpleEncoder");
> +            if (simpleEncoder != null) {
> +                txt = simpleEncoder.encode(txt);
> +            }
> +            writer.append(txt);
> +
> +        }
> +        if (!menuItem.getMenuItemList().isEmpty()) {
> +            appendWhitespace(writer);
> +            writer.append("    <ul>");
> +            appendWhitespace(writer);
> +            for (ModelMenuItem childMenuItem :  
> menuItem.getMenuItemList()) {
> +                childMenuItem.renderMenuItemString(writer, context,  
> this);
> +            }
> +            writer.append("    </ul>");
> +            appendWhitespace(writer);
>         }
>
>         writer.append("</li>");
>
> Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ 
> ModelMenu.java
> URL: 
> http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenu.java?rev=785077&r1=785076&r2=785077&view=diff
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ 
> ModelMenu.java (original)
> +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ 
> ModelMenu.java Tue Jun 16 04:37:42 2009
> @@ -345,60 +345,7 @@
>         // include portal pages if specified
>         //menuStringRenderer.renderFormatSimpleWrapperRows(writer,  
> context, this);
>         for (ModelMenuItem item : this.menuItemList) {
> -            String parentPortalPageId =  
> item.getParentPortalPageId(context);
> -            if (UtilValidate.isNotEmpty(parentPortalPageId)) {
> -                List <GenericValue> portalPages = null;
> -                try {
> -                    // first get public pages
> -                    EntityCondition cond =
> -                         
> EntityCondition.makeCondition(UtilMisc.toList(
> -                             
> EntityCondition.makeCondition("ownerUserLoginId",  
> EntityOperator.EQUALS, "_NA_"),
> -                             
> EntityCondition.makeCondition(UtilMisc.toList(
> -                                     
> EntityCondition.makeCondition("portalPageId", EntityOperator.EQUALS,  
> parentPortalPageId),
> -                                     
> EntityCondition.makeCondition("parentPortalPageId",  
> EntityOperator.EQUALS, parentPortalPageId)),
> -                                    EntityOperator.OR)),
> -                            EntityOperator.AND);
> -                    portalPages = delegator.findList("PortalPage",  
> cond, null, null, null, false);
> -                    if  
> (UtilValidate.isNotEmpty(context.get("userLogin"))) { // check if a  
> user is logged in
> -                        String userLoginId =  
> ((GenericValue)context.get("userLogin")).getString("userLoginId");
> -                        // replace with private pages
> -                        for (GenericValue portalPage : portalPages) {
> -                            cond =  
> EntityCondition.makeCondition(UtilMisc.toList(
> -                                     
> EntityCondition.makeCondition("ownerUserLoginId",  
> EntityOperator.EQUALS, userLoginId),
> -                                     
> EntityCondition.makeCondition("originalPortalPageId",  
> EntityOperator.EQUALS, portalPage.getString("portalPageId"))),
> -                                    EntityOperator.AND);
> -                            List <GenericValue> privatePortalPages  
> = delegator.findList("PortalPage", cond, null, null, null, false);
> -                            if  
> (UtilValidate.isNotEmpty(privatePortalPages)) {
> -                                portalPages.remove(portalPage);
> -                                 
> portalPages.add(privatePortalPages.get(0));
> -                            }
> -                        }
> -                        // add any other created private pages
> -                        cond =  
> EntityCondition.makeCondition(UtilMisc.toList(
> -                                 
> EntityCondition.makeCondition("ownerUserLoginId",  
> EntityOperator.EQUALS, userLoginId),
> -                                 
> EntityCondition.makeCondition("originalPortalPageId",  
> EntityOperator.EQUALS, null),
> -                                 
> EntityCondition.makeCondition("parentPortalPageId",  
> EntityOperator.EQUALS, parentPortalPageId)),
> -                                EntityOperator.AND);
> -                         
> portalPages.addAll(delegator.findList("PortalPage", cond, null,  
> null, null, false));
> -                    }
> -                    portalPages = EntityUtil.orderBy(portalPages,  
> UtilMisc.toList("sequenceNum"));
> -                } catch (GenericEntityException e) {
> -                    Debug.logError("Could not retrieve portalpages  
> in the menu:" + e.getMessage(), module);
> -                }
> -                for (GenericValue portalPage : portalPages) {
> -                    if  
> (UtilValidate.isNotEmpty(portalPage.getString("portalPageName"))) {
> -                        ModelMenuItem localItem = new  
> ModelMenuItem(item.getModelMenu());
> -                        localItem.name =   
> portalPage.getString("portalPageId");
> -                         
> localItem.setTitle(portalPage.getString("portalPageName"));
> -                        localItem.link = new Link(item);
> -                        localItem.link.setTarget("showPortalPage? 
> portalPageId=" + portalPage.getString("portalPageId") +  
> "&parentPortalPageId=" + parentPortalPageId);
> -                         
> localItem.link.setText(portalPage.getString("portalPageName"));
> -                        localItem.renderMenuItemString(writer,  
> context, menuStringRenderer);
> -                    }
> -                }
> -            } else {
>                 item.renderMenuItemString(writer, context,  
> menuStringRenderer);
> -            }
>         }
>         // render formatting wrapper close
>         menuStringRenderer.renderFormatSimpleWrapperClose(writer,  
> context, this);
>
> Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ 
> ModelMenuItem.java
> URL: 
> http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenuItem.java?rev=785077&r1=785076&r2=785077&view=diff
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ 
> ModelMenuItem.java (original)
> +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ 
> ModelMenuItem.java Tue Jun 16 04:37:42 2009
> @@ -31,9 +31,16 @@
> import org.ofbiz.base.util.Debug;
> import org.ofbiz.base.util.StringUtil;
> import org.ofbiz.base.util.UtilFormatOut;
> +import org.ofbiz.base.util.UtilMisc;
> import org.ofbiz.base.util.UtilValidate;
> import org.ofbiz.base.util.UtilXml;
> import org.ofbiz.base.util.string.FlexibleStringExpander;
> +import org.ofbiz.entity.GenericDelegator;
> +import org.ofbiz.entity.GenericEntityException;
> +import org.ofbiz.entity.GenericValue;
> +import org.ofbiz.entity.condition.EntityCondition;
> +import org.ofbiz.entity.condition.EntityOperator;
> +import org.ofbiz.entity.util.EntityUtil;
> import org.ofbiz.entityext.permission.EntityPermissionChecker;
> import org.ofbiz.widget.WidgetWorker;
> import org.w3c.dom.Element;
> @@ -200,6 +207,9 @@
>         }
>     }
>
> +    public List<ModelMenuItem> getMenuItemList() {
> +        return menuItemList;
> +    }
>
>     public void setHideIfSelected(String val) {
>         if (UtilValidate.isNotEmpty(val))
> @@ -248,7 +258,7 @@
>
>     public void renderMenuItemString(Appendable writer, Map<String,  
> Object> context, MenuStringRenderer menuStringRenderer) throws  
> IOException {
>
> -          boolean passed = true;
> +        boolean passed = true;
>         if (this.condition != null) {
>             if (!this.condition.eval(context)) {
>                 passed = false;
> @@ -257,7 +267,23 @@
>            //Debug.logInfo("in ModelMenu, name:" + this.getName(),  
> module);
>         if (passed) {
>             ModelMenuAction.runSubActions(this.actions, context);
> -            menuStringRenderer.renderMenuItem(writer, context, this);
> +            String parentPortalPageId =  
> this.getParentPortalPageId(context);
> +            if (UtilValidate.isNotEmpty(parentPortalPageId)) {
> +                List<GenericValue> portalPages =  
> this.getPortalPages(context);
> +                for (GenericValue portalPage : portalPages) {
> +                    if  
> (UtilValidate.isNotEmpty(portalPage.getString("portalPageName"))) {
> +                        ModelMenuItem localItem = new  
> ModelMenuItem(this.getModelMenu());
> +                        localItem.name =   
> portalPage.getString("portalPageId");
> +                         
> localItem.setTitle(portalPage.getString("portalPageName"));
> +                        localItem.link = new Link(this);
> +                        localItem.link.setTarget("showPortalPage? 
> portalPageId=" + portalPage.getString("portalPageId") +  
> "&parentPortalPageId=" + parentPortalPageId);
> +                         
> localItem.link.setText(portalPage.getString("portalPageName"));
> +                        menuStringRenderer.renderMenuItem(writer,  
> context, localItem);
> +                    }
> +                }
> +            } else {
> +                menuStringRenderer.renderMenuItem(writer, context,  
> this);
> +            }
>         }
>     }
>
> @@ -354,6 +380,51 @@
>         return this.parentPortalPageId.expandString(context);
>     }
>
> +    public List<GenericValue> getPortalPages(Map<String, Object>  
> context) {
> +        List<GenericValue> portalPages = null;
> +        String parentPortalPageId =  
> this.getParentPortalPageId(context);
> +        if (UtilValidate.isNotEmpty(parentPortalPageId)) {
> +            GenericDelegator delegator = modelMenu.getDelegator();
> +            try {
> +                // first get public pages
> +                EntityCondition cond =
> +                    EntityCondition.makeCondition(UtilMisc.toList(
> +                         
> EntityCondition.makeCondition("ownerUserLoginId",  
> EntityOperator.EQUALS, "_NA_"),
> +                         
> EntityCondition.makeCondition(UtilMisc.toList(
> +                                 
> EntityCondition.makeCondition("portalPageId", EntityOperator.EQUALS,  
> parentPortalPageId),
> +                                 
> EntityCondition.makeCondition("parentPortalPageId",  
> EntityOperator.EQUALS, parentPortalPageId)),
> +                                EntityOperator.OR)),
> +                        EntityOperator.AND);
> +                portalPages = delegator.findList("PortalPage",  
> cond, null, null, null, false);
> +                if  
> (UtilValidate.isNotEmpty(context.get("userLogin"))) { // check if a  
> user is logged in
> +                    String userLoginId =  
> ((GenericValue)context.get("userLogin")).getString("userLoginId");
> +                    // replace with private pages
> +                    for (GenericValue portalPage : portalPages) {
> +                        cond =  
> EntityCondition.makeCondition(UtilMisc.toList(
> +                                 
> EntityCondition.makeCondition("ownerUserLoginId",  
> EntityOperator.EQUALS, userLoginId),
> +                                 
> EntityCondition.makeCondition("originalPortalPageId",  
> EntityOperator.EQUALS, portalPage.getString("portalPageId"))),
> +                                EntityOperator.AND);
> +                        List <GenericValue> privatePortalPages =  
> delegator.findList("PortalPage", cond, null, null, null, false);
> +                        if  
> (UtilValidate.isNotEmpty(privatePortalPages)) {
> +                            portalPages.remove(portalPage);
> +                             
> portalPages.add(privatePortalPages.get(0));
> +                        }
> +                    }
> +                    // add any other created private pages
> +                    cond =  
> EntityCondition.makeCondition(UtilMisc.toList(
> +                             
> EntityCondition.makeCondition("ownerUserLoginId",  
> EntityOperator.EQUALS, userLoginId),
> +                             
> EntityCondition.makeCondition("originalPortalPageId",  
> EntityOperator.EQUALS, null),
> +                             
> EntityCondition.makeCondition("parentPortalPageId",  
> EntityOperator.EQUALS, parentPortalPageId)),
> +                            EntityOperator.AND);
> +                     
> portalPages.addAll(delegator.findList("PortalPage", cond, null,  
> null, null, false));
> +                }
> +                portalPages = EntityUtil.orderBy(portalPages,  
> UtilMisc.toList("sequenceNum"));
> +            } catch (GenericEntityException e) {
> +                Debug.logError("Could not retrieve portalpages in  
> the menu:" + e.getMessage(), module);
> +            }
> +        }
> +        return portalPages;
> +    }
>     public String getWidgetStyle() {
>         if (UtilValidate.isNotEmpty(this.widgetStyle)) {
>             return this.widgetStyle;
>
>

Reply via email to