issue while loading data

喜夏-厌秋 提交于 2019-12-25 02:54:39

问题


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

回答1:


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.




回答2:


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>



回答3:


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.



来源:https://stackoverflow.com/questions/24246714/issue-while-loading-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!