The Nightmare
The Nightmare

Reputation: 701

Not reaction to pressing button

I have a ring in 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>

My RingBean:

@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;
    }

}

PersonImage class:

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;
    }

}

faces-config:

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

When i pressed my button, no reaction. But why? I added this action to the button:

And in Ring I added: images.add(new PersonImage("person4.png", "Admin", "adminList"));

action is adminList. Why does this not work?

When i changed the button to: <p:commandButton value="#{image.name}" action="adminList" /> everything works. Why? Both construction returned identical string.

Upvotes: 1

Views: 126

Answers (1)

Andy
Andy

Reputation: 6568

In your

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

change image.action to image.getAction.

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

action is expecting a method expression, therefore you have to supply to full method name getAction. The abbreviated name action(as in image.action) is only valid when an attribute is expecting a value expression.

COMMENT

In p:graphicImage You don't have to deal with the URL value this way. Let JSF handle it for you. For example, if you have your images in the following path

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

simply provide the value like this

/images/someImage.png 

In other words,

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

JSF will append the additional path info when the page is served.

Upvotes: 1

Related Questions