1
我試圖使用<p:resetInput>
,因爲它代表。這工作正常,直到我用@org.springframework.stereotype.Controller
註解JSF bean。在PrimeFaces中使用p:resetInput和Spring bean 3.5
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豆與@Controller
像這樣註釋,
@Controller
@ManagedBean
@RequestScoped
public final class TestManagedBean
{
private String txtName;
//Setters and getters.
}
這不起作用只有按下重置該值的按鈕時,纔會將值爲<p:inputText>
的唯一UIInput組件的值重置爲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>
工作,因爲它代表?
爲什麼你不斷將JSF和Spring bean管理註釋混合在一個錯誤的假設中,即他們彼此理解?你在之前的所有問題中都一直這樣做。特定於Spring的bean註冊註釋'@ Controller'默認爲應用程序範圍,但是您不知何故,JSF特定的bean範圍註釋'@ RequestScoped'被Spring奇蹟般地識別。您應該使用Spring的自己的作用域註釋,並*拋棄兩個JSF bean管理註釋,因爲它們完全沒有效果,並且只會讓維護者感到困惑。 – BalusC
謝謝。我現在意識到了。 – Tiny