6 Replies Latest reply on Feb 24, 2014 3:47 AM by Adrian Los

    It is possible to clear h:inputText with h:commandButton?

    Adrian Los Newbie

      Hello forumers,


      Id like to clear the h:inputText after the actionaction="#{menuManager.insertMainMenuGroup()}".

      Here is a piece of my .xhtml page:

      <h:panelGrid columns="3">
        <h:outputLabel value="Main Menu:" for="mainMenuGroupName" />
        <h:inputText value="#{mainMenuGroupView.mainMenuGroupName}" id="mainMenuGroupName">
         <rich:validator />
        <rich:message for="mainMenuGroupName" id="msgMainMenuGroupName" />

      <h:commandButton id="btn" value="Submit" action="#{menuManager.insertMainMenuGroup()}" >
        <f:ajax event="click" render="mainMenuGroupName" listener="#{mainMenuGroupView.mainMenuGroupNameListener}" />

      <rich:notifyMessages stayTime="2500" nonblocking="true" />


      And a piece of the view code:


      class MainMenuGroupView {...
      public void mainMenuGroupNameListener(AjaxBehaviorEvent event) {
      this.mainMenuGroupName = "";


      If i delete the f:ajax tag, the data will instert to the database, and my class send a succes facemessage. But now with f:ajax tag the commandButton will be cleared, but the data wont be inserted to the database.


      What am i doing wrong?

      Does someone have any idea how to change this code?

      Thank you in advance for any help you can provide.

        • 1. Re: It is possible to clear h:inputText with h:commandButton?
          Siva P Master



          For your issue try using,

          render attribute(specify the component id need to be cleared )

          Any of the keywords "@this", "@form", "@all", "@none" may be specified in the identifier list.


          IF you are using ajax library or Seam means we have different options to clear it after updating.Like on complete.




          • 2. Re: Re: It is possible to clear h:inputText with h:commandButton?
            Adrian Los Newbie

            Dear Siva,


            I tried use the render attribute, but I don't know well how should I use it. Here is my xhtml page.

            I'd like to when I click on the bti_ci button all inputtext and selection be clear, and the default.


            Thank you,



            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
            <html xmlns="http://www.w3.org/1999/xhtml"
            <ui:composition template="/resources/master.xhtml">
             <ui:define name="title">Create category</ui:define>
             <ui:define name="content">
             <div id="additem">
             <h:form id="hfrom1">
             <f:facet name="header">
             <h:outputText value="Create category group" />
             <h:panelGrid columns="3">
             <h:outputLabel value="Main Category:" for="categoryGroupName" />
             <h:inputText value="#{categoryGroupView.categoryGroupName}"
             <rich:validator />
             <rich:message for="categoryGroupName" id="msgCategoryGroupName" />
             <h:commandButton id="btn_mc" value="Submit"
             action="#{categoryManager.insertCategoryGroup()}" />
             <rich:notifyMessages stayTime="2500" nonblocking="true" />
             <p />
             <br />
             <h:form id="hfrom2">
             rendered="#{fn:length(categoryManager.listCategoryGroups_mg) > 0}">
             <f:facet name="header">
             <h:outputText value="Create category item" />
             <f:facet name="start">
             <h:graphicImage value="/images/ai.gif"
             style="height:12px;width:12px;" alt="ai" />
             <h:panelGrid columns="3">
             <h:outputLabel value="Main Category Group" for="categoryGroup" />
             <rich:select enableManualInput="false"
             validatorMessage="Required to choose one Category Group."
             defaultLabel="Click here to select" id="categoryGroup"
             <f:selectItems value="#{categoryManager.listCategoryGroups_si}" />
             <f:validateLongRange minimum="1" maximum="99" />
             <f:validateRequired />
             <rich:message for="categoryGroup" id="msgCategoryGroup" />
             <h:outputLabel value="Add a category item:" for="categoryItem" />
             <h:inputText value="#{categoryItemView.categoryItemName}"
             <rich:validator />
             <rich:message for="categoryItem" id="msgCategoryItem" />
             <h:commandButton id="btn_ci" value="Submit" render="additem"
             action="#{categoryManager.saveCategoryItemToCategoryGroup}" >
             <a4j:jsFunction name="begin" render="additem" /></h:commandButton>
             <p />
             <rich:messages ajaxRendered="true" />
            • 3. Re: It is possible to clear h:inputText with h:commandButton?
              liumin hu Master

              1. I think listener is called before action.

              2. h:commandbutton dont do ajax thing, a4j:commandbutton is better.

              3 why a4j:jsfuncion is nested by h:commandbutton?

              • 4. Re: It is possible to clear h:inputText with h:commandButton?
                Adrian Los Newbie

                Dear liumin hu,


                Yes, you right, the listener called before the action, this is a reason why I deleted the actionlistener already. I tried to do something with ajax is nesting the a4j:jsfunction by h:commandbutton. I'll try with a4j:commandbutton as you suggest.




                • 5. Re: It is possible to clear h:inputText with h:commandButton?
                  liumin hu Master

                  I think what you need is put your code of listener at the end of your code of action if your backingbean is viewscope or upper.


                  h:commandbutton + f:ajx = aj4:commandbutton.


                  IMAO a4j:jsfunction is needed for some special situation.

                  • 6. Re: Re: It is possible to clear h:inputText with h:commandButton?
                    Adrian Los Newbie



                    Sorry for my late answer, I've tried this

                    <a4j:commandButton id="btn_mc" value="Save" action="#{categoryManager.insertCategoryGroup()}" event="click" execute="@none" render="categoryGroupName"/>

                    but still doesn't work well. I'm so newbie about this, but I find another way to solve this.

                    Well, at the action, in the insertCategoryGroup() method I've added this line:




                    Well, I think it is not the pretty solution, but it works for now.

                    Maybe I'll see another way later,