jsf - primefaces - 将参数传递给primefaces自动完成

时间:2012-07-02 15:42:33

标签: jsf jsf-2 primefaces

我尝试按照f:param or f:attribute support on primefaces autocomplete?中的解决方案将参数传递给primefaces 3.3.1自动完成组件但没有成功。如果我通过UIComponent.getCurrentComponent()。getAttributes迭代Map返回,它不包含我在.xhtml文件中设置的属性名称,所以当我尝试获取属性时,我得到一个空指针。在上述解决方案之后,primefaces实现是否有任何变化?

我正在使用Eclipse Indigo和Glassfish 3.1.2以及Mojarra 2.0.9。

我的部分代码

xhtml:

<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>

java:

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;
}
}

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

谢谢你们,伙计们。

0 个答案:

没有答案