Skip to main content

Dynamic accodionMenu with jMaki

6 replies [Last post]
alexandergc
Offline
Joined: 2008-09-16

Hi,

I'm starting to use jmaki in my new project. In this project I'm trying to insert an accordion menu. It's quite simple, but I'm having trouble to find (not to say I have no idea) how to make this widget more dynamic.
I want to get from a database the user's access level and with this level loaded on a collection, to form my menu on the left bar.

Thanks
Alexander

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
alexandergc
Offline
Joined: 2008-09-16

SloanB,

I think it's cutting the message because it's too big. Maybe you want me to e-mail you with the project. Just let me know.

Thanks
Alexander

sloanb
Offline
Joined: 2003-09-14

Alexandergc,

Which accordian menu are you using? Be happy to help you out.

alexandergc
Offline
Joined: 2008-09-16

Hi SloanB,

I just found out that my problem is not JMaki but JSF. I followed Arun's example on this URL http://weblogs.java.net/blog/arungupta/archive/2007/08/totd_5_loading.html
It works pretty well when I use <%jsp:usebean....%> tags. But when I configured a managed bean "itemBean" that I thought it would work just as fine it brings me nothing to the combobox.


itemBean
server.ItemValueBean
session

I appreciate any help you could give me

Alexander

sloanb
Offline
Joined: 2003-09-14

Can you post the bean code so I can take a look at it for you?

alexandergc
Offline
Joined: 2008-09-16

Sure, there it is. When I use de jsp: tag it works pretty fine.

Index.jsp
Main Content Area
<%--

--%>


ItemValueBean.java
package server;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class ItemValueBean {

public ItemValueBean() {
}

public String getValue() throws JSONException{
JSONArray value = new JSONArray();

for(int i=0; i<=1; i++){
JSONObject item = new JSONObject(); //declara item como um objeto JSON
item.put("name", "name" + i);
item.put("label", "label" + i);
value.put(item); // insere o objeto item no objeto JSONArray value
}

return jsonArrayToString(value, null);
}

private String jsonArrayToString(JSONArray ja, StringBuffer buff) throws JSONException {
if(buff == null){
buff = new StringBuffer("[");
}else
buff.append("[");

for(int key = 0; key String value = null;
if (ja.optJSONObject(key) != null){
jsonToObjectLibertal(ja.optJSONObject(key), buff);
} else if (ja.optJSONArray(key) != null) {
jsonArrayToString(ja.optJSONArray(key), buff);
} else if (ja.optLong(key, -1) != -1) {
value = ja.get(key) + "";
buff.append(value);
} else if (ja.optDouble(key, -1) != -1) {
value = ja.get(key) + "";
buff.append(value);
} else if (ja.optBoolean(key)) {
value = ja.getBoolean(key) + "";
buff.append(value);
} else if (ja.opt(key) != null) {
Object obj = ja.opt(key);
if (obj instanceof Boolean) {
value = ja.getBoolean(key) + "";
} else {
value = "'" + ja.get(key) + "'";
}
buff.append(value);
}
if (key < ja.length() -1) buff.append(",");
}

buff.append("]");
return buff.toString();
}

private String jsonToObjectLibertal(JSONObject jo, StringBuffer buff) throws JSONException {
if (buff == null)
buff = new StringBuffer("{");
else
buff.append("{");

JSONArray names = jo.names();
for (int l=0; (names != null) && l < names.length(); l++) {
String key = names.getString(l);
String value = null;
if (jo.optJSONObject(key) != null) {
value = key + ":";
buff.append(value);
jsonToObjectLibertal(jo.optJSONObject(key), buff);
} else if (jo.optJSONArray(key) != null) {
value = key + ":";
buff.append(value);
jsonArrayToString(jo.optJSONArray(key), buff);
} else if (jo.optLong(key, -1) != -1) {
value = key + ":" + jo.get(key) + "";
buff.append(value);
} else if (jo.optDouble(key, -1) != -1) {
value = key + ":" + jo.get(key) + "";
buff.append(value);
} else if (jo.opt(key) != null) {
Object obj = jo.opt(key);
if (obj instanceof Boolean) {
value = key + ":" + jo.getBoolean(key) + "";
} else {
value = key + ":" + "'" + jo.get(key) + "'";
}
buff.append(value);
}
if (l < names.length() -1) buff.append(",");
}
buff.append("}");

return buff.toString();
}
}

faces-config.xml

xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">

itemBean
server.ItemValueBean
session

Message was edited by: alexandergc

lazarus___
Offline
Joined: 2008-08-26

Hi, t in a jsf
i m trying to use this widget too but i have another problem...
i want to use in a jsf project actually i have 3 managed bean with this code for the start page
[code]





[/code]
where for example the first listSetup is this
[code]
public String listSetup() {
reset(true);
return "tariffarioazione_list";
}
[/code]
in cofig file for the jsf i have this
[code]


tariffarioazione_list
/tariffarioazione/List.jsp


[/code]
the question is
Can i insert in Accordion menu the links that now i have like shown before?
and if i can how can integrate my managed bean in this widget?
i know i have already asked for help another time and i don t want to disturb asking too much helps but i don t have documentation that show how i have to use widgets with jfs. thanks to snolab i have understood the publish and subscribe mechanism well but it does not work for everything and i really don t know where i can find solutions to my problems..