1

我在primefaces有一个戒指:

    <h:form>
        <p:ring id="ring" value="#{ringBean.images}" var="image"
                styleClass="image-ring" easing="easeInOutBack">
            <p:graphicImage value="./../../images/#{image.image}" width="150" height="150"/>
            <p:commandButton value="#{image.name}" action="#{image.action}" />
        </p:ring>
    </h:form>

我的环豆:

@ManagedBean
@RequestScoped
public class RingBean implements Serializable{ 

    private List<PersonImage> images;
    private PersonImage selectedPerson;

    public RingBean() {
        images = new ArrayList<PersonImage>();
        images.add(new PersonImage("person3.png", "Pacjent", "patientList"));
        images.add(new PersonImage("person4.png", "Admin", "adminList"));
        images.add(new PersonImage("person5.png", "Lekarz", "doctorList"));
        images.add(new PersonImage("person6.png", "Sekretarka", "secretaryList"));
        images.add(new PersonImage("person7.png", "Nieaktywni", "inactiveList"));
    }

    public List<PersonImage> getImages() {
        return images;
    }       

    public PersonImage getSelectedPerson() {
        return selectedPerson;
    }

    public void setSelectedPerson(PersonImage selectedPerson) {
        this.selectedPerson = selectedPerson;
    }

}

人物图像类:

public class PersonImage {

    String image;
    String name;
    String action;

    public PersonImage() {
    }

    public PersonImage(String image, String name, String action) {
        this.image = image;
        this.name = name;
        this.action = action;
    }

    public String getImage() {
        return image;
    }

    public void setImage(String image) {
        this.image = image;
    }

    public String getName() {
        return name;
    }

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

    public String getAction() {
        return action;
    }

    public void setAction(String action) {
        this.action = action;
    }

}

面孔配置:

<navigation-case>
            <from-outcome>adminList</from-outcome>
            <to-view-id>/protected/admin/adminList.xhtml</to-view-id>
            <redirect/>
        </navigation-case>
        <navigation-case>
            <from-outcome>doctorList</from-outcome>
            <to-view-id>/protected/admin/doctorList.xhtml</to-view-id>
            <redirect/>
        </navigation-case>
        <navigation-case>
            <from-outcome>patientList</from-outcome>
            <to-view-id>/protected/admin/patientList.xhtml</to-view-id>
            <redirect/>
        </navigation-case>
        <navigation-case>
            <from-outcome>secretaryList</from-outcome>
            <to-view-id>/protected/admin/secretaryList.xhtml</to-view-id>
            <redirect/>
        </navigation-case>

当我按下我的按钮时,没有任何反应。但为什么?我将此操作添加到按钮:

在 Ring 我添加了: images.add(new PersonImage("person4.png", "Admin", "adminList"));

操作是 adminList。为什么这不起作用?

当我将按钮更改为:<p:commandButton value="#{image.name}" action="adminList" /> 一切正常。为什么?两种构造都返回相同的字符串。

4

1 回答 1

1

在你的

<p:commandButton value="#{image.name}" action="#{image.action}" />

更改image.actionimage.getAction.

<p:commandButton value="#{image.name}" action="#{image.getAction}" />

action期待一个方法表达式,因此您必须提供完整的方法名称getAction。缩写名称action(如 image.action 中的)仅在属性需要值表达式时才有效。

评论

p:graphicImage您不必以这种方式处理 URL 值。让 JSF 为您处理。例如,如果您的图像位于以下路径中

<context-path>/web pages/images/someImage.png 

只需提供这样的值

/images/someImage.png 

换句话说,

<p:graphicImage value="/images/#{image.image}"> 

提供页面时,JSF 将附加额外的路径信息。

于 2013-06-28T23:35:08.057 回答