我正在尝试为primefaces数据表中的每一行显示错误消息 这是我的xhtml,我删除了一些标签,为了清楚起见省略了一些javascript函数
<f:view>
<h:form id="mainEditForm">
<!-- <p:messages id="messages" showDetail="true" autoUpdate="true" closable="true" /> -->
<p:dataTable id="configTable"
value="#{favoriteReportsQueries.myFavoriteReportsQueriesPreferences}"
var="repList"
selection="#{favoriteReportsQueries.selectedFavoriteReportsQueries}"
rowKey="#{repList.reportFavoriteName}">
<p:column headerText="Report / Query">
<h:selectOneMenu id="reportQuery" value="#{repList.reportURL} onchange="submit();" update="reportGivenName">
<f:valueChangeListener type="cmecf.ui.favoritereports.validator.CustomNameValueChangeListener" />
<f:selectItems
value="#{favoriteReportsQueries.applicationReportsAndQueries}"
var="appRepList" itemValue="#{appRepList.value}"
itemLabel="#{appRepList.label}" />
</h:selectOneMenu>
</p:column>
**<p:column headerText="Custom Name">
<p:inputText id="reportGivenName"
value="#{repList.reportFavoriteName}" size="50"/>
<f:validator validatorId="cmecf.favoritereports.CustomValidator" for="reportGivenName"/>
<p:message for="reportGivenName"/>
</p:column>**
<p:column style="width:10px;">
<f:facet name="header">
Delete
</f:facet>
<p:selectBooleanCheckbox id="deleteId"
styleClass="selectBooleanCheckbox"
value="#{repList.delete}">
<p:ajax event="valueChange" process="@this"></p:ajax>
</p:selectBooleanCheckbox>
</p:column>
</p:dataTable>
<h:panelGrid columns="7">
<p:column>
<p:commandButton id="savePrefs"
action="#{favoriteReportsQueries.storeReportsPreferences}"
oncomplete="resizeiFrame()"
value="Save" ajax="false" />
</p:column>
<p:column></p:column>
<p:column>
<p:commandLink value="Add New"
action="#{favoriteReportsQueries.addNewRow}"
oncomplete="resizeiFrame()"
update="configTable" />
</p:column>
<p:spacer width="2px"></p:spacer>
<p:column>
<p:commandLink type="reset" value="Clear"
action="#{favoriteReportsQueries.restorePreferences}"
oncomplete="resizeiFrame()"
update="configTable" ajax="false" />
</p:column>
<p:column></p:column>
<p:column>
<p:commandLink value="Cancel"
action="#{favoriteReportsQueries.cancel}"
ajax="false" />
</p:column>
</h:panelGrid>
</h:form>
</f:view>
我实现了只返回错误消息的验证器
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;
@FacesValidator("cmecf.favoritereports.CustomValidator")
public class CustomNameValidator implements Validator{
@Override
public void validate(FacesContext context, UIComponent component,
Object value) throws ValidatorException {
FacesMessage msg =
new FacesMessage("Name already exists",
"Invalid name");
msg.setSeverity(FacesMessage.SEVERITY_ERROR);
throw new ValidatorException(msg);
}
}
当我运行此应用时,我收到此错误
<f:validator> Parent not composite component or an instance of EditableValueHolder: org.primefaces.component.column.Column@be0296
提前致谢 西
答案 0 :(得分:0)
试试这个..
<p:inputText id="reportGivenName"
value="#{repList.reportFavoriteName}" size="50">
<f:validator validatorId="cmecf.favoritereports.CustomValidator" />
</p:inputText>