2012-09-19 2 views
1

내가 여러 가지 개찰구 구성 요소에서 IsVisible() 예를 들어FormComponents 일반적인에서 IsVisible 방법이

같은 구현을 가질 수 있습니다 어떻게든지해서 거기에 내가 같은에서 IsVisible 방법을 가지고 있지만 내가 그나마 레이블, TextField의, DropdownChoices 등이 코드 변경을 유지하기가 어렵 기 때문에 모든 사용자 정의 클래스를 구현하지 않아도됩니다.

btw 페이지 디자인으로 인해 웹 마크 업 컨테이너에 넣을 수 없습니다.

나는이 모든 것을 상속 받기를 바랍니다.

public class DepositoryFormComponent extends Component 
{ 
public DepositoryFormComponent(String id) { 
    super(id); 
} 

public DepositoryFormComponent(String id, IModel model) { 
    super(id, model); 
} 

public boolean isVisible() { 
    return isFormDepositoryType(); 
} 

protected boolean isFormDepositoryType() { 
    return getCurrentSelections().getSelectedOwnedAccount().getAssetType() == AssetType.DEPOSITORY; 
} 

protected CurrentSelections getCurrentSelections() { 
    return (CurrentSelections) getSession().getAttribute(CurrentSelections.ATTRIBUTE_NAME); 
} 

public void onRender(){}; 

}

답변

2

당신은 몇 가지 옵션이있다 : 당신의 가시성을 제어 할

  1. 마크 업에 대한 제어를 가지고있는 경우에

    및 수있는 하나의 태그 그룹 모든 구성 요소를 <wicket:enclosure> 태그를 사용하여 전체 마크 업 부분에 대한 구성 요소 제어 가시성을 만들 수 있습니다. 이 페이지 디자인에 영향을 미치지 않습니다, 그리고 당신은 가시성을 계산하고 ComponentsetVisible()를 호출 이러한 구성 요소 IBehavior에 추가 할 수있는 WebMarkupContainer

  2. 을 추가하는 것과 유사한 효과를 얻을 것입니다 알 수 있습니다. 나중에 setVisible()을 호출하여 Component의 가시성을 변경하지 않으려면 Component#setVisibilityAllowed()을 호출 할 수도 있습니다. 어쩌면 정확히 isVisible을 무시하는 것이 아니지만 사용자 지정 구성 요소를 만들지 않으면 재정의를 얻지 못할 수도 있습니다.

    public class VisiblityControlBehavior extends AbstractBehavior { 
    
        private boolean isComponentVisible() { 
         return isFormDepositoryType(); 
        } 
    
        protected boolean isFormDepositoryType() { 
         return getCurrentSelections().getSelectedOwnedAccount().getAssetType() == AssetType.DEPOSITORY; 
        } 
    
        protected CurrentSelections getCurrentSelections() { 
         return (CurrentSelections) getSession().getAttribute(CurrentSelections.ATTRIBUTE_NAME); 
        } 
    
        @Override 
        public void bind(Component component) { 
         boolean visible = isComponentVisible(); 
         component.setVisible(visible); 
         component.setVisibilityAllowed(visible); 
        } 
    }