gpt4 book ai didi

jsf - 当我点击任何链接时,它应该在 JSF、Primefaces 的同一个新窗口中打开

转载 作者:行者123 更新时间:2023-12-04 14:14:03 27 4
gpt4 key购买 nike

在我的 JSF 页面中,我几乎没有 Links{link1,link2,link3,link4}-{Student Id's}.
我尝试的是当我点击链接时,它会在 "NEW WINDOW". 中打开学生信息

当我点击下一个链接时,它正在打开一个新窗口,但我想在同一个新窗口中打开,即目标应该是打开的同一个新窗口。

图示:

Target Link to Same 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 创建的一个空页面,因此无需发布它。

您可能会看到以下内容:
enter image description here

点击“Johnson”的id后:
enter image description here

点击“另一个链接”后:
enter image description here

更新

当@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> , 制作 actionactionListener因为我们要先设置选中的Student,最后我加上 window.openoncomplete属性,以便新页面将在新窗口中打开,而不是选项卡中。
当然我们需要编辑方法 studentController.selectStudent() , 像这样:
public void selectStudent(Student stu) {
selectedStu = stu;
}

如您所见,返回类型为 作废 现在,这个方法唯一要做的就是设置选定的学生。
希望这可能会有所帮助。

关于jsf - 当我点击任何链接时,它应该在 JSF、Primefaces 的同一个新窗口中打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20865710/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com