0

I have a userProfileBean which I can access outside of the repeat but when I do

<ui:repeat id="reqlistID" var="reqlist" value="#{userProfileBean.friendRequestsList}">
    jmeno: #{reqlist.jmeno} <br/> prijmeni: #{reqlist.prijmeni} <br/> id: #{reqlist.id} <br/>
    <p:commandButton id="allowFriendButton" 
                     action="#{userProfileBean.allowFriend()}" 
                     value="Přidat"
                     update="reqlistID">
    </p:commandButton>

Then the allowFriend method doesn't get called and netbeans says unknown property. Am I missing something?

Edit: thanks for the replies. Still doesn't work. Now the state is this.

<h:form>
    <p:commandButton id="allson" 
                     action="#{userProfileBean.testt()}" 
                     value="Přidat"
                     ajax="false">
    </p:commandButton>
</h:form>

<c:if test="#{principalBean.p.login == userProfileBean.name}">
    Žádosti přidání do přátel:<br/>
    <ui:repeat id="reqlistID" var="reqlist" value="#{userProfileBean.friendRequestsList}">
        jmeno: #{reqlist.jmeno} <br/> prijmeni: #{reqlist.prijmeni} <br/> id: #{reqlist.id} <br/>
        <h:form>
            <p:commandButton id="allowFriendButton" 
                             action="#{userProfileBean.testt()}" 
                             value="Přidat"
                             ajax="false">
            </p:commandButton>
        </h:form>

        <br/>
    </ui:repeat>
</c:if>

The first <p:commandButton> works and calls the method properly (with page reload). The second button reloads the page but does not call the method. The problem seems to be with accessing the userProfileBean from inside the repeat. But I can't google out any explanation.

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
David Polák
  • 1,581
  • 4
  • 18
  • 33
  • *the allowFriend method doesn't get called and netbeans says unknown property* have you checked if this method exists in your managed bean and is `public`? – Luiggi Mendoza May 09 '13 at 14:20

2 Answers2

0

I guess you're missing the form element. Try putting your buttons in a form like

<h:form>
<ui:repeat id="reqlistID" var="reqlist" value="#{userProfileBean.friendRequestsList}">
    jmeno: #{reqlist.jmeno} <br/> prijmeni: #{reqlist.prijmeni} <br/> id: #{reqlist.id} <br/>
    <p:commandButton id="allowFriendButton" 
                     action="#{userProfileBean.allowFriend()}" 
                     value="Přidat"
                     update="reqlistID">
    </p:commandButton>
</ui:repeat>
</h:form>
Ozan Tabak
  • 662
  • 3
  • 9
0

Found the source of the problem, the form is getting regenerated and the bean cannot find the original button element, because it is request scoped. Tried to implement a view scope, but something failed there. So I just made the bean session scoped.

David Polák
  • 1,581
  • 4
  • 18
  • 33
  • 1
    As to the view scope failure, carefully read http://stackoverflow.com/questions/3342984/jstl-in-jsf2-facelets-makes-sense/3343681#3343681 – BalusC May 09 '13 at 14:20
  • Okay I see what's happening now, so what is the correct way to implement this. I have a need for generating delete buttons for every user inserted content. One way to do it I can see is to pass the ID of the content to some deletehandler.xhtml in a url parameter, which is what I did not want to as it seems to me to be a security problem, is it? – David Polák May 09 '13 at 14:44