0

我在尝试从 p:galleria 组件内部创建命令链接时遇到问题问题是尽管事实上在运行时链接值value="Show present #{present.name} #{present.presentId}"包含正确的 id 值作为示例value="Show present Foo 1",当按下命令链接时它发送第二个错误的 id每次都反对

<h:form>
    <p:galleria value="#{presentBean.allPresentList}" var="present" panelWidth="500" panelHeight="313" showCaption="true">  
        <f:facet name="content">
            <h:commandLink value="Show present #{present.name} #{present.presentId}"                   action="pretty:present" actionListener="#{presentBean.setPresentObj}">
                <f:attribute name="present" value="#{present.presentId}"/>
              </h:commandLink>
        </f:facet>
    </p:galleria> 
</h:form>

@ManagedBean(name="presentBean")
@SessionScoped
public class PresentBean implements Serializable{

    ArrayList<Present> allUserPresentList = new ArrayList<Present>();

    @PostConstruct
    private void usersPresent(){
        PresentDao presentDao = new PresentDaoImpl();
        allPresentList = (ArrayList<Present>) presentDao.findAllPresents();
    }

    public ArrayList<Present> getAllUserPresentList() {
        return allUserPresentList;
    }

    public void setAllUserPresentList(ArrayList<Present> allUserPresentList) {
        this.allUserPresentList = allUserPresentList;
    }

    private String presentId ;

    public String getPresentId() {
        return presentId;
    }

    public void setPresentId(String presentId) {
        this.presentId = presentId;
    }

    public void setPresentObj(ActionEvent ev){
        Object presentOb = ev.getComponent().getAttributes().get("present");
        if(presentOb != null){
            this.presentId = (String) presentOb;
        }else{
            presentId = null ;
        }
    }
}

有可能,您需要查看设备规范,看看如何。有时您只需要进行直接 x/系统调用,其余的将由 windows 处理,或者您需要包装驱动程序并通过它进行对话。但是这里恐怕没有简单的答案,这完全取决于具体的卡,它的驱动程序。

因此,要么发布卡片规格,要么对其进行一些研究。

4

1 回答 1

1

您需要使用 setPropertyActionListener 而不是<f:attribute name="present" value="#{present.presentId}"/>f:attribute 标记仅在创建组件时评估(仅一次),而不是在组件基于迭代行生成 html 时评估。

所以你需要改为使用:

 <f:setPropertyActionListener target="#{presentBean.presentId}" value="#{present.presentId}" />

这将在您的托管 bean 中设置 presentId 的值,因此在您的操作方法中,您可以直接访问 presentId 本身,而无需解决它。

或者,如果您使用更高版本的 JSF(使用 Servlet 3.0 或更高版本),那么您可以在托管 bean 中创建一个方法,该方法将 presentId 甚至当前对象作为参数

例如在您的托管 bean 中:

 public void myAction(Present p){
       //do whatever you want with the Present object
    }

在你的 .xhtml 中:

<h:commandLink value="Show present #{present.name} #{present.presentId}"         actionListener="#{presentBean.myAction(present)}">
</h:commandLink>
于 2013-06-12T22:09:18.183 回答