简体   繁体   English

如何隐藏Wicket面板?

[英]How do I make a Wicket Panel hidden?

So I have to edit code of a co-worker but I cannot seem to figure out how to adjust it so the panel is hidden when there is no data present. 因此,我必须编辑一位同事的代码,但似乎无法弄清楚如何进行调整,因此在没有数据的情况下隐藏面板。 Currently it returns null when no data is present. 当前,如果没有数据,则返回null。 If there is information available for a customer, it shows their full info. 如果有客户可用的信息,它将显示其完整信息。 If there is not, I want to make the panel hidden. 如果没有,我想隐藏面板。 This is also a re-useable panel used throughout the site. 这也是整个站点使用的可重复使用的面板。 What do I need to adjust to make this work? 我需要进行哪些调整才能使其正常工作?

@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));

}

Override onConfigure and you can probably do something like this: 覆盖onConfigure,您可能可以执行以下操作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM