0

I have multiple forms in page and each form have datatables. When i select the datatable mapped to that control should be shown on the page . Facing the below exception when developing application using primefaces:

  javax.faces.view.facelets.TagAttributeException: //C:/Workspace/Application/WebContent/transfer.xhtml @28,102 rendered="#{transferMB.mySelectedValues('1')}" Error Parsing: #{transferMB.mySelectedValues('1')}
            at com.sun.faces.facelets.tag.TagAttributeImpl.getValueExpression(TagAttributeImpl.java:428)
            at com.sun.faces.facelets.tag.TagAttributeImpl.getValueExpression(TagAttributeImpl.java:378)
            at com.sun.faces.facelets.tag.jsf.ComponentRule$ValueExpressionMetadata.applyMetadata(ComponentRule.java:107)
            at com.sun.faces.facelets.tag.MetadataImpl.applyMetadata(MetadataImpl.java:81)
            at javax.faces.view.facelets.MetaTagHandler.setAttributes(MetaTagHandler.java:129)
            at javax.faces.view.facelets.DelegatingMetaTagHandler.setAttributes(DelegatingMetaTagHandler.java:102)
     weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
            at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
            at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2277)
            at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2183)
            at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1454)
            at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
            at weblogic.work.ExecuteThread.run(ExecuteThread.java:178)
        Caused by: javax.el.ELException: Error Parsing: #{transferMB.mySelectedValues('1')}
            at com.sun.el.lang.ExpressionBuilder.createNodeInternal(Unknown Source)
            at com.sun.el.lang.ExpressionBuilder.build(Unknown Source)
            at com.sun.el.lang.Expres

sionBuilder.createValueExpression(Unknown Source)
        at com.sun.el.ExpressionFactoryImpl.createValueExpression(Unknown Source)
        at com.sun.faces.facelets.tag.TagAttributeImpl.getValueExpression(TagAttributeImpl.java:412)
        ... 94 more
user3684675
  • 381
  • 4
  • 8
  • 32

3 Answers3

0

You should use comma to separate forms you are going to update like:

<p:ajax update=":transForm, :sprdForm" />   

It means there are two forms to be updated.
If you code like:

<p:ajax update=":transForm :sprdForm" />

Means you want to update sprdForm in the transForm, which it not possible since you can't put a form in another form.

nosnhoj
  • 793
  • 1
  • 12
  • 30
0

You are trying to compare a list with a single String:

rendered="#{transferMB.selectedItems == '1'}"

But instead, you should check if the list INCLUDES this single string:

In the html:

rendered="#{denemeBean.controlSelectedValues('1')}"

In the bean class:

// list should be initialized (unless, we'll get NullPointer 
// when using the below method)

private List<String> selectedItems = new ArrayList<>();

// This methods returns true if parameter is included in the 
// list of selected items

public boolean controlSelectedValues(String needed) {
    for (String string : selectedItems) {
        if (string.equals(needed)) {
            return true;
        }
    }
    return false;
}

Finally, I'm not sure if you really need to put those datatables inside forms. Below you can see working copy that I worked on: (of course you should replace outputTexts with your datatables)

// bean file

import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

@ManagedBean(name = "denemeBean")
@ViewScoped
public class DenemeBean implements Serializable {

    private List<String> selectedItems = new ArrayList<>();

    /**
     * @return the selectedItems
     */
    public List<String> getSelectedItems() {
        return selectedItems;
    }

    /**
     * @param selectedItems the selectedItems to set
     */
    public void setSelectedItems(List<String> selectedItems) {
        this.selectedItems = selectedItems;
    }

    public boolean controlSelectedValues(String needed) {
        for (String string : selectedItems) {
            if (string.equals(needed)) {
                return true;
            }
        }

        return false;
    }
}

// html file: 

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets">
    <h:head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    </h:head>
    <h:body>
        <h:form>

            <h:selectManyCheckbox value="#{denemeBean.selectedItems}">
                <f:selectItem itemValue="1" itemLabel="Transfer Status" />
                <f:selectItem itemValue="2" itemLabel="Spread Status" />
                <f:selectItem itemValue="3" itemLabel="Number1 - 3" />
                <p:ajax event="change" update=":tables" />
            </h:selectManyCheckbox>

        </h:form>

        <p:panel id="tables" >
            <p:panel id="transForm" rendered="#{denemeBean.controlSelectedValues('1')}">
                <h:outputText value="table1 Here" />
            </p:panel>

            <p:panel id="sprdForm" rendered="#{denemeBean.controlSelectedValues('2')}">
                <h:outputText value="table 2 Here" />
            </p:panel>
        </p:panel>
    </h:body>
</html>
Null Pointer
  • 344
  • 1
  • 2
  • 11
  • I tried as you mentioned, its throwing the exception on page. " rendered="#{searchMB.controlSelectedValues('1')}" Error Parsing: #{transferMB.controlSelectedValues('1')}". Exception on console: 1100: JSF1073: javax.faces.view.facelets.TagAttributeException caught during processing of RENDER_RESPONSE 6 @Null Pointer. – user3684675 Jun 17 '14 at 13:19
  • done as you suggested, facing the exception. Please see the above post modified and included the exception - @Null Pointer. – user3684675 Jun 18 '14 at 02:16
  • I guess that you can't pass parameters in your call. (related to Expression Language (EL) but I don't know the details). So, you'll need to change this call & related control method to a non parameter style. Like: "rendered="#{denemeBean.controlTableA}"" and "public boolean controlTableA(){controlSelectedValues("1");}" This way, you have a method for each control. And these methods call our main method with the necessary parameter. – Null Pointer Jun 19 '14 at 08:17
0

Using <p:ajax update=":transForm :sprdForm" /> is totally valid. You have multiple other issues here.

First point: Your rendered-attribute compares a List with a String (selectedItems=='1'). It should test if the List contains the String (selectedItems.contains('1')). (Attention: You must use EL 2.2 for this)

Second point is: I think <p:panelGrid> needs the columns-attribute. I stripped down your code and this works fine for me:

<h:body>
<h:form>
    <p:selectManyCheckbox value="#{transferMB.selectedItems}">
        <f:selectItem itemValue="1" itemLabel="Transfer Status" />
        <f:selectItem itemValue="2" itemLabel="Spread Status" />
        <f:selectItem itemValue="3" itemLabel="Number1 - 3" />
        <p:ajax update=":transForm :sprdForm"/>
    </p:selectManyCheckbox>
</h:form>

<h:form id="transForm">
    <p:panelGrid columns="1" rendered="#{transferMB.selectedItems.contains('1')}">
        transForm
    </p:panelGrid>
</h:form>

<h:form id="sprdForm">
    <p:panelGrid columns="1" rendered="#{transferMB.selectedItems.contains('2')}">
        sprdForm
    </p:panelGrid>
</h:form>
</h:body>

I used <p:selectManyCheckbox> because <h:selectManyCheckbox> with inner <p:ajax> resulted in java.lang.ClassCastException: java.lang.Boolean cannot be cast to org.primefaces.component.api.ClientBehaviorRenderingMode. I think this could be a bug in my JSF Implementation jsf-impl-2.1.7-jbossorg-2.jar.

Ishkafel
  • 333
  • 1
  • 10
  • Facing following exception when tried as mentioned in above posts: " rendered="#{searchMB.controlSelectedValues('1')}" Error Parsing: #{transferMB.controlSelectedValues('1')}". Exception on console: 1100: JSF1073: javax.faces.view.facelets.TagAttributeException caught during processing of RENDER_RESPONSE 6 . @Ishkafel – user3684675 Jun 17 '14 at 13:19
  • What is the root-Exception in the Stacktrace? With the information given we could only guess. Always check for NullPointerException (List initialized?). You also mentioned searchMB and transferMB in the comment, check your code: Which one do you use? The method `controlSelectedValues` basically does the same as `contains` on a List, why not use this? – Ishkafel Jun 18 '14 at 06:18
  • I found http://stackoverflow.com/questions/24271045/javax-faces-view-facelets-tagattributeexception/24278653#24278653 where you ask the same question. Please see my suggestion posted there – Ishkafel Jun 18 '14 at 06:42