Solved

p:commandLink value does not getting updated. This is frustrating

Posted on 2014-03-31
3
232 Views
Last Modified: 2014-04-02
All,
I am having a series of p:commandLink components. Each one is linked to a bean function. Just for testing purposes, I want to see the link's text getting changed when clicking it as shown in the code below. On the browser the links do not changed when clicked. What is the problem here and what I am not doing right. Please help. This is the design I am expected to implenent in a actual system.



<ui:composition>
 
 
      <table role="region" aria-label="Key Services Portlet"
class="table">
            <tbody>
                  <tr>
                        <td >
                              <p:commandLink
value="#{dataManager.aDataItem1}"
actionListener="#{dataManager.goToClickedLink1()}"/>
                        </td>
                  </tr>
                  <tr>
                        <td >
                              <p:commandLink
value="#{dataManager.aDataItem2}"
actionListener="#{dataManager.goToClickedLink2()}"/>
                        </td>
                  </tr>
                  <tr>
                        <td >
                              <p:commandLink
value="#{dataManager.aDataItem3}"
actionListener="#{dataManager.goToClickedLink3()}"/>
                        </td>
                  </tr>
                  
                  <tr>
                        <td >
                              <p:commandLink value="more"
actionListener="#{dataManager.goToClickedMore()}"/>
                        </td>
                  </tr>
        </tbody>
      </table>
      
</ui:composition>
</html>





 

@ManagedBean(name="DataManager")
@SessionScoped
public class DataManager  {

      private List<String> list;
      private String aDataItem1 = "Employment Opportunity 1";
      private String aDataItem2 = "Employment Opportunity 2";
      private String aDataItem3 = "Employment Opportunity 3";
 
 
      public  DataManager()  {
             
               
      }

      
      
      public String getaDataItem1()
      {
            return aDataItem1;
      }
      
      public void setaDataItem1(String aValue)
      {
             
            aDataItem1 = aValue;
      }
      
      public String getaDataItem2()
      {
            return aDataItem2;
      }
      
      public void setaDataItem2(String aValue)
      {
             
            aDataItem2 = aValue;
      }
      
      public String getaDataItem3()
      {
            return aDataItem3;
      }
      
      public void setaDataItem3(String aValue)
      {
             
            aDataItem3 = aValue;
      }
      
      
      
      public void goToClickedLink1()
      {
            System.out.println("Clicked goToClickedLink1");
            aDataItem3 = "Hello World P";
      }
      
      
      public void goToClickedLink2()
      {
            System.out.println("Clicked goToClickedLink2");
            aDataItem2 = "Hello World Q";
      }
      
      public void goToClickedLink3()
      {
            System.out.println("Clicked goToClickedLink3");
            aDataItem3 = "Hello World R";
      }
      
      public void goToClickedMore()
      {
            System.out.println("Clicked goToClickedMore");
            aDataItem3 = "asjkfdhgsakjhdfkjashfd";
      }
}
0
Comment
Question by:prain
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
mccarl earned 300 total points
ID: 39968498
Looking at the documentation/showcase for Primefaces (I assume that is what you are using, you haven't actually told us), it appears that you may need to tell primefaces what might need to be updated once the actionlistener fires. The example shows the use of the "update" attribute on the p:commandLink element. Try adding this attribute and setting the value to the "id" of a container element. Now I am not sure if you can just add an "id" to your table, of if it specifically needs to be a primefaces component. If adding the id to the table doesn't work, try wrapping the table in a p:panel element with the "id" set to something appropriate and then use that id in the "update" attribute on the p:commandLink's.

ie. something like this...
<ui:composition>
 
  <p:panel id="linkPanel">
      <table role="region" aria-label="Key Services Portlet"
class="table">
            <tbody>
                  <tr>
                        <td >
                              <p:commandLink
value="#{dataManager.aDataItem1}"
actionListener="#{dataManager.goToClickedLink1()}" update="linkPanel"/>
                        </td>
                  </tr>
                  <tr>
                        <td >
                              <p:commandLink
value="#{dataManager.aDataItem2}"
actionListener="#{dataManager.goToClickedLink2()}" update="linkPanel"/>
                        </td>
                  </tr>
                  <tr>
                        <td >
                              <p:commandLink
value="#{dataManager.aDataItem3}"
actionListener="#{dataManager.goToClickedLink3()}" update="linkPanel"/>
                        </td>
                  </tr>
                  
                  <tr>
                        <td >
                              <p:commandLink value="more"
actionListener="#{dataManager.goToClickedMore()}" update="linkPanel"/>
                        </td>
                  </tr>
        </tbody>
      </table>
    </p:panel>
</ui:composition>
</html>

Open in new window

0
 

Author Closing Comment

by:prain
ID: 39969030
PERFECT!!!!
Thank You Very Much. Yes somehow I did not realize that the update property must be set. Phew, coming from ASP.NET background this is different. Thanks again.
0
 
LVL 35

Expert Comment

by:mccarl
ID: 39972071
Your welcome, glad I could help!  :)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
what is spring 3 40
zeroFront challenge 7 71
MaxSpan challenge 9 68
seriesUp challenge 7 109
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now