大家晚上好!
我已经部署了一个由Vaadin7制作的应用程序,在测试过程中,我们在IE上运行应用程序时遇到了一些奇怪的事情。
菜单栏仅显示三(3)个项目,其余项目通过三角形按钮查看。它只发生在IE上(我们在办公室上有IE11,如果有帮助的话)..在Firefox和Chrome上,它完美运行,如下图所示:
这是我用于标题的代码:
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import no.solarsoft.studentweb.listener.MenuItemSelectionListener;
import no.solarsoft.studentweb.manager.ResourceManager;
import no.solarsoft.studentweb.manager.SessionHelper;
import no.solarsoft.studentweb.theme.StudentWebTheme;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.vaadin.server.FileResource;
import com.vaadin.server.Page;
import com.vaadin.server.ThemeResource;
import com.vaadin.server.VaadinService;
import com.vaadin.ui.MenuBar.MenuItem;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.Image;
import com.vaadin.ui.MenuBar;
import com.vaadin.ui.Panel;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
public class Header extends CustomComponent{
private static final long serialVersionUID = 4573713330320823676L;
List<MenuItemSelectionListener> menuItemListeners = new ArrayList<MenuItemSelectionListener>();
private MenuBar barmenu ;
private VerticalLayout headerLayout;
private Panel panel;
private Logger logger ;
Image imgOrganisation;
private MenuItem previous = null;
private static final String BASE_PATH = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath();
public Header(){
logger = LogManager.getLogger(Header.class);
MenuBar.Command myCommand = new MenuBar.Command() {
private static final long serialVersionUID = -1224979160403018369L;
@Override
public void menuSelected(MenuItem selectedItem) {
// TODO Auto-generated method stub
int id = selectedItem.getId();
for (MenuItemSelectionListener l : menuItemListeners) {
l.handleMenuItemSelection(id);
}
if(previous!=null){
previous.setStyleName(null);
}
selectedItem.setStyleName(StudentWebTheme.HEADER_HIGHLIGHT);
previous = selectedItem;
}
};
barmenu = new MenuBar();
barmenu.addStyleName("mybarmenu");
panel = new Panel();
headerLayout = new VerticalLayout();
imgOrganisation = ResourceManager.getInstance().getLogoAsImage(SessionHelper.getOrganisationCode()+".png");
if(barmenu.getItems().size()==0){
barmenu.addItem("PersonDetaljer", null,myCommand);
barmenu.addItem("Studieplan", null,myCommand);
barmenu.addItem("Studieprogrammer", null,myCommand);
barmenu.addItem("Gjennomføringer", null,myCommand);
barmenu.addItem("Eksamener", null,myCommand);
barmenu.addItem("Endelige Karakterer", null,myCommand);
barmenu.addItem("Lånekassen", null,myCommand);
barmenu.addItem("Artikkel", null,myCommand);
barmenu.addItem("Instillinger", null,myCommand);
barmenu.addItem("Logg av", null,myCommand);
}
logger.info("menu bar size: {} ", barmenu.getItems().size());
barmenu.setSizeFull();
imgOrganisation .setSizeUndefined();
barmenu.setVisible(false);
headerLayout.addComponents(imgOrganisation,barmenu);
headerLayout.setSpacing(true);
panel.setContent(headerLayout);
panel.setSizeUndefined();
panel.setWidth("100%");
panel.getContent().setSizeUndefined();
setCompositionRoot(panel);
}
public void setMenuBarVisible(boolean visible){
barmenu.setVisible(visible);
}
public void setMenuItemStyle(String uri){
for(MenuItem item : barmenu.getItems()){
logger.info(" \nitem: {} \nuri:{} \nprevious: {} ", item.getText(),
uri,previous==null?"null":previous.getText());
if(uri.equalsIgnoreCase(itemToUri(item.getText()))){
logger.info("bingo! ");
item.setStyleName(StudentWebTheme.HEADER_HIGHLIGHT);
previous=item;
}else{
item.setStyleName(null);
logger.info("style name: {}", item.getStyleName());
logger.info("null style");
}
}
}
public String itemToUri(String itemName){
String newItemName="";
for(int index =0;index<itemName.length();index++){
switch(itemName.charAt(index)){
case 'Å':
case 'å':
newItemName+="aa";
break;
case 'Ø':
case 'ø':
newItemName+="oe";
break;
case 'Æ':
case 'æ':
newItemName+="ae";
break;
case ' ':
break;
default:
newItemName+=itemName.charAt(index);
}
}
return newItemName;
}
public void addMenuItemSelectionListener(MenuItemSelectionListener l) {
menuItemListeners.add(l);
}
我想知道为什么它在IE上显得“怪异”。我希望有一个人可以帮助我。谢谢!