gpt4 book ai didi

java - Primefaces selectOneListbox 验证错误 : Value is not valid

转载 作者:行者123 更新时间:2023-12-01 05:29:21 25 4
gpt4 key购买 nike

我一整天都在试图解决这个问题,我用谷歌搜索了很多,我找到了答案,但我不明白为什么这对我不起作用,我尝试了我想到的一切。

我有 primefaces selectOneListbox:

    <p:selectOneListbox id="idCrawledDataSelectMenu"
required="true"
value="#{crawlerCorpusTreatmentBean.corpusId}"
converter="crawledDataConverter"
style="height: 200px; width: 500px;">
<f:selectItems id="idCrawledDataItems"
value="#{crawlerCorpusTreatmentBean.crawledDataList}"
var="crawledData"
itemLabel="#{crawledData.url}"
itemValue="#{crawledData}"/>
</p:selectOneListbox>

我有一个转换器:

@FacesConverter(value = "crawledDataConverter")
public class CrawledDataConverter implements Converter {

@Override
public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String s) {
return s;
}

@Override
public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object o) {
if (o instanceof CrawlerCorpusData) {
CrawlerCorpusData data = (CrawlerCorpusData) o;
return data.getId();
}
return null;
}
}

我有我的托管bean,我在其中形成我的crawledDataList对象。

@ManagedBean(name="crawlerCorpusTreatmentAction")
@RequestScoped
public class CrawlerCorpusTreatmentAction extends BaseAction implements Serializable {

/**
* Logger.
*/
private static final Logger LOGGER = LoggerFactory.getLogger(CrawlerCorpusTreatmentAction.class);

/**
* Processes continue action of crawled corpus treatment request.
*
* @return success if action was success, otherwise - failure
*/
public String processContinue() {
CrawlerCorpusTreatmentBean corpusTreatmentBean = getBean(Beans.CRAWLER_CORPUS_TREATMENT_BEAN);
try {
CrawlerInfoWrapper crawlerInfoWrapper = createCrawlerInfoWrapper();
List<CrawledData> crawledDataList = crawlerInfoWrapper.getCrawledData(corpusTreatmentBean.getCorpusDomain());
List<CrawlerCorpusData> corpusDataList = BeanUtils.convertCrawledDataFromPojo(crawledDataList);
corpusTreatmentBean.setCrawledDataList(corpusDataList);
return ACTION_SUCCESS;
} catch (SystemException e) {
String errorMessage = MessageFactory.getErrorString(MessageFactory.ERROR_SYSTEM_ERROR);
LOGGER.error(errorMessage, e);
addErrorMessage(errorMessage + e.getMessage());
return ACTION_FAILURE;
} catch (CrawlerInfoException e) {
String errorMessage = MessageFactory.getErrorString(MessageFactory.ERROR_CRAWLER_INFO_ERROR);
LOGGER.error(errorMessage, e);
addErrorMessage(errorMessage + e.getMessage());
return ACTION_FAILURE;
}
}

public String processChooseCorpus() {
CrawlerCorpusTreatmentBean corpusTreatmentBean = getBean(Beans.CRAWLER_CORPUS_TREATMENT_BEAN);
corpusTreatmentBean.getCorpusId();

return ACTION_SUCCESS;
}

我的 CrawlerCorpusData 对象:

public class CrawlerCorpusData {

private String id;

private String url;

public String getId() {
return id;
}

public CrawlerCorpusData() {
}

public CrawlerCorpusData(String id, String url) {
this.id = id;
this.url = url;
}

public void setId(String id) {
this.id = id;
}

public String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof CrawlerCorpusData)) {
return false;
}
CrawlerCorpusData data = (CrawlerCorpusData) obj;
return this.id == data.getId();
}
}

我尝试使用List<SelectItem> ,尝试使用selectOneMenu,尝试不使用转换器,任何成功:(

有人可以告诉我我在这里错过了什么吗?

最佳答案

selectItems 提供的值应与您的情况下的操作值 crawlerCorpusTreatmentBean.corpusId 相匹配。我会尝试

itemValue="#{crawledData.id}"

您不应该在 p:selectOneListbox 中需要任何转换器,我相信默认的数字转换器应该可以。如果您想操作完整的对象值(例如crawlerCorpusTreatmentBean.crawledData),则需要转换器。此类对象无法以明显的方式序列化,您需要提供自定义对象<->字符串转换。

编辑:如果更正的标记不起作用,则可能意味着项目列表在请求之间丢失。它存储在 corpusTreatmentBean 中,因此该 bean 的范围应该比请求更宽,例如 View。或者,可以通过将 processContinue 逻辑移动到 corpusTreatmentBean @PostConstruct 例如,在每个请求中重新创建列表。

关于java - Primefaces selectOneListbox 验证错误 : Value is not valid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9249166/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com