无法保留我的输入文字

时间:2022-10-23 20:01:49

I have an input text area, inside a panel grid. This panel grid is only rendered when a check box is ticked. I'm using a value change listener to listen to the check box to render the text area. This rendering mechanism works, but the trouble is that I can't retrieve the value the user inputs in the text area. It always returns null. Any help appreciated.

我在面板网格内有一个输入文本区域。仅在勾选复选框时才会呈现此面板网格。我正在使用值更改侦听器来侦听复选框以呈现文本区域。这种渲染机制有效,但问题是我无法检索用户在文本区域中输入的值。它总是返回null。任何帮助赞赏。

// if box is checked, input text area is rendered
public void showURL(ValueChangeEvent event) {
    FacesContext context = FacesContext.getCurrentInstance();
    boolean value = (Boolean) event.getNewValue();
    setRenderURL(value);
    context.renderResponse();
}

<h:panelGrid columns="2" >
<h:outputLabel value="Is position vacant?" />
<h:selectBooleanCheckbox valueChangeListener="#{formBean.showURL}"
                 onclick="submit()"
             immediate="true" />
</h:panelGrid>

<h:panelGrid columns="2" rendered="#{formBean.renderURL}" >
<h:panelGroup>
    <h:outputLabel value="Link: "/>
            // trouble here: getURL always returns null
    <h:inputText size="60" value="#{formBean.URL}" />
</h:panelGroup>
</h:panelGrid> 

1 个解决方案

#1


0  

Add

<h:inputHidden value="#{formBean.renderURL}" />

to the same form so that the condition for the rendered attribute is retained during the request wherein input components are processed. JSF namely won't validate/convert/update an input component whenever the rendered attribute of it or one of it parents evaluates false.

以相同的形式,以便在处理输入组件的请求期间保留所呈现的属性的条件。只要输入组件的渲染属性或其中一个父组件评估为false,JSF就不会验证/转换/更新输入组件。

#1


0  

Add

<h:inputHidden value="#{formBean.renderURL}" />

to the same form so that the condition for the rendered attribute is retained during the request wherein input components are processed. JSF namely won't validate/convert/update an input component whenever the rendered attribute of it or one of it parents evaluates false.

以相同的形式,以便在处理输入组件的请求期间保留所呈现的属性的条件。只要输入组件的渲染属性或其中一个父组件评估为false,JSF就不会验证/转换/更新输入组件。