在我的 JSF 页面中,我几乎没有 Links{link1,link2,link3,link4}-{Student Id's}.
我尝试的是当我点击链接时,它会在 "NEW WINDOW".
中打开学生信息
当我点击下一个链接时,它正在打开一个新窗口,但我想在同一个新窗口中打开,即目标应该是打开的同一个新窗口。
图示:
我从 STACKOVERFLOW 收集东西时尝试过的代码片段 Open Page in New Window :
<p:dataTable id="studentDtTble" var="studData" value="#{studentController.dataList}">
<p:columnGroup type="header">
<p:row>
<p:column headerText="StudentId"></p:column>
<p:column headerText="StudentName"></p:column>
<p:column headerText="Add" ></p:column>
</p:row>
</p:columnGroup>
<p:column>
<p:commandLink id="sidlink" action="/studentinfo.xhtml" target="_blank">
<h:outputText value="#{studData.studentId}" styleClass="txtlink" />
</p:commandLink>
</p:column>
<p:column>
<h:outputText value="#{studData.studentName}" />
</p:column>
<p:column >
<p:selectBooleanCheckbox value="#{studData.add}" />
</p:column>
</p:dataTable>
在@Nosnhoj 回复后编辑:
When i Click on any of the SID Link then there Details Should Opened in the "Same NEW Window".
最佳答案
使用 <h:commandLink>
而不是 <p:commandLink>
.
我尝试了您的代码并进行了如下更改:
<h:commandLink id="sidlink" action="#{studentController.selectStudent(studData)}" target="_blank">
<h:outputText value="#{studData.studentId}" styleClass="txtlink" />
</h:commandLink>
我已更改
<p:commandLink>
至 <h:commandLink>
, 和 调用支持 bean 中的方法来设置选定的学生 .(对于New Window
应该需要学生信息。)这是
studentController.selectStudent
的代码:private Student selectedStu;
public String selectStudent(Student stu) {
selectedStu = stu;
return "/studentinfo.xhtml";
}
以下是
New Window
的代码: <h:form>
<h:commandLink value="Another Link" action="/anotherinfo.xhtml" target="_self"/>
<br/>
Student: <h:outputText value="#{studentController.selectedStu.studentName}"/>
</h:form>
这只是显示所选学生的姓名,以及您想要的另一个链接。
请注意
target
属性是 _self
因为您希望新页面显示在同一窗口中。最后,
anotherinfo.xhtml
只是我通过 NetBeans 创建的一个空页面,因此无需发布它。您可能会看到以下内容:
点击“Johnson”的id后:
点击“另一个链接”后:
更新
当@User2561626 解释他/她的意图时,我更新我的答案如下:
如果你想要一个 新窗口弹出而不是 新标签 ,您应该像这样更改代码:
<p:commandLink id="sidlink" actionListener="#{studentController.selectStudent(studData)}" oncomplete="window.open('studentinfo.xhtml', 'newwindow', 'width=300, height=250');">
<h:outputText value="#{studData.studentId}" styleClass="txtlink" />
</p:commandLink>
我换
<h:commandLink>
返回 <p:commandLink>
, 制作 action
如 actionListener
因为我们要先设置选中的Student,最后我加上window.open
在 oncomplete
属性,以便新页面将在新窗口中打开,而不是选项卡中。当然我们需要编辑方法
studentController.selectStudent()
, 像这样:public void selectStudent(Student stu) {
selectedStu = stu;
}
如您所见,返回类型为 作废 现在,这个方法唯一要做的就是设置选定的学生。
希望这可能会有所帮助。
关于jsf - 当我点击任何链接时,它应该在 JSF、Primefaces 的同一个新窗口中打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20865710/