【发布时间】:2014-04-15 06:38:19
【问题描述】:
我正在使用jsf 和primefaces。
我有一个表单,其中我有一个 StudentId 输入文本和一个命令链接以在新的 Pop-Up 中查看 Student Details 和一个 Get 要显示的命令按钮
我想在点击获取按钮时实现这一点。
- 如果之前未打开弹出窗口,则不要打开弹出窗口。
- 如果弹出窗口已打开,则使用新参数刷新该窗口。
这是我的代码:
查看页面:
...//js code is below ..
<h:outputText value="StudentId :" />
<p:inputText value="#{myController.studentId}" >
<pe:keyFilter mask="num"/>
</p:inputText>
<p:commandButton value="Get" actionListener="#{myController.getStudentMarksDetails(myController.studentId)}" >
<p:commandLink onclick="openWindow('http://www.google.com','pageName')" >
<h:outputText value="Student Info ">
</p:commandLink>
...//Displays Student Marks
我的控制器
public Student getStudentMarksDetails(Long studentId){
//Some Code to Get the Student Marks
// I want to Check whether a Pop-Up already exists or not, if pop-up is opened then refresh with this url
RequestContext.getCurrentInstance().execute("updatePopUpWindow('http://stackoverflow.com','pageName');");
}
我的 JS
var myWindow;
//Opens in the Same window
function openWindow(url, name){
myWindow = window.open(url, name,'status=no,toolbar=no,location=no,menubar=no,resizable,width=1008,height=690,scrollbars,left=100,top=50,').focus();
}
// To check whether a Pop-Up window is opened or not
//if the pop-up window with pageName is not Opened before then dont open a Pop-Up.
//if the pop-up window is already opened, then refresh that window with new arguments.
function updatePopUpWindow(url, name){
if(myWindow!=null){
if(!myWindow.closed){
myWindow.close();
}
}
//Check the condition Here
myWindow = window.open(url, name,'status=no,toolbar=no,location=no,menubar=no,resizable,width=1008,height=690,scrollbars,left=100,top=50,').focus();
}
我试过放置这个条件但没有用:
if(myWindow.name == name){
myWindow = window.open(url, name,'status=no,toolbar=no,location=no,menubar=no,resizable,width=1008,height=690,scrollbars,left=100,top=50,').focus();
}
我推荐了很多links,但无法解决我需要的方式。
如何在JQuery 中实现此问题,因为JS 属性独立于浏览器
更新评论: 我无法使用 PF 对话框,因为我不知道该外部服务链接将如何以及何种类型的数据和视图来自该外部服务链接。认为我不是我传递来获取学生详细信息的 URL 的作者。
【问题讨论】:
-
您确定要使用弹出窗口而不是 PF 模态对话框吗?
-
@perissf 我想打开一个新窗口,在 url 后面加上 studentId 来获取学生信息。我想打开一个新的浏览器窗口,而不是对话框!
-
@all 在我的情况下,学生信息详细信息由另一个外部项目提供,所以如果我必须打开一个新窗口并使用 StudentId 传递 URL 来调用另一个项目的外部服务!这不是我可以使用 PF 对话框的情况!
-
仍然不明白为什么你不能按照我建议的方式使用它...你可以完全控制对话框,你可以完全控制你传递的 URL - 你还需要什么?
-
@Dodek 我想打开一个窗口,因为即使我们在父页面上执行任何其他操作,让 StudentDetailsInfo 窗口保持原样,我们也可以查看学生详细信息。
标签: java javascript jquery jsf primefaces