简体   繁体   English

带有参数值的js函数调用<p:commandButton>

[英]js function call with parameter value from <p:commandButton>

I have a code like: 我有一个类似的代码:

<p:commandButton type="submit" value="Select User" onclick="showGrpMemberSearchPageCalenderLeave(#{groupname})"/>

Here I have set the value of groupname like: 在这里,我将groupname的值设置为:

<c:set var="groupname" value="#{session.getAttribute('USER_GROUP_NAME')}"/>

If I print this value #{session.getAttribute('USER_GROUP_NAME')} it gives the correct value. 如果我打印此值#{session.getAttribute('USER_GROUP_NAME')}它将给出正确的值。 but the java script function that I want to call showGrpMemberSearchPageCalenderLeave(#{groupname}) is not invoked. 但是我要调用showGrpMemberSearchPageCalenderLeave(#{groupname})的Java脚本函数没有被调用。

The function is: 该函数是:

function showGrpMemberSearchPageCalenderLeave(groupName){
var x= (screen.width-530)/2;
var y= (screen.height-450)/2;
window.open('./SearchGroupMembersLeaveCalander.xhtml?groupName='+groupName,'mywindow','resizable=no,toolbar=no,scrollbars=yes,height=450,width=530,top='+y+',left='+x);
return false;
}

this actually opens a popup. 这实际上会打开一个弹出窗口。 when I did not have the parameter value, the popup opened fine. 当我没有参数值时,弹出窗口可以正常打开。 Please help! 请帮忙!

onclick="showGrpMemberSearchPageCalenderLeave(#{groupname})"

So, you're printing the EL variable #{groupname} as a JS variable? 那么,您要将EL变量#{groupname}打印为JS变量吗? Imagine that #{groupname} returns a string value of somegroup , then this code get ultimately rendered as follows (open page in browser, rightclick and View Source to see it yourself): 假设#{groupname}返回字符串somegroup ,那么该代码最终呈现如下(在浏览器中打开页面,右键单击并查看源代码以自己查看 ):

onclick="showGrpMemberSearchPageCalenderLeave(somegroup)"

Do you have a JS variable somegroup in the JS scope? 在JS范围内,您是否有JS变量somegroup Apparently not. 显然不是。 It look like that you intented to pass it as a JS string. 看起来您打算将其作为JS字符串传递。 You should then quote it. 然后,您应该引用它。 You ultimately want that JSF generates the following HTML/JS code: 您最终希望JSF生成以下HTML / JS代码:

onclick="showGrpMemberSearchPageCalenderLeave('somegroup')"

You should then write the JSF/EL code in such way that it generates exactly the desired HTML/JS code: 然后,您应该以这样的方式编写JSF / EL代码,使其完全生成所需的HTML / JS代码:

onclick="showGrpMemberSearchPageCalenderLeave('#{groupname}')"

Unrelated to the concrete problem, the value in your c:set makes no sense: 具体问题无关 ,您的c:set的值没有任何意义:

<c:set var="groupname" value="#{session.getAttribute('USER_GROUP_NAME')}"/>

It look like that you do not understand how EL works. 您似乎不了解EL的工作原理。 It already searches for variables in page, request, session and application scope. 它已经在页面,请求,会话和应用程序范围内搜索变量。 This should be done as follows: 应按以下步骤进行:

<c:set var="groupname" value="#{USER_GROUP_NAME}"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM