从URL获取值时遇到错误(javax.el.PropertyNotWritableException :)

时间:2012-05-09 05:57:53

标签: jsf-2

我有一个页面,我正在使用h:link like

<h:link outcome="countryPages_View.xhtml">
    <img src="images/afghanistan.png" style="border: none;"/>
    <f:param name="SaarcCountryId" value="11" />
    <f:param name="once" value="true" />
    <f:param name="fromPage" value="homePage" />
</h:link>

<h:link outcome="countryPages_View.xhtml">
    <h:graphicImage  url="images/bangladesh.png" style="margin-left:10px;border: none" />
    <f:param name="SaarcCountryId" value="5" />
    <f:param name="once" value="true" />
    <f:param name="fromPage" value="homePage" />
</h:link>

当我点击图片时,网址就变好了。网址就像这样

http://localhost:8080/WIT/faces/countryPages_View.xhtml?SaarcCountryId=1&once=true&fromPage=homePage

然后在我的页面上我得到这样的值

<ui:composition template="./WEB-INF/templates/layout.xhtml">
    <ui:define name="title">SAARC Country View</ui:define>
    <ui:define name="content">
        <f:metadata>
            <f:viewParam name="SaarcCountryId" value="#{countryPages_Setup.cntryid}" />
            <f:viewParam name="once" value="#{countryPages_Setup.onse}" />
            <f:viewParam name="fromPage" value="#{countryPages_Setup.page}}" />
            <f:event type="preRenderView" listener="#{countryPages_Setup.beforeRenderPage}" />
        </f:metadata>
        <h:form id="countryPages" prependId="false">
            ....
        </h:form>

    </ui:define>
</ui:composition>

我的豆就像这样

@ManagedBean
@ViewScoped
public class CountryPages_Setup implements Serializable {
    private String cntryid;
    private String page;
    private String onse;

    public void beforeRenderPage(ComponentSystemEvent event) {
        System.out.println(page);
        System.out.println(onse);
        System.out.println(cntryid);        
    } //end of beforeRenderPage()

    //Constructor
    public CountryPages_Setup() {

    } //end of constructor

    // getter and setter
    public String getCntryid() {
        return cntryid;
    }
    public void setCntryid(String cntryid) {
        this.cntryid = cntryid;
    }
    public String getOnse() {
        return onse;
    }
    public void setOnse(String onse) {
        this.onse = onse;
    }
    ...
} //end of class CountryPages_Setup

当我的页面加载时,我收到错误。

exception
javax.servlet.ServletException: javax.el.PropertyNotWritableException: /countryPages_View.xhtml @20,88 value="#{countryPages_Setup.page}}": Illegal Syntax for Set Operation

root cause
javax.faces.component.UpdateModelException: javax.el.PropertyNotWritableException: /countryPages_View.xhtml @20,88 value="#{countryPages_Setup.page}}": Illegal Syntax for Set Operation

root cause
javax.el.PropertyNotWritableException: /countryPages_View.xhtml @20,88 value="#{countryPages_Setup.page}}": Illegal Syntax for Set Operation

为什么我收到此错误?我为我的视图参数设置了setter和getter?此外,当页面加载时,首先我的构造函数调用。我想在我的构造函数中使用这些f:param值。我认为在构造函数之后我的beforeRenderPage()方法会调用。如何在构造函数中获取这些值,以便我可以在构造函数中使用它?

由于

1 个答案:

答案 0 :(得分:2)

表达式末尾有第二个括号:page}}

<f:viewParam name="fromPage" value="#{countryPages_Setup.page}}" />