2

我有以下抽象类

public abstract class ReturnAgentFromTab extends BasePage{

    @Persist("session")
    public abstract Agent getAgent();
    public abstract void setAgent(Agent agent);

    @InjectObject("spring:agentApplicationModeResolver")
    public abstract AgentApplicationModeResolver getAgentApplicationModeResolver();

    .... more @InjectObject()

    public void nextPage(IRequestCycle cycle) {

        setApplicationModeUsingAgentStatus(getAgent());

        AgentSearchNavigationManager navManager = getAgentSearchNavigationManagerFactory().getAgentSearchNavigationManager();
        FlowStage stage = getFlowStage();
        if (stage == null) {
            setApplicationModeUsingAgentStatus(getAgent());
            stage = getUserDefaultFlowStageService().getDefaultFlowStage(UserHolder.getUser(), getVisitClass().getApplicationMode());
        }

        Class nextPageClass = navManager.getNextPage(getUserDefaultFlowStageService());

        String nextPageQualifier = getUserDefaultFlowStageService().getPageQualifier(getAgent(), nextPageClass, getVisitClass().getApplicationMode());
        IPage nextPage = getPageUtils().getPage(nextPageClass, nextPageQualifier);
        if ((getFlowStage() instanceof PSDFlowStage)) {
            nextPageQualifier = getFlowStage().getValue();
        }
        nextPage = getPageUtils().getPage(nextPageClass, nextPageQualifier);
        if (navManager instanceof NameBasedAgentSearchNavigationManager && nextPageClass != SignOffStatusPage.class) {
            NameBasedAgentSearchNavigationManager nameBasedNavManager = (NameBasedAgentSearchNavigationManager) navManager;
            String nextPageName = nameBasedNavManager.getNextPageName(stage); 
            if (!nextPageName.equals(nextPageClass.getSimpleName())) {
                nextPage = getPageUtils().getPage(nextPageName, nextPageQualifier);
            }
        }

        if (isNextPageActivateAgentGeneral(nextPage)) {
            initialisePageLink(nextPageClass, nextPage);
        }
        ((WuamsBasePage) nextPage).init(getAgent().getAgentId());
        getPageUtils().navigateTo(nextPage);

    }

    private void setApplicationModeUsingAgentStatus(Agent agent) {
        getVisitClass().setApplicationMode(getHomeLinksFactory().getRegionHomeLinksService().getApplicationMode(agent));
    }

    private boolean isNextPageActivateAgentGeneral(IPage nextPage) {
        return nextPage instanceof ActiveAgentGeneralPage;
    }

    private void initialisePageLink(Class nextPageClass, IPage nextPage) {
        if (getVisitClass().getPageLink() == null) {
            getVisitClass().setPageLink(PageLinkUtil.getPageLinkMessageKeyFromPageClass(nextPageClass, 
                    getUserDefaultFlowStageService().getDefaultFlowStage(UserHolder.getUser(), getVisitClass().getApplicationMode()).getValue()));
        }
    }

}

我想做的是nextPage(cycle)从另一个抽象和扩展的类中调用我的ReturnAgentFromTab,但是当我尝试时

public abstract class DoSomethingWithAgent extends ReturnAgentFromTab {

@Persist("session")
public abstract ReturnAgentFromTab getReturnAgentFromTab();
public abstract void setReturnAgentFromTab(ReturnAgentFromTab returnAgentFromTab);
....
getReturnAgentFromTab().nextPage(cycle);

我得到一个空指针异常,我知道这是因为我实际上并没有在任何地方设置 ReturnAgentFromTab,但我不明白如何使用抽象类来设置它。有人可以帮忙吗?

如果您需要更多代码,请询问

4

3 回答 3

2

抽象类的要点是简单地不实现某些东西,例如提供某些对象。该方法getReturnAgentFromTab()是一个完美的例子:类本身并不关心该对象来自哪里,因为这是子类的唯一责任。所以扩展那个类,编写那个方法,突然之间,基类就完成了它的工作。

于 2012-11-02T12:32:27.430 回答
1

好吧,您不能初始化抽象类,唯一的方法是让其他一些具体类扩展您的抽象类,并使用具体类实例调用非抽象方法。

abstarct class ABS1 {
   //abstract methods
   //concreate method
   public void concMethod() {
      }
 }

public class ABS1Impl extends ABS1 {
 //implement all the abstract methods
 }
public abstract class ABS2 {
   ABS1 abs = new ABSImpl();
   abs.concMethod // 
}
于 2012-11-02T12:32:59.927 回答
1

我认为这可能只是因为两个原因。

  1. 可能是getReturnAgentFromTab()正在回归null。或者
  2. cycle的值为null
于 2012-11-02T12:36:23.110 回答