通过javascript在jsf中设置commandlink标签的目标属性的条件

时间:2013-04-01 15:36:14

标签: javascript jsf

我想通过javascript为jsf中的commandlink目标属性设置条件。

仅当条件为真时,否则只有目标属性才会起作用。

或者我们可以通过javascript传递commandlink目标属性的值。

这是我的代码:

<script language=javascript >
function open_win()
{

var selecttype = document.getElementById("frmList:Export").value;
var datetype1 = document.getElementById("frmList:fld_Date").value;

   if (selecttype == "PDF" && datetype1 != false)
return target = "_blank";
else 
return target = "_self"  
  }
 </script>


 <h:commandLink  target = "" onclick = "open_win()" style="border: none;"     
    actionListener="#{report.yes}">
    <h:graphicImage   
    style="border: none;" value="#{User.imageBasePath}/btn_yes.gif" />
  </h:commandLink>

1 个答案:

答案 0 :(得分:0)

JSF将commandLink呈现为HTML <a>标记,可以在Javascript中修改。是的,您可以通过执行

在Javascript中传递target属性
document.getElementById("frmList:reportLink").target = "_blank";

 <h:commandLink id="reportLink" onclick = "open_win()" style="border: none;" 
                    actionListener="#{report.yes}">

更好的方法是在commandLink中添加此逻辑,

<h:commandLink  target = "#{(export=='PDF' and fld_Date)?'_blank':'_self'}"
                style="border: none;" actionListener="#{report.yes}">
    <h:graphicImage style="border: none;" 
                value="#{User.imageBasePath}/btn_yes.gif" />
  </h:commandLink>