我试图在我的primefaces pickList中添加一个inputText字段,但是我遇到了一些问题。
首先:我无法通过正常的左键单击在textField中写入。我必须右键单击才能输入textField。
第二:它似乎没有将textField中的值保存到相应的实体。
我的情况:
<h:form id="pickListForm">
<p:pickList converter="primeFacesPickListConverter" id="pickList" value="#{locodeBackingBean.locodes}"
var="locode" showCheckbox="true"
itemValue="#{locode.id}">
<f:facet name="sourceCaption">#{msgs['locode.not.infected']}</f:facet>
<f:facet name="targetCaption">#{msgs['locode.infected']}</f:facet>
<p:column style="width:70%;">
<h:outputText value="#{locode.description}"/>
</p:column>
<p:column style="width:30%">
<p:inputText value="#{locode.incubationPeriod}"/>
</p:column>
</p:pickList>
<p:commandButton value="#{msgs.save}" action="#{locodeBackingBean.save()}" update="growl"/>
</h:form>
我的支持bean:
@ManagedBean
@ViewScoped
public class LocodeBackingBean implements Serializable {
private static final long serialVersionUID = 1L;
@Inject
private transient LocodeRepositoryBean locodeRepository;
private DualListModel<Locode> locodes = new DualListModel<>();
public void save() {
for (Locode locode : locodes.getTarget()) {
locode.setInfectedArea(true);
locodeRepository.save(locode);
}
for (Locode locode : locodes.getSource()) {
locode.setInfectedArea(false);
locodeRepository.save(locode);
}
addFacesMessage("locode.action.saved");
}
@PostConstruct
public void search() {
List<Locode> source = locodeRepository.findAllNotInfected(locodeSearchCriteria);;
List<Locode> target locodeRepository.findAllInfected(locodeSearchCriteria);
locodes.setSource(source);
locodes.setTarget(target);
}
public DualListModel<Locode> getLocodes() {
return locodes;
}
public void setLocodes(DualListModel<Locode> locodes) {
this.locodes = locodes;
}
要完成,我的转换器:
@FacesConverter(value = "primeFacesPickListConverter")
public class PrimeFacesPickListConverter<T extends Domain> implements Converter {
@Override
public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
if (arg1 instanceof PickList) {
Object dualList = ((PickList) arg1).getValue();
DualListModel dl = (DualListModel) dualList;
for (Object o : dl.getSource()) {
if (equalsById(arg2, o)) return o;
}
for (Object o : dl.getTarget()) {
if (equalsById(arg2, o)) return o;
}
}
throw new PrimeFacesPickListConverterException("Could not match object's id (" + arg2 + ") to any id's in the list.");
}
private boolean equalsById(String arg2, Object o) {
String id = String.valueOf((((T) o)).getId());
return arg2.equals(id);
}
@Override
public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
return String.valueOf(arg2);
}
使用PrimeFaces 5.2
答案 0 :(得分:0)
一般情况下,选择列表不包含“控件”。所以从来没有设计过以这种方式工作,如果它不起作用,那就太不幸了。重新设计你的ui是唯一要做的事情。