Author |
Message |
04/09/2008 11:23:26
|
becherer
Active
Joined: 28/11/2007 18:16:59
Messages: 20
Offline
|
hi there,
im just playin around with the Outlookbar and would like to build it up
in a dynamic way, so that i just put the bar itself in the layout and create the items and the content via Componentbinding.
maybe theres already experience to that topic out there
I started as follows :
private OUTLOOKBARComponent outlook = new OUTLOOKBARComponent(); // is mentioned as componentbinding in the Layout
public void buildMenu(){
// Setting the Items
for(int i = 0; i < 5; i++){
OUTLOOKBARITEMComponentTag olbic = new OUTLOOKBARITEMComponentTag();
olbic.setText(i);
BaseComponent bc = olbic.createBaseComponent();
outlook.getChildren().add(bc);
}
// Works fine so far
// Heres my Problem Adding the Content :
OUTLOOKBARCONTENTComponentTag olbct = new OUTLOOKBARCONTENTComponentTag();
BaseComponent bcc = olbct.createBaseComponent();
outlook.getChildren().add(bcc);
Executing this code i run into an ClassCastException - it seems as if i cannot place the Content in the ChildList of the Outlookbar...
But where should it be placed??
thnx n bye
|
|
|
04/09/2008 11:44:37
|
CaptainCasa
Power User
Joined: 21/11/2007 12:23:06
Messages: 5555
Offline
|
Hi,
to make sure: the nullpointer is on server side.
Could you append the stack trace?
Björn
|
Björn Müller, CaptainCasa GmbH |
|
|
04/09/2008 11:48:30
|
CaptainCasa
Power User
Joined: 21/11/2007 12:23:06
Messages: 5555
Offline
|
Oh sorry, I see what is wrong. You must not create the "outlook" member on your own. Please code as follows:
Code:
private OUTLOOKBARComponent outlook;
public void setOutlook(OUTLOOKBARComponent outlook)
{
if (this.outlook == outlook) return; // no change
this.outlook = outlook;
buildMenu();
}
public void buildMenu()
{
if (this.outlook == null) return; // for very special sitautions...
...
<your code>
...
}
The JSF component tree is the one creating the outlook component. You "only" get it through the setter.
Björn
|
Björn Müller, CaptainCasa GmbH |
|
|
04/09/2008 12:25:17
|
becherer
Active
Joined: 28/11/2007 18:16:59
Messages: 20
Offline
|
hi captain,
thnx - it works ;-)
i want to bind the Actionlisteners of the items also dynamically :
// Building Items
for(...){
OUTLOOKBARITEM... bla = new OUTLOOO...;
bla.setActionListener(#{"d.myAdapter.getContent");
}
// All Items call the same Function
public void getContent(ActionEvent ae){
String id = ae.getComponent.getId();
if(id == soundso){
...
}
else if(id=thisnthat){
...
}
}
is that an effective solution? i would like to avoid setting the ActionListeners as String, is there a more dynamic way?
thnx
|
|
|
04/09/2008 12:34:44
|
CaptainCasa
Power User
Joined: 21/11/2007 12:23:06
Messages: 5555
Offline
|
...no! It works, but I do not like it if the manged beans are hard wired with component ids. We strongly recommend to NOT do this... (!!!!!!)
You need to use dynamic binding concepts of expressions: use array or map binding to bind to an object that you build up on server side.
Example: the binding of an actionListener can be:
#{a.b.als[1].onSelect}
als[1] is an element of a List of "ActionListener objects", each one supporting "onSelect(ActionEvent ae)".
You can do the same with map, remember: every "." can either be a "get" by introspection or a "get" into a map.
Hops this sounds not too weird...
Björn
|
Björn Müller, CaptainCasa GmbH |
|
|
04/09/2008 13:24:05
|
becherer
Active
Joined: 28/11/2007 18:16:59
Messages: 20
Offline
|
hi,
nope, sounds good!
thnx n bye
|
|
|
|