Hibernate zk以编程方式选择组合框项
我无法以编程方式设置combobox的值。有人能告诉我代码中缺少了什么吗Hibernate zk以编程方式选择组合框项,hibernate,spring,zk,Hibernate,Spring,Zk,我无法以编程方式设置combobox的值。有人能告诉我代码中缺少了什么吗 public class Profile extends Window implements AfterCompose { @Override public void afterCompose() { Session session = Sessions.getCurrent(false); ApplicationContext ctx = WebAppli
public class Profile extends Window implements AfterCompose {
@Override
public void afterCompose() {
Session session = Sessions.getCurrent(false);
ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(
(ServletContext) getDesktop().getWebApp().getNativeContext());
UsersDao usersDao = (UsersDao) ctx.getBean("daoUsers");
User user = (User) session.getAttribute("user");
user = usersDao.getUser(user.getUsername(),user.getPassword());
Textbox username_t = (Textbox) this.getFellow("username");
Textbox password_t = (Textbox) this.getFellow("password");
Textbox conpassword_t = (Textbox) this.getFellow("con_password");
Textbox firstname_t = (Textbox) this.getFellow("firstName");
Textbox lastname_t = (Textbox) this.getFellow("lastName");
Textbox email_t = (Textbox) this.getFellow("email");
Combobox hintQuestion_t = (Combobox) this.getFellow("hintQuestion");
Textbox hintAnswer_t = (Textbox) this.getFellow("hintAnswer");
Combobox locale_t = (Combobox) this.getFellow("locale");
Combobox authority_t = (Combobox) this.getFellow("authority");
username_t.setText(user.getUsername());
firstname_t.setText(user.getUserDetails().getFirstName());
lastname_t.setText(user.getUserDetails().getLastName());
email_t.setText(user.getUserDetails().getEmail());
Comboitem selectedItem = getSelectedIndexComboboxItem(hintQuestion_t, user.getHintQuestion());
hintQuestion_t.setSelectedItem(selectedItem);
hintAnswer_t.setText(user.getHintAnswer());
selectedItem = getSelectedIndexComboboxItem(locale_t, user.getUserDetails().getLocale());
locale_t.setSelectedItem(selectedItem);
selectedItem = getSelectedIndexComboboxItem(authority_t, ((Authority)user.getAuthorities().toArray()[0]).getRole());
authority_t.setSelectedItem(selectedItem);
}
private Comboitem getSelectedIndexComboboxItem(Combobox combobox, String value) {
List<Comboitem> items = combobox.getItems();
Comboitem item = items.get(0);
for (int i = 0; i < items.size(); i++) {
Comboitem comboitem = items.get(i);
String label = (String)comboitem.getLabel();
String cval = (String)comboitem.getValue();
if ((label!=null && label.equalsIgnoreCase(value)) || (cval != null && cval.equalsIgnoreCase(value))) {
item = comboitem;
break;
}
}
return item;
}
}
公共类概要文件扩展窗口{
@凌驾
公共空间{
Session Session=Sessions.getCurrent(false);
ApplicationContext ctx=WebApplicationContextILS.getRequiredWebApplicationContext(
(ServletContext)getDesktop().getWebApp().getNativeContext());
UsersDao UsersDao=(UsersDao)ctx.getBean(“daoUsers”);
User=(User)session.getAttribute(“用户”);
user=usersDao.getUser(user.getUsername(),user.getPassword());
Textbox username_t=(Textbox)this.getFellow(“用户名”);
Textbox password_t=(Textbox)this.getFellow(“密码”);
Textbox conpassword_t=(Textbox)this.getFellow(“con_密码”);
Textbox firstname_t=(Textbox)this.getFellow(“firstname”);
Textbox lastname_t=(Textbox)this.getFellow(“lastname”);
Textbox email_t=(Textbox)this.getFellow(“电子邮件”);
Combobox hintQuestion_t=(Combobox)this.getFellow(“hintQuestion”);
Textbox hintAnswer_t=(Textbox)this.getFellow(“hintAnswer”);
Combobox locale_t=(Combobox)this.getfello(“locale”);
Combobox authority_t=(Combobox)this.getFellow(“authority”);
username_t.setText(user.getUsername());
firstname_t.setText(user.getUserDetails().getFirstName());
lastname_t.setText(user.getUserDetails().getLastName());
email_t.setText(user.getUserDetails().getEmail());
Comboitem selectedItem=getSelectedIndexComboboxItem(hintQuestion_t,user.getHintQuestion());
hintQuestion_t.setSelectedItem(selectedItem);
hintAnswer_t.setText(user.getHintAnswer());
selectedItem=getselectedIndexComboxItem(locale\u t,user.getUserDetails().getLocale());
locale_t.setSelectedItem(selectedItem);
selectedItem=getselectedIndexComboxItem(authority_t,((authority)user.getAuthorities().toArray()[0]).getRole());
权限设置selectedItem(selectedItem);
}
私有Comboitem getSelectedIndexComboboxItem(Combobox Combobox,字符串值){
List items=combobox.getItems();
Comboitem=items.get(0);
对于(int i=0;i
//zk文件
<window id="profile" use="com.jf.web.zk.ui.Profile">
<tabbox id="tabbox" width="40%" >
<tabs>
<tab label="Account Information"/>
<tab label="Personal Information"/>
<tab label="Contact Details"/>
</tabs>
<tabpanels>
<tabpanel>
<grid>
<rows>
<row>
<label value="${i18nUtils.message('user.username')}"/>
<hbox>
<textbox id="username" />*,a-zA-Z,0-9
</hbox>
</row>
<row>
<label value="${i18nUtils.message('user.password')}"/>
<hbox>
<textbox id="password" type="password"/>*
</hbox>
</row>
<row>
<label value="${i18nUtils.message('registration.user.password.confirm')}"/>
<hbox>
<textbox id="con_password" type="password"/>*
</hbox>
</row>
<row>
<label value="${i18nUtils.message('user.details.first.name')}"/>
<hbox>
<textbox id="firstName" type="text"/>*
</hbox>
</row>
<row>
<label value="${i18nUtils.message('user.details.last.name')}"/>
<hbox>
<textbox id="lastName" type="text"/>*
</hbox>
</row>
<row>
<label value="${i18nUtils.message('user.details.email')}"/>
<hbox>
<textbox id="email" type="text"/>*
</hbox>
</row>
<row>
<label value="${i18nUtils.message('user.hint.question')}"/>
<hbox>
<combobox id="hintQuestion" onCreate='self.setSelectedIndex(1);'>
<comboitem label="${i18nUtils.message('user.hint.question.possible.value1')}" />
<comboitem label="${i18nUtils.message('user.hint.question.possible.value2')}" />
<comboitem label="${i18nUtils.message('user.hint.question.possible.value3')}" />
<comboitem label="${i18nUtils.message('user.hint.question.possible.value4')}" />
<comboitem label="${i18nUtils.message('user.hint.question.possible.value5')}" />
</combobox>*
</hbox>
</row>
<row>
<label value="${i18nUtils.message('user.hint.answer')}"/>
<hbox>
<textbox id="hintAnswer" type="text"/>*
</hbox>
</row>
<row>
<label value="${i18nUtils.message('user.details.locale')}"/>
<hbox>
<combobox id="locale" onCreate='self.setSelectedIndex(1);self.setReadonly(true);'>
<comboitem label="${i18nUtils.message('user.details.locale.en')}" value="en_US"/>
<comboitem label="${i18nUtils.message('user.details.locale.bg')}" value="bg_BG"/>
</combobox>*
</hbox>
</row>
<row>
<label value="${i18nUtils.message('authority.account.type')}"/>
<hbox>
<combobox id="authority" onCreate='self.setSelectedIndex(0);self.setReadonly(true);'>
<comboitem label="${i18nUtils.message('authority.job.seeker')}" value="Job Seeker"/>
<comboitem label="${i18nUtils.message('authority.employer')}" value="Employer"/>
<comboitem label="${i18nUtils.message('authority.hra')}" value="Human Resource Agency"/>
<comboitem label="${i18nUtils.message('authority.advertiser')}" value="Advertiser"/>
</combobox>*
</hbox>
</row>
</rows>
</grid>
</tabpanel>
</tabpanels>
</tabbox>
<grid width="40%">
<rows>
<row>
<button label="${i18nUtils.message('bttn.save')}" onClick="save()"/>
<button label="${i18nUtils.message('bttn.cancel')}" onClick="cancel()"/>
</row>
</rows>
</grid>
</window>
</zk>
*,a-zA-Z,0-9
*
*
*
*
*
*
*
*
*
“getSelectedIndexComboboxItem()”确实返回正确的选定项,但对UI似乎没有影响。例如,语言环境设置为默认保加利亚语,我需要将其设置为英语。我认为这是ZK版本中的一个错误。您可以尝试使用setSelectedItemApi或
<window title="composer5 example" border="normal" width="300px" apply="example.MyComposer">
<grid>
<rows>
<row>First Name: <textbox id="firstName"/></row><!-- forward is removed -->
<row>Last Name: <textbox id="lastName"/></row><!-- forward is removed -->
<row>Full Name: <label id="fullName"/></row>
</rows>
</grid>
</window>
package example;
public class MyComposer extends GenericForwardComposer {
private Textbox firstName;
private Textbox lastName;
private Label fullName;
@Override
public void doAfterCompose(Component comp) throws Exception {
// TODO Auto-generated method stub
super.doAfterCompose(comp);
}
//onChange event from firstName component
public void onChange$firstName(Event event) {
fullName.setValue(firstName.getValue()+" "+lastName.getValue());
}
//onChange event from lastName component
public void onChange$lastName(Event event) {
fullName.setValue(firstName.getValue()+" "+lastName.getValue());
}
}