2013-02-19 131 views
-1

所以我必须编辑同事的代码,但我似乎无法弄清楚如何调整它,以便在没有数据存在时隐藏面板。当前没有数据时,它返回null。如果客户有信息可用,则会显示其完整信息。如果没有,我想隐藏面板。这也是整个现场使用的可重复使用的面板。我需要做些什么调整才能完成这项工作?如何隐藏Wicket面板?

@Override 
protected void onInitialize() 
{ 
    // TODO Auto-generated method stub 
    super.onInitialize();   


    if(customer != null) 
    { 
     loadWithCustomer(); 
    } 
    else 
    { 
     loadWithNoCustomer(); 
    } 


} 

@Override 
protected void onBeforeRender() 
{ 
    super.onBeforeRender(); 

    AjaxLink<Void> createOrderLink = makeCreateOrderLink(customer); 

    SkinnyBuSession session = (SkinnyBuSession) Session.get();  
    if(session != null && session.getCustomer() == null) 
     createOrderLink.setEnabled(false); 

    addOrReplace(createOrderLink); 
} 

private void loadWithCustomer() 
{ 
    addOrReplace(new Label("heading", customer.getAccountName())); 


    Contact contact = null; 
    if(customer.getContacts() != null && customer.getContacts().size() > 0) 
    { 
     contact = customer.getContacts().get(0); 
    } 
    else 
    { 
     contact = new Contact();//makeUpJunkContactForNow(); 
     customer.getContacts().add(contact); 
    } 
    Address address = null; 
    if(customer.getAddresses() != null && customer.getAddresses().size() > 0) 
    { 
     address = customer.getAddresses().get(0); 
    } 
    else 
    { 
     address = new Address();//makeUpJunkAddressForNow(); 
     customer.getAddresses().add(address); 
    } 

    String phone = contact.getPhoneNumber() != null ? contact.getPhoneNumber().getNationalNumber() : ""; 
    if (phone != null && phone.length() == 10) 
    { 
     phone = String.format("(%s) %s-%s", phone.substring(0, 3), phone.substring(3, 6),phone.substring(6, 10)); 
    }  

    addOrReplace(new Label("accountName", customer.getAccountName())); 
    addOrReplace(new Label("address1", address.getAddressLine1())); 
    addOrReplace(new Label("address2", address.getAddressLine2())); 
    addOrReplace(new Label("city", address.getCityName() + ",")); 
    addOrReplace(new Label("state", address.getStateCode())); 
    addOrReplace(new Label("postalCode", address.getPostalCode())); 
    addOrReplace(new Label("contactName", contact.getName())); 
    addOrReplace(new Label("email", contact.getEmailAddress())); 
    addOrReplace(new Label("phone", phone));   

} 

private void loadWithNoCustomer() 
{ 
    Label heading = new Label("heading", ""); 
    addOrReplace(heading.setVisible(false)); 

    addOrReplace(new Label("accountName", "").setVisible(false)); 
    addOrReplace(new Label("address1", "").setVisible(false)); 
    addOrReplace(new Label("address2", "").setVisible(false)); 
    addOrReplace(new Label("city", "").setVisible(false)); 
    addOrReplace(new Label("state", "").setVisible(false)); 
    addOrReplace(new Label("postalCode", "").setVisible(false)); 
    addOrReplace(new Label("contactName", "").setVisible(false)); 
    addOrReplace(new Label("email", "").setVisible(false)); 
    addOrReplace(new Label("phone", "").setVisible(false)); 

} 
+0

更新你的问题你已经尝试过的。 – Jesse 2013-02-20 00:03:39

回答

3

覆盖onConfigure你也许可以做这样的事情:

@Override 
protected void onConfigure() { 
    super.onConfigure(); 
    setVisible(customer != null); 
} 
+0

您需要使用setVisibilityAllowed,因为组件可能会覆盖isVisible()方法,忽略您使用setVisible()设置的值 – RobAu 2013-02-25 19:58:45

+0

谢谢您为我所需要的工作 – Andrea 2013-03-01 16:32:01