2017-06-17 51 views
2

我复合组件包含以下形式获取备份组件形式的数据?我在支持bean中重写了processUpdates方法,尝试了以下内容。从复合组件

Answer ItemSource = (Answer) getValueExpression("ItemSource").getValue(context.getELContext()); 
String formid = String.format("sc%d", ItemSource.getAnswerId()); 
String get = context.getExternalContext().getRequestParameterMap().get(formid); 

String get始终为空。有没有办法获得输入的价值?

PS:我知道在jsf中使用纯html并不是它的目的。我只是想知道我的计划是如何实现的。

回答

3

我从来没有使用纯jsf属性的纯html,所以我不知道它是否适用。

一般来说,这是访问在复合嵌套组件的常用方法:

<cc:interface componentType="answerCompositeComponent"> 
    <cc:attribute name="AnswerType" type="code.elephant.domainmodel.AnswerType" required="true" /> 
    <cc:attribute name="ItemSource" type="code.elephant.domainmodel.Answer" required="true" /> 
    <cc:attribute name="QuestionId" type="java.lang.Long" required="true" /> 
</cc:interface> 
<cc:implementation> 
    <h:inputText id="questionInput" binding="#{cc.input}" /> 

    <!-- maybe something like this might work 
     <input jsf:id="questionInput" jsf:binding="#{cc.input}" /> 
    --> 
</cc:implementation> 

其中

@FacesComponent("answerCompositeComponent") 
public class AnswerCompositeComponent extends UINamingContainer 
{ 
    private UIInput input; 

    @Override 
    public void processUpdates(FacesContext context) 
    { 
     super.processUpdates(context); 

     Object value = input.getValue(); 
     Object localValue = input.getLocalValue(); 
     Object submittedValue = input.getSubmittedValue(); 

     // do your things with values 
    } 

    public UIInput getInput() 
    { 
     return input; 
    } 

    public void setInput(UIInput input) 
    { 
     this.input = input; 
    } 
} 

注意,复合背衬部件是NamingContainer,因此比较喜欢静态的(或无所有)嵌套的组件ID。避免使用动态ID,除非你真的需要它们,而且你确切知道你在做什么。

+0

非常感谢!这对我行得通。不要这样。没有,如果它与问题有关 - 有没有办法告诉jsf使用id属性而不是name属性?我在这里列出了我需要用属性名称进行分组的无线电输入列表。 – Briefkasten

+0

对于UIInput组件,JSF将** * id *和* name *设置为生成的html中的相同值。 html输入* name *属性是html容器*

*本身所必需的,否则它不知道在提交请求中哪些键值对以及如何传递键值对。也许我误解了你在问什么? –

+0

Ahokay。是否也可以在processUpdates方法中获取组合组件的生成html代码并搜索' Briefkasten