0

I would like when i click the link for cancelling a request my form which contains the form with commandLink to update dynamically (because this record should not be visible in this form anymore). Here is my code:

<h:form id = "form">
        <p:dataGrid id = "dataGrid" value="#{userRequestBean.userActiveRequests}" columns="1"
            var="userActiveRequest" selection="#{userRequestBean.request}"
            rowKey="#{userActiveRequest.id}">
            <f:facet name="header">
            My requests
        </f:facet>

            <h:panelGrid id="panelGrid">
                <h:outputText value="#{userActiveRequest.title.toUpperCase()}" />
                <h:outputText value="#{userActiveRequest.description}" />

                <h:form rendered="#{not empty userActiveRequest.hiredAgency}">
                    <h:commandLink
                        value="Details for agency #{userActiveRequest.hiredAgency.tUser.name}"
                        action="agencyDetail?faces-redirect=true">
                        <f:setPropertyActionListener target="#{agencyBean.tAgency}"
                            value="${userActiveRequest.hiredAgency}" />
                    </h:commandLink>
                </h:form>
**//HERE IS THE COMMANDLINK WHICH I MENTIONED**
                <h:form rendered="#{empty userActiveRequest.hiredAgency}">
                    To cancel, click <p:commandLink
                        value="HERE" action="#{userRequestBean.cancelRequest()}"
                        update = "form:dataGrid:panelGrid">
                        <f:setPropertyActionListener target="#{userRequestBean.request}"
                            value="${userActiveRequest}" />
                    </p:commandLink>
                </h:form>

                <p:commandButton value="Details"
                    action="userRequestDetails?faces-redirect=true">
                    <f:setPropertyActionListener target="#{userRequestBean.request}"
                        value="${userActiveRequest}" />
                </p:commandButton>
            </h:panelGrid>
        </p:dataGrid>
    </h:form>

ADDED: Part of the Java class:

private List<TRequest> userActiveRequests; // + get and set methods

    public UserRequestBean(){
        EntityManager em = HibernateUtil.getEntityManager();
        Query query = em.createQuery("select r " +
                "from TUser u join u.userRequests r where u.id = :userId and r.isActive = 'Y'");
        query.setParameter("userId", Long.valueOf(11));
        userActiveRequests = query.getResultList();
    }

    public void cancelRequest (){
        EntityManager em = HibernateUtil.getEntityManager();
        em.getTransaction().begin();
        request.setIsCancelled(true);
        request.setIsActive(false);
        em.merge(request);
        em.getTransaction().commit();
        //remove the object from the List
        userActiveRequests.remove(request);
    }
Tot
  • 207
  • 8
  • 25
  • The problem is that you're nesting forms, and that's invalid HTML. Remove the `` that wraps your other ``s and the command link action will be invoked. – Luiggi Mendoza May 28 '14 at 21:50
  • I removed the outher but it still gave me error - Cannot find component with expression "dataGrid:panelGrid" referenced from "dataGrid:0:j_idt19:j_idt21". – Tot May 29 '14 at 19:16
  • So your real problem now is that you're trying to update a component whose id cannot be identified. Give a specific ID for all your components and then update the complete component id. In this case, after removing the top ``, the complete component id for your ` – Luiggi Mendoza May 29 '14 at 19:23
  • Now, no error is occurred, but the record which i cancelled is still in dataGrid. It seems that update does not work, it does not redresh the dataGrid. – Tot May 29 '14 at 19:28
  • Is the link a removal action or an action that should update the state in database? Are you sure you're also updating the object stored in your `List` as well? – Luiggi Mendoza May 29 '14 at 19:30
  • Yes, i would with to update the state of the object in the database and i removed the object from the list in the Java code. I will edit my post and i will add the method from the Java class. – Tot May 29 '14 at 19:37
  • Hm, this works but only in Firefox. – Tot May 29 '14 at 20:23

1 Answers1

0

as Luiggi has said - nesting forms is invalid.

Refer to this on SO: Can you nest html forms? Have a look at your design to see if u really need to nest that inner form, or can just use partial ajax updates to meet your needs.

Community
  • 1
  • 1
VeenarM
  • 1,263
  • 1
  • 10
  • 14