0

I have a datatable, and one of the columns contains the status of the particular item. The status appears as a commandLink in the column. If the status of the item as retrieved from the database is a comma separated value like Status1,Status 2, I have to display 2 commandlinks in the column for the same item namely, one with Status1 and another with Status 2.

<h:commandLink id="status1Link" value="#{pc_test.status1}"
                            onclick="showAssignKeyRvPopup(#{plist.t3Id},'#{plist.t3FileName}','#{plist.status}');return false;"
                            rendered="#{plist.status == 'Status1,Status2'}"
                            update="assignKeyRvDialog">
                        </h:commandLink> 

The above is the code I'm using to display the commandLink. on click, it shows a popup, from which if I clcik OK, I have to perform an action that updates the status again. I have 2 commandLinks in the same column, my question is when I click on one commandLink and perform an action, I want the text of that commandLink only to change, not the other one. So, I need to pass the id of the commandLink that I click. Please let me know how I can go about doing this.

I tried just as you suggested -

<p:remoteCommand name="doSubmit" actionListener="#{pc_testmaps.doAssignUser}" />

<p:commandButton id="assignUser" value="Submit" onclick="doSubmit();"> </p:commandButton>

function doSubmit() {
            document.getElementById('nonMCLink') = commandLinkId;
            doAssignUser([{name:'commandLinkId', value:commandLinkId}]);
        }

And in the bean, 

public void doAssignUser() throws DelegateException {

        FacesContext context = FacesContext.getCurrentInstance();
        Map<String, String> map = context.getExternalContext().getRequestParameterMap();
        String linkStatus = (String) map.get("commandLinkId");
        System.out.println(linkStatus);
}

It still doesn't seem to work, when I print the linkStatus value, I'm getting it as null. Please help.

Raaz
  • 125
  • 1
  • 5
  • 16
  • do you use 3rd component technology like primefaces,richfaces.. – mstzn Oct 18 '12 at 09:50
  • Yeah, I'm using Primefaces 3.0 – Raaz Oct 18 '12 at 09:55
  • Your concrete functional requirement is unclear. *"I want the text of that commandLink only to change, not the other one"* Before or after invoking the method? If before, why don't you just use onclick? If after, why don't you just modify `#{pc_test.status1}`? By the way, please don't obfuscate PrimeFaces away if you were actually using it. It would only lead to more confusion and possibly inapplicable answers. The `update` attribute is invalid in `` and the `` has more enhanced attributes which could be used to solve the problem more easily. – BalusC Oct 18 '12 at 11:27
  • Sorry I have not been clear. I would like the status to change after invoking the method, and I would want to know which of the 2 command links I have clicked so that I can update the appropriate link's status. – Raaz Oct 18 '12 at 11:32

1 Answers1

1

if you use primefaces,it can be so easily with p:remoteCommand

Firstly,get id of commandLink using javascript,then you can get it into your bean using action.

Here is simple example.Check this out.

using remoteCommand

UPDATE

    <p:remoteCommand name="doSubmit"
        actionListener="#{yourBean.doSubmit}" />

<script type="text/javascript">
function onOKclick() {
$(document).ready(function() {
    var commandLinkID = "yourcommandlinkId" //or get id using javascript with name          
doSubmit([{name:'commandLinkID', value:commandLinkID}]);
    });         
}
</script>

Your OK buton on the popup

  <h:commandButton onclick="onOKclick();" /> 
//calling onOKclick js function is important.you can call onOkclikc js function where you want 

Your doSubmitMethod in your bean;

public void doSubmit(){
  FacesContext context = FacesContext.getCurrentInstance();
            Map<String, String> map = context.getExternalContext().getRequestParameterMap();
           String value = (String) map.get("commandLinkID");
System.out.print(value);


}

Maybe it helps is you.

Community
  • 1
  • 1
mstzn
  • 2,881
  • 3
  • 25
  • 37
  • I have 2 commandLinks in the same column as I mentioned, and when I click on either, it shows a popup from where I can select a user. Only when I click on OK in that popup, does the doSubmit method in the bean get called. So, in this case, if I have a javascript function, where do I call it from? Also please tell me if there's any other way to do this. – Raaz Oct 18 '12 at 10:30
  • ok when you click on OK in your popup,you can call javascript and passing id of commandLink which you want – mstzn Oct 18 '12 at 10:35
  • I have edited my question after trying out the ideas you gave, please take a look. – Raaz Oct 18 '12 at 11:27