2015-09-18 121 views
0

我想添加一個inputText字段到我的primefaces pickList,但我有一些問題。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

從來沒有打算這樣使用。一般來說,將控件嵌入到選取列表中並不常見(至少我從未見過它)。另請參閱http://stackoverflow.com/questions/32489834/how-do-i-embed-a-primefaces-selectonemenu-into-a-picklist – Kukeltje

回答

0

領料一般不在傾向於包含「控制」。所以它從來沒有被設計成以這種方式工作,如果它不起作用,那只是不幸的。重新設計你的用戶界面是唯一要做的事情。

+0

我會解決它..重構它到一個dataTable .. – GregD