1

我有一个页面,我正在使用 h:link 之类的

<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>

当我单击图像时,网址就可以了。URL变成了这样

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() 方法会调用。如何在构造函数中获取这些值,以便在构造函数中使用它?

谢谢

4

1 回答 1

2

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

<f:viewParam name="fromPage" value="#{countryPages_Setup.page}}" />
于 2012-05-09T06:14:38.033 回答