简体   繁体   English

Ektorp ArrayList在PrimeFaces List组件的JSF中获取所有内容

[英]Ektorp ArrayList get all in JSF in the PrimeFaces List component

How can i get my List of existing Tourneys via Ektorp API from CouchDB? 我如何从CouchDB通过Ektorp API获取我现有的锦标赛名单? My code looks like this: 我的代码如下所示:

thanks a lot. 非常感谢。

I call the methode getAll() in my TourneyService Class and getAll() is a list of Tourneys 我在TourneyService类中调用方法getAll(),而getAll()是Tourneys的列表

//TourneyService // 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 // 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 // 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 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>

Error: 错误:

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

@GenerateView has the following constraints: @GenerateView具有以下约束:

  • The method must be named findBy[Property]. 该方法必须命名为findBy [Property]。 If a @TypeDiscriminator is defined, the "all" view used by the getAll method can also be generated. 如果定义了@TypeDiscriminator,则还可以生成getAll方法使用的“所有”视图。
  • The method may only have one parameter. 该方法可能只有一个参数。
  • The property must exist in the target class. 该属性必须存在于目标类中。

Verify that you have an @TypeDiscriminator in your Tourney class 验证您的Tourney类中是否有@TypeDiscriminator

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

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