tags:

views:

37

answers:

1

Hi! 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.

// 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> 
A: 

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.

BalusC
dont really follow mate. i understand the reason but not the code. so i'll have two #{formBean.renderURL} ?
el_zako
The one which is used in `rendered` attribtue isn't submitted to server. The one in `h:inputHidden value` will be. This way JSF knows the original value of `renderURL`. Otherwise JSF will use its *default* value which is apparently `false`, given your problem.
BalusC