f:validateLongRange 在不应该实例化 Bean 的地方实例化 Bean
我有以下验证器:
<h:inputText id="orderC" value="#{columnEdit.selectedColumn.position}" maxlength="2" validatorMessage="#{columnEdit.valOrder}">
<f:validateLongRange maximum="#{columnEdit.maxOrder}" minimum="#{columnEdit.minOrder}" />
</h:inputText>
该验证器属于 JSF 页面,其支持 bean 是 ViewScoped。
相关代码片段:
public Integer getMaxOrder()
{
maxOrder = selectedFileFormat.getColumnList().size();
return maxOrder;
}
_
public Integer getMinOrder()
{
if (getIsCode())
{
minOrder = 1;
}
else
{
minOrder = 2;
}
return minOrder;
}
_
public String getValOrder()
{
valOrder = "Range of " + minOrder + " to " + maxOrder;
return valOrder;
}
_
我的页面上有一个取消按钮:
<p:commandButton value="#{i18n['xxx.cancel']}" action="#{columnEdit.cancel}" ajax="false">
<p:confirmDialog message="#{i18n['xxx.cancelConf']}" severity="warn" />
<f:param name="formatId" value="#{columnEdit.selectedFileFormat.id}"/>
<f:param name="navigationCase" value="edit"/>
</p:commandButton>
_
谁的行动:
public String cancel()
{
Integer theFormatId = selectedFileFormat.getId();
return "fileFormatEdit.xhtml"
}
_
我的问题:为什么按下取消按钮后会调用我的 bean 的 postConstruct?我发现原因是 f:validateLongRange
但为什么它要实例化一个新的 columnEdit bean?
I have the following validator:
<h:inputText id="orderC" value="#{columnEdit.selectedColumn.position}" maxlength="2" validatorMessage="#{columnEdit.valOrder}">
<f:validateLongRange maximum="#{columnEdit.maxOrder}" minimum="#{columnEdit.minOrder}" />
</h:inputText>
The validator belongs to a JSF page whose backing bean is ViewScoped.
The relevant code snippets:
public Integer getMaxOrder()
{
maxOrder = selectedFileFormat.getColumnList().size();
return maxOrder;
}
_
public Integer getMinOrder()
{
if (getIsCode())
{
minOrder = 1;
}
else
{
minOrder = 2;
}
return minOrder;
}
_
public String getValOrder()
{
valOrder = "Range of " + minOrder + " to " + maxOrder;
return valOrder;
}
_
There is a cancel button on my page:
<p:commandButton value="#{i18n['xxx.cancel']}" action="#{columnEdit.cancel}" ajax="false">
<p:confirmDialog message="#{i18n['xxx.cancelConf']}" severity="warn" />
<f:param name="formatId" value="#{columnEdit.selectedFileFormat.id}"/>
<f:param name="navigationCase" value="edit"/>
</p:commandButton>
_
Whose action:
public String cancel()
{
Integer theFormatId = selectedFileFormat.getId();
return "fileFormatEdit.xhtml"
}
_
My Question: why is the postConstruct of my bean being called after pressing the cancel button? I found that the cause is the f:validateLongRange
but why is it instantiating a new columnEdit bean?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这是因为您正在专门定义下一个视图以通过 return "fileFormatEdit.xhtml" 进行导航?
如果您打算返回同一页面,请尝试更改为返回 null(意味着没有导航,并使用当前活动视图)。
或者只需将操作方法定义更改为 public void cancel(),这样您就不必返回任何内容。
I think it's because you're are specifically defining the next view to navigate by return "fileFormatEdit.xhtml" ?
If you mean to return to the same page, try changing to return null (meaning no navigation, and make use the current active view).
Or simply change the action method definition to public void cancel(), where you dont have to return anything.