【问题标题】:Ektorp ArrayList get all in JSF in the PrimeFaces List componentEktorp ArrayList get all in JSF in PrimeFaces List 组件
【发布时间】:2014-02-14 16:01:12
【问题描述】:

如何通过 Ektorp API 从 CouchDB 获取我的现有锦标赛列表?我的代码如下所示:

非常感谢。

我在我的 TourneyService 类中调用 getAll() 方法,而 getAll() 是 Tourneys 列表

//TourneyService

@Service
public class TourneyService implements Serializable{

private static final long serialVersionUID = 699617628013084160L;

@Autowired
private TourneyRepository tourneyRepository;

public List<Tourney> getAllTourneys(){
    return tourneyRepository.getAll();
}
}

//TourneyRepository

@Component
public class TourneyRepository extends CouchDbRepositorySupport<Tourney> {

@Autowired
public TourneyRepository(@Qualifier("cegocouchdb") CouchDbConnector db) {
    super(Tourney.class, db);
    initStandardDesignDocument();
}

@GenerateView @Override
public List<Tourney> getAll() {
    ViewQuery q = createQuery("all")
                    .descending(true)
                    .includeDocs(true);
    return db.queryView(q, Tourney.class);
}

   }

//TourneyListBean

    @ManagedBean(name = "TourneyListMmgtBean")
    @RequestScoped
    public class TourneyListBean implements Serializable {

private static final long serialVersionUID = 6130842812974474768L;

@ManagedProperty(value = "#{tourneyService}")
private TourneyService tourneyService;

private List<Tourney> tourneys; 

public void onEdit(RowEditEvent event) {
    FacesMessage msg = new FacesMessage("Tourney changed", "");

    FacesContext.getCurrentInstance().addMessage(null, msg);
}

public void onCancel(RowEditEvent event) {
    FacesMessage msg = new FacesMessage("Aktion abgebrochen", "");

    FacesContext.getCurrentInstance().addMessage(null, msg);
}


public TourneyService getTourneyService() {
    return tourneyService;
}

public void setTourneyService(TourneyService tourneyService) {
    this.tourneyService = tourneyService;
}

public List<Tourney> getTourneys() {
    tourneys = tourneyService.getAllTourneys();
    if (tourneys == null) {
        tourneys = new ArrayList<Tourney>();
    }
    return tourneys;
}

public void setTourneys(List<Tourney> torneys) {
    this.tourneys = torneys;
}
   }

JSF

<ui:define name="content">



    <h:form id="form">

        <p:growl id="messages" showDetail="true" />

        <p:dataTable var="tourney" value="#{TourneyListMmgtBean.tourneys}"
            id="tourneyList" editable="true">

            <f:facet name="header">  
        In-Cell Editing  
    </f:facet>

            <p:ajax event="rowEdit" listener="#{TourneyListMmgtBean.onEdit}"
                update=":form:messages" />
            <p:ajax event="rowEditCancel"
                listener="#{TourneyListMmgtBean.onCancel}" update=":form:messages" />

            <p:column headerText="Turniername" style="width:30%">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{tourney.name}" />
                    </f:facet>
                    <f:facet name="input">
                        <p:inputText value="#{tourney.name}" style="width:100%"
                            label="Turniername" />
                    </f:facet>
                </p:cellEditor>
            </p:column>

            <p:column headerText="Straße" style="width:20%">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{tourney.street}" />
                    </f:facet>
                    <f:facet name="input">
                        <p:inputText value="#{tourney.street}" style="width:100%"
                            label="Straße" />
                    </f:facet>
                </p:cellEditor>
            </p:column>

            <p:column headerText="Turnierstadt" style="width:24%">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{tourney.city}" />
                    </f:facet>
                    <f:facet name="input">
                        <p:inputText value="#{tourney.city}" style="width:100%"
                            label="Turnierstadt" />
                    </f:facet>
                </p:cellEditor>
            </p:column>

            <p:column headerText="Beginnzeit" style="width:24%">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{tourney.beginTime}" />
                    </f:facet>
                    <f:facet name="input">
                        <p:inputText value="#{tourney.beginTime}" style="width:100%"
                            label="Beginnzeit" />
                    </f:facet>
                </p:cellEditor>
            </p:column>

            <p:column headerText="Endzeit" style="width:24%">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{tourney.endTime}" />
                    </f:facet>
                    <f:facet name="input">
                        <p:inputText value="#{tourney.endTime}" style="width:100%"
                            label="Endzeit" />
                    </f:facet>
                </p:cellEditor>
            </p:column>

            <p:column headerText="Turnierpunkte" style="width:24%">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{tourney.points}" />
                    </f:facet>
                    <f:facet name="input">
                        <p:inputText value="#{tourney.points}" style="width:100%"
                            label="Turnierpunkte" />
                    </f:facet>
                </p:cellEditor>
            </p:column>

            <p:column style="width:6%">
                <p:rowEditor />
            </p:column>

        </p:dataTable>

    </h:form>

</ui:define>

错误:

org.ektorp.support.ViewGenerationException: Cannot generate 'all' view for null.

【问题讨论】:

    标签: spring jsf primefaces couchdb ektorp


    【解决方案1】:

    @GenerateView 具有以下约束:

    • 该方法必须命名为 findBy[Property]。如果定义了@TypeDiscriminator,也可以生成getAll方法使用的“all”视图。
    • 该方法可能只有一个参数。
    • 该属性必须存在于目标类中。

    验证您的 Tourney 课程中是否有 @TypeDiscriminator

    【讨论】:

      猜你喜欢
      • 2014-12-02
      • 2022-12-27
      • 1970-01-01
      • 2022-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-16
      相关资源
      最近更新 更多