【问题标题】:How to return value from backing bean as composite component attribute如何从支持 bean 返回值作为复合组件属性
【发布时间】:2014-11-07 03:07:55
【问题描述】:

我有以下 JSF 复合组件:

<composite:interface componentType="myComp">
    <composite:attribute name="input" type="java.lang.Integer" />
    <composite:attribute name="output" type="java.lang.Integer" />
    <composite:attribute name="action" method-signature="java.lang.String action()"/>
</composite:interface>
<composite:implementation>
    <h:inputText id="input" value="#{cc.attrs.input}" />
</composite:implementation>

假设复合被调用为

<h:form id="form">
    <cc:myComposite id="cc" input="#{bean.input}" 
                    output="#{bean.output}" action="#{bean.action}"  />
</h:form>

一旦调用bean.action,它就会在bean.output 中设置一个值。我需要在我的 javascript 中访问这个值,就像这样

document.getElementById('form:cc:output').value

从 myComp 我可以设置属性

getAttributes().put("output", output); 

但数据驻留在支持 bean 中。有什么想法吗?

【问题讨论】:

    标签: jsf composite-component


    【解决方案1】:

    您需要一个组件来将“输出”值提交给支持 bean。使用 inputHidden 来完成:

    <composite:interface componentType="myComp">
      <composite:attribute name="input" type="java.lang.Integer" />
      <composite:attribute name="output" type="java.lang.Integer" />
      <composite:attribute name="action" method-signature="java.lang.String action()"/>
    </composite:interface>
    <composite:implementation>
      <h:inputText id="input" value="#{cc.attrs.input}" />
      <h:inputHidden id="output" value="#{cc.attrs.output}" />
    </composite:implementation>
    

    然后您就可以通过 javascript 使用其隐藏的输入元素设置“输出”值。

    【讨论】:

    • 您的意思是通过javascript设置输出属性还是检索它?我正在寻找后者,例如var x = document.getElementById('form:cc:output').value;
    猜你喜欢
    • 2015-02-26
    • 2011-07-24
    • 2012-06-19
    • 2011-10-16
    • 2011-11-01
    • 2012-09-03
    • 2012-04-01
    • 2011-06-29
    • 2012-07-20
    相关资源
    最近更新 更多