【问题标题】:Parsing argument with JSF commandlink to managed bean [duplicate]使用 JSF 命令解析参数链接到托管 bean [重复]
【发布时间】:2016-06-06 08:22:39
【问题描述】:

我尝试使用 JSF 将参数解析为使用 ajax 的托管 bean。我的 JSF 代码是这样的

        <h:commandLink id="user" action="#{pageBean.setPage("user")}" >
                                    user
                   <f:ajax execute="user" render="contentBody" />

       </h:commandLink>

托管bean是这个

@ManagedBean
public class PageBean {
    private String path;
    private String page;

    public PageBean() {
    }

    @PostConstruct
    public  void init(){
        path = "/WEB-INF/dashboard.xhtml";
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public String getPage() {
        return page;
    }

    public void setPage(String page) {
        this.page = page;
    }
 }

但是当我运行它时,我得到了以下错误。这是为什么?

Error Parsing /WEB-INF/templete.xhtml: Error Traced[line: 37] Element type "h:commandLink" must be followed by either attribute specifications, ">" or "/>".

【问题讨论】:

    标签: jsf jsf-2 el commandlink


    【解决方案1】:

    您在 user 周围的属性中使用了双引号。

    <h:commandLink id="user" action="#{pageBean.setPage("user")}" >
    

    这导致templete.xml 不是有效的 XML 文件。

    使用单引号的正确示例行(由@gWombat 提出):

    <h:commandLink id="user" action="#{pageBean.setPage('user')}" >
    

    【讨论】:

      【解决方案2】:

      你应该在参数user周围使用简单的引号:

      action="#{pageBean.setPage('user')}"
      

      【讨论】:

        猜你喜欢
        • 2017-06-14
        • 2016-07-09
        • 2011-08-07
        • 2012-11-09
        • 2013-07-01
        • 2011-11-06
        • 2011-11-23
        • 2016-05-09
        相关资源
        最近更新 更多