-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hey, I'm trying to set a native li elements class dynamically from the session with @load:
<h:li class="@load(sessionScope.selectedMenu)">
When I load the page I get this error:
org.zkoss.zk.ui.UiException: Cannot convert articleTable of type class java.lang.String to class java.lang.Class
ArticleTable is the value of the selectedMenu session attribute. It gives the same error when I try this:
<h:li class="@load('something')">
I also tried accessing session attribute with the ${sessionScope.selectedMenu}
syntax, but it didn't give back any value, which is strange because I use the same syntax to access labels and that works fine.
Am I doing something wrong or this is just not possible?
Thanks!
Hello ,
Please find below a working example:
Zul:
<zk>
<window xmlns="http://www.zkoss.org/2005/zul"
apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('sample.SessionTest')">
<textbox value="@bind(sessionScope.name)"/>
</window>
</zk>
Java:
package sample;
import org.zkoss.bind.annotation.AfterCompose;
import org.zkoss.bind.annotation.ContextParam;
import org.zkoss.bind.annotation.ContextType;
import org.zkoss.bind.annotation.Init;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Sessions;
import org.zkoss.zk.ui.select.Selectors;
import java.io.Serializable;
public class SessionTest implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
@Init
public void init() {
Sessions.getCurrent().setAttribute("name", "test name");
}
@AfterCompose
public void afterCompose(
@ContextParam(ContextType.VIEW)
Component view) {
Selectors.wireComponents(view, this, false);
}
}
Best Regards,
Darksu
Asked: 2015-07-31 09:38:45 +0800
Seen: 12 times
Last updated: Jul 31 '15
The compiler expect for class a real class object. You give a string object. Thats why you have the fault.
chillworld ( 2015-08-01 18:42:05 +0800 )edit