1

次のような問題があります。

問題なくロールを追加できますが、削除または編集する必要がある場合、roleController.selectedRolenullであるため機能しません。最初はマネージド Bean を requestScope として持っていましたが、すべてのリクエストで Bean が再作成されるため、null がそこから来ている可能性があります。そのため、ViewScoped に変更して追加ボタンが再び機能するように修正しましたが、それでも編集と削除で同じ問題が発生します。

何が起こっているかは次のとおりです。行を選択し、編集ボタンをクリックします。これにより、ロール情報を含むダイアログが正しく表示されます。しかし、編集をクリックすると、null 値が表示されます。私はいくつかの例を見てきましたが、私は何も悪いことをしていないようです。しかし、私は本当に基本的な何かが欠けているかもしれません:/

どんな洞察も大歓迎です!

Beanに関しては、次のものがあります。

@ManagedBean
@RequestScoped
....
private Roles selectedRole = new Roles();
(I have the normal setter and getter)
    public void edit() {
        Logger.getGlobal().log(Level.INFO, "====> EDIT ROLE" + selectedRole.getRole());
    }

ページは ui:define とヘッダーのことを省略して次のようになります。

<h:form id="contentView">
    <p:dataTable id="lstRoles" var="r" value="#{roleController.rolesList}" selectionMode="single" 
                 selection="#{roleController.selectedRole}" rowKey="#{r.role}" paginator="true"
                 paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {CurrentPageReport}  {RowsPerPageDropdown}"
                 rowsPerPageTemplate="10,15,50" rows="10">
        <p:column headerText="Role" sortBy="#{r.role}">
            <p:outputLabel value="#{r.role}"></p:outputLabel>
        </p:column>
        <p:column headerText="Description">
            <h:outputLabel value="#{r.description}"></h:outputLabel>
        </p:column>                
        <f:facet name="footer">
            <p:commandButton value="New" icon="ui-icon-star" oncomplete="newRoleDialog.show()"></p:commandButton>
            <p:commandButton value="Edit" icon="ui-icon-check" oncomplete="editRoleDialog.show()" update=":editRoleForm:editRolePanel"></p:commandButton>
            <p:commandButton value="Delete" icon="ui-icon-trash"></p:commandButton>
        </f:facet>
    </p:dataTable>
    <p:blockUI block="lstRoles" trigger="lstRoles">
        LOADING 
    </p:blockUI>
</h:form>

<!-- Edit User -->
<p:dialog header="Edit User" widgetVar="editRoleDialog" resizable="false">
    <h:form id="editRoleForm">
        <p:panelGrid id="editRolePanel" columns="2">
            <h:outputText value="Role: "></h:outputText>
            <h:outputText value="#{roleController.selectedRole.role}"></h:outputText>

            <h:outputText value="Description: "></h:outputText>
            <p:inputText value="#{roleController.selectedRole.description}" required="true"></p:inputText>

            <f:facet name="footer">
                <p:commandButton value="Confirm" update=":contentView:lstRoles :growl" oncomplete="handleSubmitRequest(xhr, status, args, 'editRoleDialog','editRoleForm');" actionListener="#{roleController.edit()}"></p:commandButton>
                <p:commandButton type="reset" value="reset"></p:commandButton>
            </f:facet>
        </p:panelGrid>
    </h:form>
</p:dialog>

編集:私はプライムフェイス3.5でGlassfish 3.1を使用しています

編集 2:だから、私は出力ラベルを使用できないようです。入力に変更すると、マネージド Bean で必要な値を取得します (行を選択するときに既に処理されていると思いますが、セッターを呼び出すためだと思います)。しかし、これは PK キーであり、テーブルでは FK としても使用されるため、最初のフィールドは編集したくありません。しかし、少なくとも何が起こっているか、多かれ少なかれ知っていることを知っています。

4

2 に答える 2

1

データテーブルから選択されたロールをマネージド Bean の selectedrole 属性に設定する必要があります。これを試してください。

<p:commandButton value="Edit" icon="ui-icon-check" oncomplete="editRoleDialog.show()" update=":editRoleForm:editRolePanel">
    <f:setPropertyActionListener target="#{roleController.selectedRole}" value="#{r}"/>
</p:commandButton>

ほとんどの場合、Bean も ViewScoped にする必要があります。

編集:上記のコードが必要ないことを使用しているかどうかを明確にするために、datatableの選択機能について知りませんでした。

于 2013-02-23T14:55:05.930 に答える
-1

inputtext のvalueChangeListener属性を試してください。通常、 @SessionScopeにエンティティの一部を含めるのは非常に困難です。使用すれば確実に機能します

<inputText value="#{bean.value}"/>

ただし、使用すると機能しない場合があります

<inputText value="#{bean.entity.value}"/>

. valueChangeListenerを使用して、このようなメソッドを作成すると、エンティティの値を強制的に保存できます。

public void saveValue(ValueChangeEvent event) {
        Integer newValue = (Integer) event.getNewValue();//u can use getOldValue to get value before
        entity.setValue(newValue);
    }

幸運を!

于 2013-03-18T08:39:34.020 に答える