0

これは私の最初の PrimeFaces プロジェクトで、Primefaces 5.2 を使用しています。リストページのroleList.xhtmlに次のようなフォーム/アクションを入れました:

<?xml version="1.0" encoding="UTF-8"?>
<!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:ui="http://xmlns.jcp.org/jsf/facelets"
  xmlns:p="http://primefaces.org/ui"
  xmlns:f="http://xmlns.jcp.org/jsf/core"
  xmlns:h="http://java.sun.com/jsf/html">
<h:head/>
<h:body>
<ui:composition template="/WEB-INF/ozssc-template.xhtml">
<ui:define name="content">
    <h3>#{clientrole['web.role.list.heading']}</h3>
    <p:toolbar>
        <p:toolbarGroup>
            <h:panelGrid columns="3">
            <p:button value="#{apps['applicaiton.nav.backtomain']}" outcome="/index.xhtml" icon="fa fa-fw fa-home" type="button"/>
            <h:form><p:commandButton value="#{clientrole['web.role.label.new']}" action="#{roleControlBean.createRole()}" icon="fa fa-fw fa-plus-square" ajax="false" type="submit"/></h:form>
            </h:panelGrid>
        </p:toolbarGroup>
    </p:toolbar>

    <p:dataTable id="rolelist" var="role" value="#{roleBean.roles}" rows="20" paginator="true" tableStyle="width:auto" resizableColumns="true" liveResize="true">
    <f:facet name="header">Size of #{clientrole['web.role.table.name']} #{roleBean.roles.size()}</f:facet>
        <!--<p:column headerText="#{clientrole['web.role.label.id']}"><h:link value="#{role.roleId}" outcome="#{roleControlBean.viewRole(role.roleId)}" /></p:column>-->
        <p:column headerText="#{clientrole['web.role.label.id']}"><h:form><h:commandLink value="#{role.roleId}"  action="#{roleControlBean.viewRole(role)}" /></h:form></p:column>
        <!--<p:column headerText="#{clientrole['web.role.label.id']}">#{role.roleId}</p:column>-->
        <p:column headerText="#{clientrole['web.role.label.name']}">#{role.roleName}</p:column>
        <p:column headerText="#{clientrole['web.role.label.desc']}">#{role.roleDescription}</p:column>
        <p:column headerText="#{clientrole['web.role.label.reportto']}">#{role.roleReportto}</p:column>
        <p:column headerText="#{clientrole['web.role.label.function']}">#{role.roleFunction}</p:column>
    </p:dataTable>
</ui:define>
</ui:composition>
</h:body>
</html>

私のバックビーンメソッドは次のとおりです。

@Named(value = "roleControlBean")
@SessionScoped
public class RoleControlBean implements Serializable{
  private static final String ROLE_EDIT="/role/roleEdit.xhtml";
  .......
  public String createRole(){
    Role newrole = new Role();
    newrole.inited();
    /*logger.info(newrole != null?newrole.toString():"no role created by constructor.");*/
    roleRemote.create(newrole);
    if (roleBean.findRoleInCache(newrole.getRoleId())!=null){
        roleBean.setCurrentRole(newrole);
    }
    return ROLE_EDIT;
  }
  .......
}

前のコードが示すように、xhtml は、バッキング Bean の createRole() メソッドを呼び出してロールを作成し、roleEdit.xhtml に移動するために押すボタンを生成します。しかし、残念ながら、roleList.xhtml にアクセスしたり更新したりするたびに. バッキング Bean メソッドが呼び出されて新しいロール オブジェクトが作成されました。つまり、ボタンを押してバッキング Bean アクションを起動することなくフォーム/アクションが実行されましたが、UI はまだ roleList.xhtml に残っています。

PrimeFaces の開発経験が豊富な人はいますか?私が間違っている点を指摘してください。

編集: このページは template.xhtml も読み込みます。リンク/結果を使用して他のページで他のバッキング メソッドを呼び出すと、再び発生します。

<p:link id="personid" value="#{clientperson['web.person.label.new']}" outcome="#{personControlBean.createPersonFromStaff(staffBean.currentStaff.staffId)}"
                               ajax="false" rendered="#{empty staffBean.currentStaff.personId}"><f:attribute name="staffId" value="#{staffBean.currentStaff.staffId}"/>
                </p:link>

私の質問は次のとおりです:ページの読み込み時にリンク/ボタンが自動起動されないようにするにはどうすればよいですか??

新規追加 私のアプリケーション サーバーは Weblogic 12cR2 です。同様の質問に対するBalusCの回答をすでに見ました。私の場合はうまくいきません。理由はわかりません。ページがロードされたときにリンケージ/ボタンが実行された理由と、それが何度も繰り返されるのを防ぐ方法をもう少し説明してください。

4

0 に答える 0