简体   繁体   English

如何从其他xhtml调用共享的rich:popupPanel

[英]how to call a shared rich:popupPanel from other xhtml

I am newbie in RichFaces and I'm trying to call a popupPanel from other xhtml. 我是RichFaces的新手,并且尝试从其他xhtml调用popupPanel。 I use a4j:commnandLink and a4j:commandButton to call the same popup. 我使用a4j:commnandLink和a4j:commandButton调用相同的弹出窗口。 One for edit a user (passing parameters), and other create a new one. 一个用于编辑用户(传递参数),另一个用于创建新用户。 Dependencies: richfaces 4.3.5.Final, jsf 2.1.9 EL 2.2 依赖关系:richfaces 4.3.5.Final,jsf 2.1.9 EL 2.2

Here is the main page called list.xhtml 这是称为list.xhtml的主页

  <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:a4j="http://richfaces.org/a4j"
    xmlns:xf="http://www.aqualogy.net/xf/components/xf">
<h:form id="searchFilter">
    <h:panelGrid columns="4">
        <h:outputLabel for="searchFilter_username" value="usuario" />
        <h:inputText id="searchFilter_username"
            value="#{usersAction.filter.username}" label="nombre usuario" />
    </h:panelGrid>
    <h:commandButton action="#{usersAction.findUsers}" styleClass="search"
        value="buscar" />
</h:form>
<h:form>
    <rich:extendedDataTable id="searchResult" var="user"
        value="#{usersAction.users.data}"
        rows="#{requestConfiguration.itemsPerPage}" sortMode="single"
        selectionMode="none" rowClasses="odd-row, even-row"
        styleClass="stable" noDataLabel="no result Found">
        <rich:column>
            <f:facet name="header">
                <h:outputText value="Actions" />
            </f:facet>
            <a4j:commandLink id="link1" action="#{usersAction.edit(user)}">
                <f:setPropertyActionListener value="#{user}"
                    target="#{usersAction.users.currentItem}" />
                <h:graphicImage
                    value="#{xf:themeResource('images/buttons/update.png')}"
                    style="border:0" />
                <rich:tooltip
                    value="#{webComponentUIMessages['table.buttons.modify']}" />
            </a4j:commandLink>
        </rich:column>
        <rich:column sortBy="#{user.username}" width="150px">
            <f:facet name="header">
                <h:outputText value="username" />
            </f:facet>
            <h:outputText value="#{user.username}" />
        </rich:column>
        <f:facet name="footer">
            <xf:tableFooter data="#{usersAction.users.data}" />
        </f:facet>
    </rich:extendedDataTable>
    <h:commandButton id="button1" action="edit" styleClass="add"
        value="Add1">
    </h:commandButton>
    <a4j:commandButton id="button2" action="#{usersAction.create}"
        styleClass="add" value="Add2"
        render=":editPanel_messages :editPanel_form:content"
        oncomplete="#{rich:component('editPanel4')}.show();" />
    <ui:include src="edit4.xhtml"></ui:include>
</h:form>
</html>

And here it is the edit.xhtml 这是edit.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:a4j="http://richfaces.org/a4j"
    xmlns:xf="http://xf/components/xf">
    <rich:popupPanel id="editPanel4"
        header="#{webComponentUIMessages['edit.detail']}">
        <f:facet name="header">
            <h:outputText value="PopUp Panel" />
        </f:facet>
        <f:facet name="controls">
            <h:panelGroup>
                <h:graphicImage
                    value="#{xf:themeResource('images/components/popupPanel/close.png')}"
                    styleClass="hidelink">
                    <h:outputLink
                        target="#{rich:component('popup')}.hide();return false;" value="#">
                            x
                            </h:outputLink>
                </h:graphicImage>
            </h:panelGroup>
        </f:facet>
        <xf:messages id="editPanel_messages" />
        <h:form id="editPanel_form">
            <h:panelGroup id="content" layout="block">
                <h:outputLabel for="userName"
                    value="#{securityWebMessages['user.username']}"
                    style="display: block; width:161px" />
                <h:inputText id="userName" maxlength="50"
                    label="#{securityWebMessages['user.username']}" value="usuario"
                    required="true" />
            </h:panelGroup>
        </h:form>
    </rich:popupPanel>
</ui:composition>

And userAction bean.. 和userAction bean ..

@Action("usersAction") @Lazy
@Scope(WebApplicationContext.SCOPE_SESSION)
public class UsersAction {

private DataTableHelper<User> users = new DataTableHelper<User>();


    @PostConstruct
    public void init() {
        filter = userStore.newUser();
        ldapUserFilter=new net.aqualogy.xf.component.ldap.model.User();
        users.setData(new GenericDataModel<User>() {
....
}

public void create() {
        this.ldapUser = null;
        users.setCurrentItem(userStore.newUser());
    }

public void edit(User user) {
        this.ldapUser = null;
        if (newUsers.getCurrentItem() != null && user == null) {
            users.setCurrentItem(newUsers.getCurrentItem());
        } else {
            users.setCurrentItem(user);
        }
    }
}

I tried to located edit.xhtml in the same directory and in another and doesn't work. 我试图将edit.xhtml放在同一目录和另一个目录中,但不起作用。 I also tried to modify edit method in the bean to return "edit" and works in the commandLink button but only if transform the popupPanel in a rich:panel 我还尝试修改Bean中的edit方法以返回“ edit”并在commandLink按钮中工作,但前提是要在rich:panel中转换popupPanel

Thanks in advance. 提前致谢。

You already call 您已经打电话了

<ui:include src="edit4.xhtml"></ui:include>

But position of this line is wrong. 但是这条线的位置是错误的。 Put it outside of form in list.xhtml like: 将其放在list.xhtml中的表单之外,例如:

<ui:include src="edit.xhtml" />

Note : Because right now it is inside form, you have nested forms in popup , which is not supported by JSF. 注意 :因为现在它在表单内部,所以您在popup中有嵌套的表单, JSF不支持。

You can call popup like it is in the same file: 您可以像在同一文件中一样调用弹出窗口:

<a4j:commandButton value="Edit" immediate="true"
    onclick="#{rich:component('editPanel4')}.show()" />

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

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