Primefaces和liferay:单选不起作用

时间:2012-11-15 21:11:11

标签: primefaces liferay

我按照http://www.primefaces.org/showcase/ui/datatableRowSelectionSingle.jsf

给出的示例

我在Liferay中使用它作为portlet。这是我的代码:

HTML:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui">

    <h:form id="form">

        <h:panelGrid columns="1" cellpadding="10" width="100%">

            <p:dataTable id="campaignTable" var="data"
                value="#{campaign.allCampaigns}" selectionMode="single"
                rowKey="#{data.campaignId}" selection="#{campaign.selectedCampaign}">

                <f:facet name="header">  
                    <p:commandButton type="button" value="Create Campaign" icon="ui-icon-document" update=":form:createForm" onclick="createDialog.show()" />

                </f:facet>

                <p:column sortBy="#{data.campaignId}">
                    <f:facet name="header">ID</f:facet>
                    <h:outputText value="#{data.campaignId}" />
                </p:column>

                <p:column sortBy="#{data.carrier}">
                    <f:facet name="header">Carrier</f:facet>
                    <h:outputText value="#{data.carrier}" />
                </p:column>

                <p:column sortBy="#{data.shortCode}">
                    <f:facet name="header">Short Code</f:facet>
                    <h:outputText value="#{data.shortCode}" />
                </p:column>

                <p:column sortBy="#{data.sendType}">
                    <f:facet name="header">Send Type</f:facet>
                    <h:outputText value="#{data.sendType}" />
                </p:column>

                <p:column sortBy="#{data.startDate}">
                    <f:facet name="header">Start Date</f:facet>
                    <h:outputText value="#{data.startDate.time}">
                        <f:convertDateTime pattern="MM/dd/yyyy hh:mm a" />
                    </h:outputText>
                </p:column>

                <p:column sortBy="#{data.endDate}">
                    <f:facet name="header">End Date</f:facet>
                    <h:outputText value="#{data.endDate.time}">
                        <f:convertDateTime pattern="MM/dd/yyyy hh:mm a" />
                    </h:outputText>
                </p:column>

                <p:column sortBy="#{data.messageText}">
                    <f:facet name="header">Text Message</f:facet>
                    <h:outputText value="#{data.messageText}" />
                </p:column>

                <p:column sortBy="#{data.serviceId}">
                    <f:facet name="header">Service ID</f:facet>
                    <h:outputText value="#{data.serviceId}" />
                </p:column>

                <p:column sortBy="#{data.responseKeyword}">
                    <f:facet name="header">Response Keyword</f:facet>
                    <h:outputText value="#{data.responseKeyword}" />
                </p:column>

            </p:dataTable>
        </h:panelGrid>


        <p:dialog id="createDialog" header="Create Campaign" widgetVar="createDialog">

            <h:panelGrid id="createForm" columns="2" cellpadding="5">
                <h:outputLabel for="campaignId" value="Campaign ID:" />
                <p:inputText value="#{campaign.selectedCampaign.campaignId}" id="campaignId" required="true" label="Campaign ID" />

                <h:outputLabel for="startDate" value="Start Date:" />
                <p:inputText value="#{campaign.selectedCampaign.startDate}" id="startDate" required="true" label="Start Date" />

                <f:facet name="footer">
                    <p:commandButton id="createCampaignButton" value="Create" update=":growl" actionListener="#{campaign.createCampaign()}" />
                </f:facet>
            </h:panelGrid>
        </p:dialog>

    </h:form>

</ui:composition>

支持bean:

@ManagedBean
@ViewScoped
public class Campaign implements Serializable {

    private List<CampaignBean> allCampaigns;
    private CampaignBean selectedCampaign;

    public Campaign() {
        MyProxy proxy = new MyProxy();
        try {
            CampaignsResponse response = proxy.getAllCampaigns();
            if (response != null) {
                setAllCampaigns(new ArrayList<CampaignBean>(Arrays
                        .asList(response.getCampaigns())));
            }
        } catch (RemoteException e) {
            FacesContext context = FacesContext.getCurrentInstance();
            context.addMessage(null, new FacesMessage("Error",
                    "Problem listing campaigns"));
        }
    }

    public void createCampaign() {

    }


    /* Getters and Setters */
    public List<CampaignBean> getAllCampaigns() {
        return allCampaigns;
    }

    public void setAllCampaigns(List<CampaignBean> allCampaigns) {
        this.allCampaigns = allCampaigns;
    }

    public CampaignBean getSelectedCampaign() {
        return selectedCampaign;
    }

    public void setSelectedCampaign(CampaignBean selectedCampaign) {
        this.selectedCampaign = selectedCampaign;
    }


}

表单未填充选定的行值!

1 个答案:

答案 0 :(得分:2)

我终于弄明白了问题所在。整个表位于“TabView”组件中。我使用了错误的选择器,即使用update=":form:createForm"而不是update=":tabView:form:createForm",我应该使用type="button"并删除{{1}}声明。