0

我有一个数据表,其中一列包含特定项目的状态。状态在列中显示为 commandLink。如果从数据库中检索到的项目的状态是逗号分隔的值,例如 Status1,Status 2,我必须在同一项目的列中显示 2 个命令链接,即一个带有 Status1,另一个带有 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> 

以上是我用来显示 commandLink 的代码。单击时,它会显示一个弹出窗口,如果我单击 OK,我必须执行一个再次更新状态的操作。我在同一列中有 2 个 commandLink,我的问题是当我单击一个 commandLink 并执行操作时,我希望该 commandLink 的文本只更改,而不是另一个。所以,我需要传递我单击的 commandLink 的 id。请让我知道我该怎么做。

我按照您的建议尝试了-

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

它似乎仍然不起作用,当我打印 linkStatus 值时,我将其设为空。请帮忙。

4

1 回答 1

1

如果您使用 primefaces,则可以使用 p:remoteCommand轻松完成

首先,获取commandLink使用 javascript 的 id,然后您可以使用 action 将其放入您的 bean。

这是一个简单的例子。检查一下。

使用远程命令

更新

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

弹出窗口中的 OK 按钮

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

你的 bean 中的 doSubmitMethod;

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


}

也许对你有帮助。

于 2012-10-18T10:03:23.357 回答