在PrimeFaces 3.5中使用p:resetInput和Spring bean

时间:2013-06-26 16:01:10

标签: spring jsf jsf-2 primefaces

我尝试使用<p:resetInput>代表它。这工作正常,直到我使用@org.springframework.stereotype.Controller注释JSF bean。

XHTML页面:

<h:form id="form" prependId="true">
        <p:panel id="panel" header="New" style="margin-bottom:10px;" toggleable="true" toggleOrientation="horizontal">  
            <h:panelGrid id="panelGrid" columns="3" cellpadding="5">
                <h:outputLabel for="txtName" value="State *" />
                <p:inputText id="txtName" value="#{testManagedBean.txtName}" label="Name" required="true" maxlength="45">
                    <f:validateLength minimum="2" maximum="45" />
                </p:inputText>
                <p:message for="txtName"/>                    
            </h:panelGrid>

            <p:commandButton id="btnSubmit" update="panel" actionListener="#{testManagedBean.submit}" type="submit" ajax="true" value="Save" icon="ui-icon-check"/>

            <p:commandButton value="Reset" update="panel" process="@this">  
                <p:resetInput target="panel" />  
            </p:commandButton>
        </p:panel>
</h:form>

JSF托管bean:

@ManagedBean
@RequestScoped
public final class TestManagedBean
{
     private String txtName;

     //Setters and getters.
}

当我有这样的JSF bean注释@Controller时,

@Controller
@ManagedBean
@RequestScoped
public final class TestManagedBean
{
     private String txtName;

     //Setters and getters.
}

当按下重置按钮的按钮时,这不起作用且唯一的UIInput组件<p:inputText>的值不会重置为null


这甚至不适用于actionListener

<p:commandButton value="Reset" update="panel" process="@this" actionListener="#{testManagedBean.reset()}" >  
    <p:resetInput target="panel" />  
</p:commandButton>

在JSF托管bean中,reset()方法定义如下。

public void reset()
{
    RequestContext.getCurrentInstance().reset("form:panel"); 
}

因此,最后,我只在托管bean中留下了以下选项。

public void reset()
{
    txtName=null;
}

手动重置该值。

有没有办法让<p:resetInput>正常工作?

1 个答案:

答案 0 :(得分:0)

当我像这样更改托管bean时,这很有效,

@Controller
@Scope("view")
public final class testManagedBean extends LazyDataModel<Bean> implements Serializable
{
    private String txtName; //Getter and setter.
}

正如评论所暗示的那样。之后,视图范围定义为this博客指示。

<p:commandButton id="btnSubmit" update="panel" actionListener="#{testManagedBean.submit}" icon="ui-icon-check" type="submit" ajax="true" value="Save"/>

<p:commandButton value="Reset" update="panel" process="@this">
    <p:resetInput target="panel" />
</p:commandButton>
在这种情况下,

actionListener是不必要的。因此,它将从重置按钮中删除。

我刚刚通过cut&amp;粘贴问题中的最后一个修改以从unanswered question list

中删除问题
相关问题