当我单击任何链接时,它应该在JSF,Primefaces的同一新窗口中打开 [英] When i click on any link it should Open in the same New Window in JSF, Primefaces

查看:96
本文介绍了当我单击任何链接时,它应该在JSF,Primefaces的同一新窗口中打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的JSF页面中,我只有几个Links{link1,link2,link3,link4}-{Student Id's}.

In my JSF page i have few Links{link1,link2,link3,link4}-{Student Id's}.

我尝试过的是,当我单击链接时,它会在"NEW WINDOW".

What i tried is when i click on the Link it Opens the Student-Information in a "NEW WINDOW".

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

When i am clicking on the next Link it is Opening a New Window,but i want to open in the Same New Window i.e., the TARGET should be the Same NEW Window which is opened.

钻石制表示形式:

我曾尝试从STACKOVERFLOW收集内容的代码段

My Piece of Code which i had tried from collecting things from STACKOVERFLOWOpen 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".

Edited After @Nosnhoj Reply :When i Click on any of the SID Link then there Details Should Opened in the "Same NEW Window".

推荐答案

使用<h:commandLink>代替<p:commandLink>.

我尝试了您的代码,并做了如下更改:

I tried your code and make a little change like this:

<h:commandLink id="sidlink" action="#{studentController.selectStudent(studData)}" target="_blank">  
    <h:outputText value="#{studData.studentId}" styleClass="txtlink" />
</h:commandLink>

<p:commandLink>更改为<h:commandLink> ,并调用备用Bean中的方法来设置所选的Student .(对于New Window应该需要学生信息.)

I changed <p:commandLink> to <h:commandLink>, and call a method in the backing bean to set the selected Student.(For the New Window should need the student information.)

这是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,因为您希望新页面显示在同一窗口中.

Which is just showing name of the selected Student, and another link you want.
Note that the target attribute is _self because you want the new page show in the same window.

最后,anotherinfo.xhtml只是我通过NetBeans创建的空白页,因此无需发布.

Finally, the anotherinfo.xhtml is just an empty page I created via NetBeans, so there's no need to post it.

这可能是您看到的内容:

And here's what you may see:

点击"Johnson"的ID后:

After clicking the id of "Johnson" :

点击另一个链接"后:

After clicking "Another Link" :

由于@ User2561626解释了他/她的意图,我将我的回答更新如下:
如果要弹出 新窗口 而不是 New标签 ,则应更改代码,例如:

As @User2561626 explain what he/she intended to, I update my answer as follow:
If you want a New Window pop up in stead of New Tab, you should change the code like:

<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,最后我在oncomplete属性中添加window.open,这样才能打开新页面在新窗口中,但不在选项卡中.
当然,我们需要编辑方法studentController.selectStudent(),如下所示:

I change <h:commandLink> back to <p:commandLink>, make action as actionListener because we want to set the selected Student first, finally I add window.open in oncomplete attribute so that the new page will open in a new window but not tab.
Of course we need to edit the method studentController.selectStudent(), like this:

public void selectStudent(Student stu) {
    selectedStu = stu;
}

如您所见,返回类型现在为 void ,此方法唯一要做的就是设置所选的Student.
希望这会有所帮助.

As you can see, the return type is void now, and the only thing this method do is just set the selected Student.
Hope this may help.

这篇关于当我单击任何链接时,它应该在JSF,Primefaces的同一新窗口中打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆