You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by rolandpeng <ro...@cht.com.tw> on 2010/08/04 04:19:09 UTC

How to setResponsePage with a classname string parameter?

Hi,I want to redirect to a dynamic webpage,but I can only get the destination
as a fullpath classname string .The sample code like below,

String pageClass=task.getFormResourceName();

WebPage page=null;
if(pageClass.equals("com.sandbox.Page1")){
	page=new Page1();
}else if(pageClass.equals("com.sandbox.practices.Page2")){
	page=new Page2();
}else if(pageClass.equals("com.sandbox.practices.Page3")){
	page=new Page3();
}
setResponsePage(page);

Is there any better way to replace this "if...else if" way? I have tried
Class.forname(pageClass),but compiles error and shows Bound mismatch,like
below,

Bound mismatch: The generic method setResponsePage(Class<C>) of type
Component is not applicable for the arguments (Class<capture#3-of ?>). The
inferred type capture#3-of ? is not a valid substitute for the bounded
parameter <C extends Page>.

Any suggestion is welcome,thank you.
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-to-setResponsePage-with-a-classname-string-parameter-tp2312847p2312847.html
Sent from the Wicket - User mailing list archive at Nabble.com.

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


Re: How to setResponsePage with a classname string parameter?

Posted by rolandpeng <ro...@cht.com.tw>.
oh,I've figured it out...I should cast it with generic class. thank you :)

try {
      setResponsePage((Class<Page>)Class.forName(pageClass));
} catch (ClassNotFoundException e) {
      e.printStackTrace();
}	


rolandpeng wrote:
> 
> I've also tried casting like this.
> setResponsePage((Page)Class.forName(pageClass));
> 
> but compiles error as well,the message below,
> The method setResponsePage(Class<C>) in the type Component is not
> applicable for the arguments (Page)
> 
> 
> James Carman wrote:
>> 
>> Cast it?
>> 
>> On Aug 3, 2010 10:19 PM, "rolandpeng" <ro...@cht.com.tw> wrote:
>> 
> 
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-to-setResponsePage-with-a-classname-string-parameter-tp2312847p2312878.html
Sent from the Wicket - User mailing list archive at Nabble.com.

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


Re: How to setResponsePage with a classname string parameter?

Posted by rolandpeng <ro...@cht.com.tw>.
I've also tried casting like this.
setResponsePage((Page)Class.forName(pageClass));

but compiles error as well,the message below,
The method setResponsePage(Class<C>) in the type Component is not applicable
for the arguments (Page)


James Carman wrote:
> 
> Cast it?
> 
> On Aug 3, 2010 10:19 PM, "rolandpeng" <ro...@cht.com.tw> wrote:
> 
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-to-setResponsePage-with-a-classname-string-parameter-tp2312847p2312876.html
Sent from the Wicket - User mailing list archive at Nabble.com.

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


Re: How to setResponsePage with a classname string parameter?

Posted by James Carman <ja...@carmanconsulting.com>.
Cast it?

On Aug 3, 2010 10:19 PM, "rolandpeng" <ro...@cht.com.tw> wrote:
>
> Hi,I want to redirect to a dynamic webpage,but I can only get the
destination
> as a fullpath classname string .The sample code like below,
>
> String pageClass=task.getFormResourceName();
>
> WebPage page=null;
> if(pageClass.equals("com.sandbox.Page1")){
> page=new Page1();
> }else if(pageClass.equals("com.sandbox.practices.Page2")){
> page=new Page2();
> }else if(pageClass.equals("com.sandbox.practices.Page3")){
> page=new Page3();
> }
> setResponsePage(page);
>
> Is there any better way to replace this "if...else if" way? I have tried
> Class.forname(pageClass),but compiles error and shows Bound mismatch,like
> below,
>
> Bound mismatch: The generic method setResponsePage(Class<C>) of type
> Component is not applicable for the arguments (Class<capture#3-of ?>). The
> inferred type capture#3-of ? is not a valid substitute for the bounded
> parameter <C extends Page>.
>
> Any suggestion is welcome,thank you.
> --
> View this message in context:
http://apache-wicket.1842946.n4.nabble.com/How-to-setResponsePage-with-a-classname-string-parameter-tp2312847p2312847.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>