0

我试图遵循f:param 或 f:attribute 对 primefaces 自动完成的支持中的解决方案?将参数传递给 primefaces 3.3.1 自动完成组件但没有成功。如果我在 UIComponent.getCurrentComponent().getAttributes 返回的 Map 中进行迭代,它不包含我在 .xhtml 文件中设置的属性名称,因此当我尝试获取该属性时会得到一个空指针。在上述解决方案之后,primefaces 的实现是否有任何变化?

我将 Eclipse Indigo 与 Glassfish 3.1.2 和 Mojarra 2.0.9 一起使用。

我的部分代码

html:

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

...

<p:autoComplete 
   id="sourceSubMemberLookup" value="#{transactionTransferBacking.sourceSubMember}"
   size="64"
   completeMethod="#{transactionTransferBacking.completeSourceOpSubMember}"
   var="smb" itemLabel="#{smb.displayText}" itemValue="#{smb}"
   converter="opSubMemberConverter"
   forceSelection="true" dropdown="true"
   required="true" rendered="#{loggedInUser.subMemberType eq 1}" >
       <f:attribute name="attrSourceMemberId" value="#{transactionTransferBacking.sourceMember.Id">
</p:autoComplete>

...

</ui:composition>

爪哇:

package com.mysoft.backing;

import java.io.Serializable;
import javax.faces.context.FacesContext;
import javax.faces.context.Flash;
import javax.servlet.http.HttpServletRequest;
import javax.enterprise.context.RequestScoped;

@Named
@ManagedBean
@RequestScoped
public class TransactionTransferBacking implements Serializable {

...

public List<OpSubMember> completeSourceOpSubMember(String query) {
    List<OpSubMember> members=null;

    //Retrieve list of submembers based on partial user input (autocomplete)
    //Based on loggedInUser own member's memberId

    FacesContext context = FacesContext.getCurrentInstance();

    if (context==null) this.getLogger().debug("completeSourceOpSubMeber: faces is null");

    UIComponent current = UIComponent.getCurrentComponent(context);

    this.getLogger().debug("completeSourceOpSubMember: currentComponent="+current.getId());

    //Map<Object, Object> attrMap = context.getAttributes();
    Map<String, Object> attrMap = current.getAttributes();

    for (Map.Entry entry : attrMap.entrySet()) {
        this.getLogger().debug("completeSourceOpSubMember: attrMap.Key="+entry.getKey());
    }

    int memberId = (int) attrMap.get("attrSourceMemberId");

    this.getLogger().debug("completeSourceOpSubMember: MemberId from attribute = "+memberId);


            ...

    return members;
}
}

日志正确地将当前组件名称打印为所需的 AutoComplete,但问题是“attrSourceMemberId”不在“attrMap”映射中,如日志中打印的那样。

感谢你们。

4

0 回答 0