org.apache.tapestry5.ioc.util.UnknownValueException:类java.lang.String不包含属性(或公共字段)

时间:2018-07-12 09:24:44

标签: java tapestry

ViewUserRole.tml

<t:grid id="gridTable" class="t-data-grid draggable" source="userRoles" row="userRole"
rowsPerPage="100" model="userRoleModel" reorder="code,name,restrictAccount" exclude="visibleTo,id" inplace="true" t:rowClass="evenodd.next">
    <p:codeCell>
        <t:actionlink t:id="selectUserRole" t:context="userRole" t:zone="tabZone">${userRole.code}</t:actionlink>
    </p:codeCell>
    <p:actionCell>
        <t:ActionClear />
    </p:actionCell>
</t:grid>

ViewUserRole.java

package com.simantap.pages.user;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

import org.apache.tapestry5.Block;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.springframework.security.access.annotation.Secured;

import com.domain.entities.Feature;
import com.domain.entities.UserRole;
import com.domain.entities.UserRoleAuthorization;
import com.simantap.base.TabBarPage;
import com.utils.Constants;
import com.utils.TabBarItem;
import com.utils.XHR;

@Secured("ROLE_USERROLE_READ")
public class ViewUserRole extends TabBarPage {
    @Property
    private UserRole userRole;

    @Property
    @Persist
    private UserRole currentUserRole;

    @Property
    @Persist
    private List<UserRoleAuthorization> authorizations;

    @Property
    private UserRoleAuthorization authorization;

    public List<UserRole> getUserRoles() {
        return getPLPService().findAllUserRoles();
    }

    @Override
    protected void setupTabList() {
        getTabList().add(new TabBarItem(locMsg("label-authorization"), null, "Authorization", "ROLE_USERROLE_UPDATE"));
    }

    @Override
    public Block getTheBlock() {
        if (get_BlockId() == null)
            setCurrentTabEmpty();
        return getBlock(get_BlockId());
    }

    @Override
    protected void setupList() {

    }

    @Override
    protected void setupDefault() {

    }

    @XHR
    Object onActionFromSelectUserRole(UserRole userRole) {
        currentUserRole = userRole;
        return onActionFromSwitchTab(get_CurrentTab());
    }

    @XHR
    Object onActionFromSwitchTab(String tab) {
        if (currentUserRole == null)
            return SwitchToEmpty();

        if (tab.equalsIgnoreCase("Authorization"))
            return SwitchToAuthorization(currentUserRole);

        return SwitchToAuthorization(currentUserRole);
    }

    @XHR
    Object SwitchToAuthorization(UserRole userRole) {
        set_CurrentTab("Authorization");
        setupAuthorizations(userRole);
        return UpdateTabZone();
    }

    void setupAuthorizations(UserRole role) {
        if (role == null)
            return;

        UserRole myRole = getMyRole();
        if (myRole == null)
            return;

        authorizations = new LinkedList<UserRoleAuthorization>();
        List<Feature> features = getPLPService().findAllEnabledFeatures();

        for (Feature feature : features) {
            UserRoleAuthorization authorization = getPLPService().getUserRoleAuthorization(feature, role);
            if (null == authorization) {
                authorization = new UserRoleAuthorization();
                authorization.setFeature(feature);
                authorization.setUserRole(role);

                authorization.setRead(false);
                authorization.setCreate(false);
                authorization.setUpdate(false);
                authorization.setDelete(false);
            }

            if (myRole.getCode().equals(Constants.SUPER_ADMIN)) {
                authorization.setGrantRead(feature.getRead());
                authorization.setGrantCreate(feature.getCreate());
                authorization.setGrantDelete(feature.getDelete());
                authorization.setGrantUpdate(feature.getUpdate());
            }
            else {
                UserRoleAuthorization myPermission = getPLPService().getUserRoleAuthorization(feature, myRole);
                if (null == myPermission) {
                    continue;
                }

                authorization.setGrantRead(myPermission.getRead() && feature.getRead());
                authorization.setGrantCreate(myPermission.getCreate() && feature.getCreate());
                authorization.setGrantUpdate(myPermission.getUpdate() && feature.getUpdate());
                authorization.setGrantDelete(myPermission.getDelete() && feature.getDelete());
            }

            getPLPService().createOrUpdateUserRoleAuthorization(authorization);
            authorizations.add(authorization);
        }

        Collections.sort(authorizations);
    }

    @Persist
    private boolean createSelected, readSelected, updateSelected, deleteSelected;

    @XHR
    Object onActionFromReset() {
        createSelected = readSelected = updateSelected = deleteSelected = false;
        return onActionFromSelectUserRole(currentUserRole);
    }

    @XHR
    Object onActionFromAllCreate() {
        createSelected = !createSelected;
        for (UserRoleAuthorization authorization : currentUserRole.getUserRoleAuthorizations()) {
            if (getHasCreate(authorization.getFeature()))
                authorization.setCreate(createSelected);
        }
        return UpdateTabZone();
    }

    @XHR
    Object onActionFromAllRead() {
        readSelected = !readSelected;
        for (UserRoleAuthorization authorization : currentUserRole.getUserRoleAuthorizations()) {
            if (getHasRead(authorization.getFeature()))
                authorization.setRead(readSelected);
        }
        return UpdateTabZone();
    }

    @XHR
    Object onActionFromAllUpdate() {
        updateSelected = !updateSelected;
        for (UserRoleAuthorization authorization : currentUserRole.getUserRoleAuthorizations()) {
            if (getHasUpdate(authorization.getFeature()))
                authorization.setUpdate(updateSelected);
        }
        return UpdateTabZone();
    }

    @XHR
    Object onActionFromAllDelete() {
        deleteSelected = !deleteSelected;
        for (UserRoleAuthorization authorization : currentUserRole.getUserRoleAuthorizations()) {
            if (getHasDelete(authorization.getFeature()))
                authorization.setDelete(deleteSelected);
        }
        return UpdateTabZone();
    }

    public boolean getRoleEditable() {
        if (getLoggedinUser() != null)
            return getLoggedinUser().getUserRole().getCode().equals("SuperAdmin");

        return false;
    }

    @XHR
    Object onValidateFromEditAuthorizationForm() {
        try {
            for (UserRoleAuthorization auth : authorizations) {
                getPLPService().createOrUpdateUserRoleAuthorization(auth);
            }
        } catch (Exception e) {
            alertUpdateFailed(e);
            return UpdateTabZone();
        }

        alertUpdateSucceed();
        return UpdateTabZone();
    }
}

UserRole.java

package com.domain.entities;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.apache.tapestry5.beaneditor.Validate;
import org.apache.tapestry5.ioc.annotations.Inject;

@Entity
@Table(name = "user_role")
public class UserRole implements java.io.Serializable {
    private static final long serialVersionUID = 1L;

    private Integer id;
    private String code;
    private String name;
    private boolean restrictAccount;
    private String visibleTo;

    private Set<User> users = new HashSet<User>(0);
    private Set<UserRoleAuthorization> userRoleAuthorizations = new HashSet<UserRoleAuthorization>(0);

    @Inject
    public UserRole() {

    }

    @Validate("required, maxlength=30")
    @Column(name = "Code", length = 30)
    public String getCode() {
        return this.code;
    }

    @Validate("required, maxlength=50")
    @Column(name = "name", length = 50)
    public String getName() {
        return this.name;
    }

    @Validate("maxlength=200")
    @Column(name = "visibleTo", length = 50)
    public String getVisibleTo() {
        return this.visibleTo;
    }

    @Validate("required")
    @Column(name = "restrictAccount", nullable = false)
    public boolean getRestrictAccount() {
        return this.restrictAccount;
    }

    @Id
    @Validate("required")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID", unique = true, nullable = false)
    public Integer getId() {
        return this.id;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "userRole", cascade = { CascadeType.ALL })
    public Set<UserRoleAuthorization> getUserRoleAuthorizations() {
        return this.userRoleAuthorizations;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "userRole")
    public Set<User> getUsers() {
        return this.users;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setRestrictAccount(boolean restrictAccount) {
        this.restrictAccount = restrictAccount;
    }

    public void setVisibleTo(String visibleTo) {
        this.visibleTo = visibleTo;
    }

    public void setUsers(Set<User> users) {
        this.users = users;
    }

    public void setUserRoleAuthorizations(Set<UserRoleAuthorization> userRoleAuthorizations) {
        this.userRoleAuthorizations = userRoleAuthorizations;
    }
}

我得到了这个例外:

  

页面用户/ ViewUserRole的异常组装根组件:可以   不能将“ userRole.code”转换为组件参数绑定:   表达式'userRole.code'的异常生成管道:类   java.lang.String不包含名为的属性(或公共字段)   “代码”。

0 个答案:

没有答案