5 Replies Latest reply on May 2, 2013 11:08 PM by hq liu

    Components migration:change a4j:keepAlive to JSF 2 view scope

    hq liu Newbie

      Hello everyone: I change richfaces3.3.2GA to 4.2.2Final, 4.2.2 remove the a4j: keepAlive Label, so I changed Bean @Scope("request") to @ViewScoped, but <h: form> content can not be saved. Who can help me? Thank you. Sorry, my English is not very good.

        • 1. Re: Components migration:change a4j:keepAlive to JSF 2 view scope
          hq liu Newbie

          The following is my code snippet:

           

          sysMenuMgr.xhtml

          ......

          <rich:dataTable id="dataTable" var="data"

                                  value="#{sysMenuViewBean.list}" rows="#{sysMenuViewBean.pageSize}"

                                  style="width: 100%;" rowClasses="odd-row, even-row"

                                  styleClass="stable">

                                  <f:facet name="header">

                                      <rich:columnGroup>

                                          <rich:column breakBefore="true" style="width:5%;">

                                              <h:selectBooleanCheckbox id="checkAll"

                                                  value="#{sysMenuViewBean.allselected}" style="border:none;"

                                                  onfocus="this.blur()"

                                                  onclick="checkAllCheckboxesInTable(this.id,this.checked)" />

                                          </rich:column>

                                          <rich:column style="width:30%;">

                                              <h:outputText value="#{text['sysMenu.name']}" />

                                          </rich:column>

                                          <rich:column style="width:25%;">

                                              <h:outputText value="#{text['sysMenu.grade']}" />

                                          </rich:column>

                                          <rich:column style="width:25%;">

                                              <h:outputText value="#{text['sysMenu.status']}" />

                                          </rich:column>

                                          <rich:column style="width:15%;">

                                              <h:outputText value="#{text['system.operation']}" />

                                          </rich:column>

                                      </rich:columnGroup>

                                  </f:facet>

                                  <rich:column style="text-align:center;">

                                      <h:selectBooleanCheckbox id="id"

                                          value="#{sysMenuViewBean.selectedObj[data.id]}"

                                          onclick="cancelCheckboxesInTable(this.id,this.checked)"

                                          onfocus="this.blur()" style="border:none;" />

                                  </rich:column>

                                  <rich:column>

                                      <h:outputText value="#{data.name}" />

                                  </rich:column>

                                  <rich:column>

                                      <h:outputText value="#{constants.MENUTYPE},#{data.grade}"

                                          converter="SysCodeConverter" />

                                  </rich:column>

                                  <rich:column>

                                      <h:outputText value="#{constants.STATUSTYPE},#{data.status}"

                                          converter="SysCodeConverter" />

                                  </rich:column>

                                  <rich:column style="text-align:center;">

                                      <a4j:commandButton styleClass="button"

                                          image="/images/water/icons/ico_check.gif" action="check">

                                          <a4j:param value="#{data.id}" assignTo="#{sysMenuBean.id}" />

                                      </a4j:commandButton>

                                      <a4j:commandButton styleClass="button"

                                          image="/images/water/icons/ico_update.gif" action="update">

                                          <a4j:param value="#{data.id}" assignTo="#{sysMenuBean.id}" />

                                      </a4j:commandButton>

                                      <a4j:commandButton styleClass="button"

                                          image="/images/water/icons/ico_delete.gif"

                                          onclick="if(!checkDel()){return false;}"

                                          action="#{sysMenuBean.delete}"

                                          actionListener="#{sysMenuBean.clean}"

                                          render="dataTable,pageCounts,dataScroller,panel,odd,even,mouseover,mouseout">

                                          <a4j:param value="#{data.id}" assignTo="#{sysMenuBean.id}" />

                                      </a4j:commandButton>

                                  </rich:column>

                              </rich:dataTable>

          ......

          • 2. Re: Components migration:change a4j:keepAlive to JSF 2 view scope
            hq liu Newbie

            SysMenuBean.java

             

            @Component("sysMenuBean")

            // @Scope("request")

            @ViewScoped

            // @Scope("view")

            public class SysMenuBean extends BasePage implements Serializable {

            ......

            /**

                 * 保存对象

                 *

                 * @return

                 */

                public String save() {

                    // 关联所属角色

                    // Set<SysRole> roles = new HashSet<SysRole>();

                    // for (SysRole sysRole : selectedSysRoles) {

                    // roles.add(sysRole);

                    // }

                    // sysMenu.setRoles(roles);

                    if (StringUtil.isEmpty(sysMenu.getId())) {

                        try {

                            sysMenu.setId(null);

                            this.sysMenuManager.save(sysMenu);

                            this.setDetail(this.getText("data.save.suc"));

                        } catch (Exception e) {

                            e.printStackTrace();

                            this.setDetail(this.getText("data.save.err"));

                        }

                    } else {

                        try {

                            this.sysMenuManager.save(sysMenu);

                            this.setDetail(this.getText("data.edit.suc"));

                        } catch (Exception e) {

                            e.printStackTrace();

                            this.setDetail(this.getText("data.edit.err"));

                        }

                    }

                    return "back";

                }

             

            ......

            public SysMenu getSysMenu() {

                    if (!StringUtil.isEmpty(getId())) {

                        sysMenu = this.sysMenuManager.get(getId());

                    }

                    return sysMenu;

                }

            ......

             

            sysMenuForm.xhtml

             

            <!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"

                xmlns:h="http://java.sun.com/jsf/html"

                xmlns:f="http://java.sun.com/jsf/core"

                xmlns:ui="http://java.sun.com/jsf/facelets"

                xmlns:a4j="http://richfaces.org/a4j"

                xmlns:rich="http://richfaces.org/rich">

             

            <body>

             

                <ui:composition template="/templates/template.xhtml">

             

                    <ui:define name="title">

                        <h:outputLabel value="#{text['sysMenu.title']}" />

                    </ui:define>

             

                    <ui:define name="body">

                        <h:form id="dataForm">

                            <rich:panel styleClass="my-rich-panel">

                                <f:facet name="header">

                                    <div class="toolBarText">#{text['sysMenu.title']}</div>

                                </f:facet>

             

                                <h:inputHidden id="id" value="#{sysMenuBean.sysMenu.id}" />

                                <h:inputHidden id="parentId"

                                    value="#{sysMenuBean.sysMenu.parentId}" />

                                <table width="100%" border="0" cellspacing="1" cellpadding="0"

                                    class="tableBgcolor">

                                    <tr>

                                        <td align="right" class="rowBgcolor" width="20%"><h:outputLabel

                                                value="#{text['sysMenu.code']}" for="code" /></td>

                                        <td class="queryFormInput" width="30%"><h:inputText

                                                id="code" value="#{sysMenuBean.sysMenu.code}"

                                                styleClass="inputTextStyle" label="#{text['sysMenu.code']}"

                                                maxlength="15">

                                            </h:inputText></td>

                                        <td align="right" class="rowBgcolor" width="20%"><h:outputLabel

                                                value="#{text['sysMenu.name']}" for="name" /></td>

                                        <td class="queryFormInput" width="30%"><h:inputText

                                                id="name" value="#{sysMenuBean.sysMenu.name}"

                                                styleClass="inputTextStyle" label="#{text['sysMenu.name']}"

                                                maxlength="15">

                                                <f:validateRequired />

                                                <rich:validator />

                                            </h:inputText><span class="requiredTag">*</span> <rich:message for="name" /></td>

                                    </tr>

                                    <tr>

                                        <td align="right" class="rowBgcolor"><h:outputLabel

                                                value="#{text['sysMenu.grade']}" for="grade" /></td>

                                        <td class="queryFormInput" colspan="3"><rich:select

                                                id="grade" value="#{sysMenuBean.sysMenu.grade}"

                                                styleClass="mySelectStyle" label="#{text['sysMenu.grade']}">

                                                <f:selectItem itemValue=" "

                                                    itemLabel="#{text['system.pleaseSelect']}" />

                                                <f:selectItems value="#{sysMenuBean.sysMenuOptions}" />

                                                <f:validateRequired />

                                                <rich:validator />

                                            </rich:select><span class="requiredTag">*</span> <rich:message for="grade" /></td>

                                    </tr>

                                    <tr>

                                        <td align="right" class="rowBgcolor"><h:outputLabel

                                                value="#{text['sysMenu.path']}" for="path" /></td>

                                        <td class="queryFormInput" colspan="3"><h:inputText

                                                id="path" value="#{sysMenuBean.sysMenu.path}"

                                                styleClass="inputTextLongStyle" maxlength="50" /></td>

                                    </tr>

                                    <tr>

                                        <td align="right" class="rowBgcolor"><h:outputLabel

                                                value="#{text['sysMenu.image']}" for="image" /></td>

                                        <td class="queryFormInput" colspan="3"><h:inputText

                                                id="image" value="#{sysMenuBean.sysMenu.image}"

                                                styleClass="inputTextStyle" maxlength="50" /></td>

                                    </tr>

                                    <tr>

                                        <td align="right" class="rowBgcolor"><h:outputLabel

                                                value="#{text['sysMenu.status']}" for="status" /></td>

                                        <td class="queryFormInput" colspan="3"><h:selectOneRadio

                                                id="status" value="#{sysMenuBean.sysMenu.status}">

                                                <f:selectItem itemLabel="#{text['common.status.true']}"

                                                    itemValue="true" />

                                                <f:selectItem itemLabel="#{text['common.status.false']}"

                                                    itemValue="false" />

                                            </h:selectOneRadio></td>

                                    </tr>

                                    <tr>

                                        <td align="right" class="rowBgcolor"><h:outputLabel

                                                value="#{text['sysMenu.remark']}" for="remark" /></td>

                                        <td class="queryFormInput" colspan="3"><h:inputTextarea

                                                id="remark" value="#{sysMenuBean.sysMenu.remark}"

                                                styleClass="myInputTextarea" rows="3"

                                                label="#{text['sysMenu.remark']}">

                                                <f:validateLength maximum="150" />

                                                <rich:validator />

                                            </h:inputTextarea> <rich:message for="remark" /></td>

                                    </tr>

                                    <tr style="text-align: right">

                                        <td class="queryFormButton" height="30" colspan="4"><h:commandLink

                                                action="#{sysMenuBean.save}">

                                                <h:graphicImage value="/images/water/icons/ico_save.gif"

                                                    style="border:0;" />

                                            </h:commandLink> <h:commandLink action="back" immediate="true">

                                                <h:graphicImage value="/images/water/icons/ico_back.gif"

                                                    style="border:0;" />

                                            </h:commandLink></td>

                                    </tr>

                                </table>

             

             

                            </rich:panel>

                        </h:form>

                    </ui:define>

                </ui:composition>

            </body>

            </html>

            • 3. Re: Components migration:change a4j:keepAlive to JSF 2 view scope
              hq liu Newbie

              Please help me !

              Thank you!

              • 4. Re: Components migration:change a4j:keepAlive to JSF 2 view scope
                yanping hou Newbie

                can you use session scope then, customize the destroy function?

                1 of 1 people found this helpful
                • 5. Re: Components migration:change a4j:keepAlive to JSF 2 view scope
                  hq liu Newbie

                  Thank you, I have solved the problem. Like this:

                  ...

                  @ManagedBean

                  @ViewScoped

                  public class SysMenuBean extends BasePage implements Serializable {

                  ...

                  public SysMenuBean() {

                          this.sysMenuManager = (SysMenuManager) this

                                  .getManagerObject("sysMenuManager");

                          this.sysCodeManager = (SysCodeManager) this

                                  .getManagerObject("sysCodeManager");

                          String id = this.getRequestParameterMap("id");

                          if (id != null) {

                              sysMenu = this.sysMenuManager.get(id);

                          }

                      }

                  ...

                   

                  In the constructor to initialize the object, so that you can modify, thank you very much.

                  非常感谢