【问题标题】:h:inputSecret getter method not being calledh:inputSecret getter 方法没有被调用
【发布时间】:2014-08-19 09:29:50
【问题描述】:

版本:

Aapche MyFaces 2.1.14

RichFaces 4.3.5

问题:

我面临着非常奇怪的标签问题。 如下代码所示,第一次渲染from时,应该调用bean.getPassword方法。

但似乎在第一次呈现表单时(在进行回发之前)没有调用此方法。我已经通过调试验证了它。 奇怪的是,如果我把h:inputSecret 的EL 放在页面的其他地方,这个方法确实会被调用

我真的被卡住了,为什么会这样? 有没有人遇到过这样的问题?

代码:

<h:form prependId="false">

        <!-- check whether getter is called , it gets called in this case -->

    #{bean.password}

    <h:panelGrid columns="2">

            <h:outputText value="User ID:"/>
            <h:inputText value="#{bean.userId}"/>


            <h:outputText value="Password:"/>
            <h:inputSecret id="passwd1" name="passwd1" required="true" value="#{bean.password}"
                                requiredMessage="Password is required"/>

    <h:panelGrid>


</h:form>

【问题讨论】:

    标签: jsf-2 myfaces


    【解决方案1】:

    默认情况下,&lt;h:inputSecret&gt; 出于安全原因不会重新显示模型值(原始密码即在生成的 HTML 源代码中可见)。您需要将其redisplay 属性显式设置为true。另请参阅tag documentation(强调我的):

    将组件的clientId渲染为“name”属性的值。将组件的当前值渲染为“value”属性的值,当且仅当“redisplay”组件属性为字符串“true”。如果指定了“styleClass”属性,则将其值渲染为“class”属性的值。

    所以,应该这样做:

    <h:inputSecret ... redisplay="true" />
    

    希望您了解安全隐患。您通常只在提交表单时在其他字段上出现验证错误时才这样做,以避免用户因重新输入(有效?)密码而烦恼。像这样的:

    <h:inputSecret ... redisplay="#{facesContext.postback and component.valid}" />
    

    【讨论】:

    • 非常感谢您的回复。上述设置有效。我真的要感谢您在公共论坛上发布的所有 JSF 帖子。我从这些帖子中学到了很多东西。
    猜你喜欢
    • 2020-10-02
    • 2012-03-13
    • 2014-06-02
    • 2011-08-28
    • 2017-02-24
    • 2015-02-23
    • 2013-12-19
    • 1970-01-01
    相关资源
    最近更新 更多