[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 252
  • Last Modified:

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

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
prain
Asked:
prain
  • 2
1 Solution
 
mccarlIT Business Systems Analyst / Software DeveloperCommented:
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
 
prainAuthor Commented:
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
 
mccarlIT Business Systems Analyst / Software DeveloperCommented:
Your welcome, glad I could help!  :)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now