JSF(seam)如何在没有表单提交的情况下更改组合框内容

时间:2023-02-04 20:09:16

I have a form to enter information including 3 field

我有一个表格输入信息,包括3个字段

  1. textbox user name (requiere=true)
  2. 文本框用户名(requiere = true)
  3. Combobox bank name (requiere=true)
  4. 组合框银行名称(requiere = true)
  5. Combobox bank branches (requiere=true)
  6. Combobox银行分行(requiere = true)

I want when the user selects the bank, the bank branch will load without filling out form (particular user does not need to fill in the textbox: "user name")

我想当用户选择银行时,银行分行将加载而不填写表格(特定用户不需要填写文本框:“用户名”)

For example : my xhmtl form

例如:我的xhmtl表单

<h:form id="ftextform">
    <s:validateAll id="ValidateAll">
        <fieldset>

            <div class="entry">
                <h:outputLabel for="name" styleClass="label #{invalid?'errors':''}">name<em>*</em></h:outputLabel>
                <h:inputText id="name" value="#{branch.name}" required="true" />
            </div>

            <div class="entry">
                <h:selectOneMenu id="creditBank" value="#{branch.creditBank}" immediate="true">
                    <f:selectItems value="#{fExtBankList}"></f:selectItems>
                    <a:support id="onkeyup" event="onchange" actionListener="#{branch.creditBankchange}" reRender="searchResults"/>
                </h:selectOneMenu>
            </div>

            <a:outputPanel id="searchResults">
            <div class="entry">
                <h:selectOneMenu id="creditBankBranch" value="#{branch.creditBankBranch}">
                    <f:selectItems value="#{branch.creditBankBranchList}"></f:selectItems>
                </h:selectOneMenu>
            </div>
            </a:outputPanel>

        </fieldset>

        <fieldset>
            <div class="buttonBox">
                <h:commandButton id="check" value="Cancel" action="#{branch.cancel}" immediate="true"/>
                &#160;
                <h:commandButton id="next" value="Next" action="#{branch.next}"/>
            </div>
        </fieldset>

    </s:validateAll>
</h:form>

my bean :

我的豆子:

@Name("branch")
public class Branch implements IBranch
{

    private static int count = 0;
    private String creditBank;
    private String creditBankBranch = "aaa";
    private String name;

    private  List<SelectItem> creditBankBranchList = new ArrayList<SelectItem>();

    // action
    public void creditBankchange()
    {
        SelectItem e = new SelectItem(creditBank + count, creditBank);
        creditBankBranchList.add(e);
    }
....

1 个解决方案

#1


1  

the simple answer is to use <a4j:region>

简单的答案是使用 :region>

details:

细节:

view(xhtml)

视图(XHTML)

<h:form id="ftextform">

        <fieldset>

            <div class="entry">

                <h:outputLabel for="name" styleClass="label #{invalid?'errors':''}">name<em>*</em></h:outputLabel>
                <h:inputText id="name" value="#{branch.name}" required="true">
                    <s:validate/>

                </h:inputText>
                <div class="errors"><h:message for="name"/></div>
            </div>

            <a:region>
                <div class="entry">
                    <h:selectOneMenu id="creditBank" value="#{branch.creditBank}" immediate="true" >
                        <f:selectItems value="#{branch.creditBankList}"></f:selectItems>
                        <a:support status="globalStatus" event="onchange" reRender="searchResult"
                                    action="#{branch.creditBankchange}"/>
                    </h:selectOneMenu>
                    <div class="errors"><h:message for="creditBank"/></div>
                </div>

                <s:div style="width: 300px" id="searchResult"  immediate="true">
                    <h:selectOneMenu id="creditBankBranch" value="#{branch.creditBankBranch}" >
                        <f:selectItems value="#{branch.creditBankBranchList}"></f:selectItems>
                    </h:selectOneMenu>
                    <div class="errors"><h:message for="creditBankBranch"/></div>
                </s:div>
            </a:region>

        </fieldset>

        <fieldset>
            <div class="buttonBox">
                <h:commandButton id="check" value="Cancel" action="#{branch.cancel}" immediate="true"/>
                &#160;
                <h:commandButton id="next" value="Next" action="#{branch.next}"/>
            </div>
        </fieldset>
</h:form>

and bean:

和豆:

public class Branch implements IBranch
{
    private String creditBank;
    private String creditBankBranch;
    private String name;

    private  List<SelectItem> creditBankBranchList = new ArrayList<SelectItem>();
    private  List<SelectItem> creditBankList = extBankList();

    // action
    public void creditBankchange()
    {
        extBankBranchList();
    }

    // (test)create test banks list
    private List<SelectItem>  extBankList()
    {
        List<SelectItem> list = new ArrayList<SelectItem>();
        for(int i =0; i < 10; i ++)
        {
            list.add(new SelectItem(i, Integer.toString(i)));
        }

        return list;
    }

    // (test)load bank branchs list from bank
    private void extBankBranchList()
    {
        this.creditBankBranchList.clear();
        for(int i =0; i < 10; i ++)
        {
            this.creditBankBranchList.add(new SelectItem(i, "bank " + this.creditBank + "branch " + Integer.toString(i) ));
        }
    }

#1


1  

the simple answer is to use <a4j:region>

简单的答案是使用 :region>

details:

细节:

view(xhtml)

视图(XHTML)

<h:form id="ftextform">

        <fieldset>

            <div class="entry">

                <h:outputLabel for="name" styleClass="label #{invalid?'errors':''}">name<em>*</em></h:outputLabel>
                <h:inputText id="name" value="#{branch.name}" required="true">
                    <s:validate/>

                </h:inputText>
                <div class="errors"><h:message for="name"/></div>
            </div>

            <a:region>
                <div class="entry">
                    <h:selectOneMenu id="creditBank" value="#{branch.creditBank}" immediate="true" >
                        <f:selectItems value="#{branch.creditBankList}"></f:selectItems>
                        <a:support status="globalStatus" event="onchange" reRender="searchResult"
                                    action="#{branch.creditBankchange}"/>
                    </h:selectOneMenu>
                    <div class="errors"><h:message for="creditBank"/></div>
                </div>

                <s:div style="width: 300px" id="searchResult"  immediate="true">
                    <h:selectOneMenu id="creditBankBranch" value="#{branch.creditBankBranch}" >
                        <f:selectItems value="#{branch.creditBankBranchList}"></f:selectItems>
                    </h:selectOneMenu>
                    <div class="errors"><h:message for="creditBankBranch"/></div>
                </s:div>
            </a:region>

        </fieldset>

        <fieldset>
            <div class="buttonBox">
                <h:commandButton id="check" value="Cancel" action="#{branch.cancel}" immediate="true"/>
                &#160;
                <h:commandButton id="next" value="Next" action="#{branch.next}"/>
            </div>
        </fieldset>
</h:form>

and bean:

和豆:

public class Branch implements IBranch
{
    private String creditBank;
    private String creditBankBranch;
    private String name;

    private  List<SelectItem> creditBankBranchList = new ArrayList<SelectItem>();
    private  List<SelectItem> creditBankList = extBankList();

    // action
    public void creditBankchange()
    {
        extBankBranchList();
    }

    // (test)create test banks list
    private List<SelectItem>  extBankList()
    {
        List<SelectItem> list = new ArrayList<SelectItem>();
        for(int i =0; i < 10; i ++)
        {
            list.add(new SelectItem(i, Integer.toString(i)));
        }

        return list;
    }

    // (test)load bank branchs list from bank
    private void extBankBranchList()
    {
        this.creditBankBranchList.clear();
        for(int i =0; i < 10; i ++)
        {
            this.creditBankBranchList.add(new SelectItem(i, "bank " + this.creditBank + "branch " + Integer.toString(i) ));
        }
    }