如何在表单基于请求范围bean中的值进行呈现时进行提交

问题描述 投票:2回答:1

我在我的小程序中发现了一个问题,我想知道是否有人对如何尽可能地解决这个问题有任何提示或建议。

我有bean testBean,它在请求范围内。它包含以下内容:

public class testBean {

private boolean internal = false; 
private String input = "";

public String internalTrue() {
    System.out.println("Set internal true");
    setInternal(true);
    return null;
}
public String submitForm() {
    System.out.println("");
    return null;
}
public boolean isInternal() {
    return internal;
}
public void setInternal(boolean internal) {
    this.internal = internal;
}
public String getInput() {
    return input;
}
public void setInput(String input) {
    this.input = input;
}

}

我的文件welcomeJSF.jsp包含:

    <f:view>
        <h:form>
            <h:commandButton value="Set internal true" action="#{testBean.internalTrue}" />
        </h:form>
        <h:panelGrid columns="1" rendered="#{testBean.internal}">
            <h:form>
                <h:outputText value="JavaServer Faces" /><h:inputText value="#{testBean.input}" />
                <h:commandButton value="Go" action="#{testBean.submitForm}" />
            </h:form>
        </h:panelGrid>
    </f:view>

当我运行应用程序时,我出现了“Set internal true”按钮。我点击它,然后我看到了表单,其中有“Go”按钮。单击“Go”不会触发我的bean中的方法,很可能是因为该字段实际上不再在服务器上呈现,因此它不会运行该方法。这有什么聪明的解决方案吗?

提前,谢谢你的时间。

forms jsf rendering
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.