You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Java Programmer <jp...@gmail.com> on 2008/02/12 15:10:59 UTC

panel doesn't see page which it create?

Hello,
I have Panel on which in constructor I put nested Panel:
public class RegisterUserPanel extends Panel {

public RegisterUserPanel(String id) {
...
final Panel addLocationPanel = new AddLocationPanel("addLocationPanel");
addLocationPanel.add(new SimpleAttributeModifier("style", "display:none;"));
add(addLocationPanel);
add(new CheckBox("openLocationPanelLink").add(new
SimpleAttributeModifier("onclick", "var
panel=document.getElementById('" + addLocationPanel.getMarkupId() +
"');panel.style.display=this.checked?'block':'none';")));
..
}

It's as you see another panel, and the exception is thrown:
WicketMessage: This component is not (yet) coupled to a page. It has
to be able to find the page it is supposed to operate in before you
can call this method (Component#getMarkupId)

It means for me that addLocationPanel.getMarkupId() is not setup yet
(it could be quite obvious, because it's constructor and I haven't
send any info about page to it, and probably it's send after creating
instance). But what can i do in such situation? What is best pattern?

Best regards,
Adr

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: panel doesn't see page which it create?

Posted by Michael O'Cleirigh <mi...@rivulet.ca>.
Hi Adr,

The markupid of any component is only assigned when the containing 
component is actually added into the page.

The way around this is that the AttributeModifier (and most other 
behaviours I believe) class actually renders the "onclick" event during 
the onComponentTag(..) method of the panel being rendered at which point 
the markup id's are set.

You can just wrap the javascript in a model that will generate the 
correct text string when getObject() is called.

My helper class for this case takes in a string and replaces a 
placeholder with the desired markupid when the getObject() method of 
IModel is called.

e.g. panel.add (new AttributeModifier ("onClick", new 
MarkupIDInStringModel ("var panel=document.getElementById('" + 
MarkupIDInStringModel.MARKUP_ID_PLACEHOLDER + 
"');panel.style.display=this.checked?'block':'none';", addLocationPanel));

so when the onComponentTag method is called the model inserts 
addLocationPanel.getMarkupID() into the placeholder value.

Regards,

Mike
> I have moved my objects in Pnale to fields eg.:
> public class RegisterUserPanel extends Panel {
> 	
> 	final CheckBox openClosePanelCheckBox;
> 	
> 	final Panel addLocationPanel;
> ...
> }
> and from Page I setup attributes:
> RegisterUserPanel registerUserPanel = new
> RegisterUserPanel("register_user_panel");
> 		add(registerUserPanel);
> 		registerUserPanel.openClosePanelCheckBox.add(new
> SimpleAttributeModifier("onclick", "var
> panel=document.getElementById('" +
> registerUserPanel.addLocationPanel.getMarkupId() +
> "');panel.style.display=this.checked?'block':'none';"));
>
> But is this good way to follow? Any other pattern to use?
>
> best regards,
> Adr
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: panel doesn't see page which it create?

Posted by Java Programmer <jp...@gmail.com>.
I have moved my objects in Pnale to fields eg.:
public class RegisterUserPanel extends Panel {
	
	final CheckBox openClosePanelCheckBox;
	
	final Panel addLocationPanel;
...
}
and from Page I setup attributes:
RegisterUserPanel registerUserPanel = new
RegisterUserPanel("register_user_panel");
		add(registerUserPanel);
		registerUserPanel.openClosePanelCheckBox.add(new
SimpleAttributeModifier("onclick", "var
panel=document.getElementById('" +
registerUserPanel.addLocationPanel.getMarkupId() +
"');panel.style.display=this.checked?'block':'none';"));

But is this good way to follow? Any other pattern to use?

best regards,
Adr

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: panel doesn't see page which it create?

Posted by Igor Vaynberg <ig...@gmail.com>.
add(new CheckBox("openLocationPanelLink") {
  oncomponenttag(tag) {
tag.put("onclick", "var panel=document.getElementById('" +
addLocationPanel.getMarkupId() +
 "');panel.style.display=this.checked?'block':'none';")));
}

that way your code will execute during render time at which markupid
is available.

-igor


On Feb 12, 2008 6:10 AM, Java Programmer <jp...@gmail.com> wrote:
> Hello,
> I have Panel on which in constructor I put nested Panel:
> public class RegisterUserPanel extends Panel {
>
> public RegisterUserPanel(String id) {
> ...
> final Panel addLocationPanel = new AddLocationPanel("addLocationPanel");
> addLocationPanel.add(new SimpleAttributeModifier("style", "display:none;"));
> add(addLocationPanel);
> add(new CheckBox("openLocationPanelLink").add(new
> SimpleAttributeModifier("onclick", "var
> panel=document.getElementById('" + addLocationPanel.getMarkupId() +
> "');panel.style.display=this.checked?'block':'none';")));
> ..
> }
>
> It's as you see another panel, and the exception is thrown:
> WicketMessage: This component is not (yet) coupled to a page. It has
> to be able to find the page it is supposed to operate in before you
> can call this method (Component#getMarkupId)
>
> It means for me that addLocationPanel.getMarkupId() is not setup yet
> (it could be quite obvious, because it's constructor and I haven't
> send any info about page to it, and probably it's send after creating
> instance). But what can i do in such situation? What is best pattern?
>
> Best regards,
> Adr
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org