You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by "df2@wm.ru" <df...@wm.ru> on 2007/04/29 22:56:47 UTC
still save it after form validation errors ?
Hello again.
I have little question about <t:saveState>
I have following control in my edit form:
<h:commandLink action="#{CategoryBean.delete}" value="Delete"
styleClass="dl" rendered="#{CategoryBean.editmode}" />
As you can see, it uses rendered attribute and rendered only if someone
editing item. Because backing bean is request scoped i tried to use
<t:saveState> to preserve state of bean and added to beginning of the form:
<t:saveState value="#{CategoryBean} id="save1" />
And it seem worked, but if someone submits form with validation errors,
after form reloads that "Delete" button stops working again.
Any clue ? Thanx.
Re: still save it after form validation errors ?
Posted by Simon Kitching <si...@rhe.co.nz>.
If you have a validation error on the current page, then no action will
be invoked. That's a fundamental part of JSF: actions only get executed
after the backing bean properties have been updated. However properties
cannot be updated if the user data is not valid! So if any field in the
page is invalid then *no* properties get updated in the backing bean and
*no* actions get executed; the page is simply re-rendered (with
validation messages displayed if you have an h:messages tag).
If you really want an action to be executed even when the current page
has invalid data then you need to mark that action with
"immediate=true". Note, however, that if you do that then none of the
user data (ie input fields on that page) will be stored into the backing
bean.
Regards,
Simon
df2@wm.ru wrote:
> Simon Kitching пишет:
>> What do you mean by "stops working"?
>
> I mean, when i pressing it, page simply reloads while backing bean
> method not invoked.
>
>>
>> And where is this "category" variable referenced in the delete method
>> declared? Why is it not null?
>
> Oh, yes, here is all about category:
>
> // members declaration:
> private Category category;
> private boolean editmode;
>
> // Constructor: category initialized with empty domain object
> public CategoryBean() {
> category = new Category();
> category.setParent(new Category());
> }
>
>
>>
>> df2@wm.ru wrote:
>>> Thank you for your answer.
>>> Where should i else start looking ?
>>> I think that i checked everything, the form finally shrinked down and
>>> now it really simple:
>>>
>>> <t:saveState value="#{CategoryBean.editmode}"/>
>>> <h:form>
>>> <h:inputText id="name" value="#{CategoryBean.category.name}"
>>> required="true" maxlength="255" />
>>> <h:message for="name" style="color: red" />
>>>
>>> <h:commandLink action="#{CategoryBean.submit}" value="Save"
>>> styleClass="cl" />
>>> <h:commandLink action="#{CategoryBean.delete}" value="Delete"
>>> styleClass="dl" rendered="#{CategoryBean.editmode}" />
>>> </h:form>
>>>
>>> and commandLink actions:
>>>
>>> public String delete() throws SQLException {
>>> CategoryDAO dao = SqlMapDAOFactory.getCategoryDAO();
>>> int deleted = dao.deleteById(category.getId().intValue());
>>> return "category_list";
>>> }
>>>
>>> public String submit() throws SQLException {
>>> CategoryDAO dao = SqlMapDAOFactory.getCategoryDAO();
>>> dao.update(category);
>>> return "category_list";
>>> }
>>>
>>>
>>> But "Delete" button stops working if "Submit" was pressed before and
>>> validation error occurs because of: required="true" in text field.
>>> Everything looks pretty bulletproof :\
>>>
Re: still save it after form validation errors ?
Posted by "df2@wm.ru" <df...@wm.ru>.
Simon Kitching пишет:
> What do you mean by "stops working"?
I mean, when i pressing it, page simply reloads while backing bean
method not invoked.
>
> And where is this "category" variable referenced in the delete method
> declared? Why is it not null?
Oh, yes, here is all about category:
// members declaration:
private Category category;
private boolean editmode;
// Constructor: category initialized with empty domain object
public CategoryBean() {
category = new Category();
category.setParent(new Category());
}
>
> df2@wm.ru wrote:
>> Thank you for your answer.
>> Where should i else start looking ?
>> I think that i checked everything, the form finally shrinked down and
>> now it really simple:
>>
>> <t:saveState value="#{CategoryBean.editmode}"/>
>> <h:form>
>> <h:inputText id="name" value="#{CategoryBean.category.name}"
>> required="true" maxlength="255" />
>> <h:message for="name" style="color: red" />
>>
>> <h:commandLink action="#{CategoryBean.submit}" value="Save"
>> styleClass="cl" />
>> <h:commandLink action="#{CategoryBean.delete}" value="Delete"
>> styleClass="dl" rendered="#{CategoryBean.editmode}" />
>> </h:form>
>>
>> and commandLink actions:
>>
>> public String delete() throws SQLException {
>> CategoryDAO dao = SqlMapDAOFactory.getCategoryDAO();
>> int deleted = dao.deleteById(category.getId().intValue());
>> return "category_list";
>> }
>>
>> public String submit() throws SQLException {
>> CategoryDAO dao = SqlMapDAOFactory.getCategoryDAO();
>> dao.update(category);
>> return "category_list";
>> }
>>
>>
>> But "Delete" button stops working if "Submit" was pressed before and
>> validation error occurs because of: required="true" in text field.
>> Everything looks pretty bulletproof :\
>>
Re: still save it after form validation errors ?
Posted by Simon Kitching <si...@rhe.co.nz>.
What do you mean by "stops working"?
And where is this "category" variable referenced in the delete method
declared? Why is it not null?
df2@wm.ru wrote:
> Thank you for your answer.
> Where should i else start looking ?
> I think that i checked everything, the form finally shrinked down and
> now it really simple:
>
> <t:saveState value="#{CategoryBean.editmode}"/>
> <h:form>
> <h:inputText id="name" value="#{CategoryBean.category.name}"
> required="true" maxlength="255" />
> <h:message for="name" style="color: red" />
>
> <h:commandLink action="#{CategoryBean.submit}" value="Save"
> styleClass="cl" />
> <h:commandLink action="#{CategoryBean.delete}" value="Delete"
> styleClass="dl" rendered="#{CategoryBean.editmode}" />
> </h:form>
>
> and commandLink actions:
>
> public String delete() throws SQLException {
> CategoryDAO dao = SqlMapDAOFactory.getCategoryDAO();
> int deleted = dao.deleteById(category.getId().intValue());
> return "category_list";
> }
>
> public String submit() throws SQLException {
> CategoryDAO dao = SqlMapDAOFactory.getCategoryDAO();
> dao.update(category);
> return "category_list";
> }
>
>
> But "Delete" button stops working if "Submit" was pressed before and
> validation error occurs because of: required="true" in text field.
> Everything looks pretty bulletproof :\
>
>>
>> Yes, t:saveState will save the data even when validation fails. The
>> "saving" process occurs when the JSF component tree is saved, and that
>> always occurs at the end of each request.
>>
>> Your problem must be something else...
>>
>> By the way, if all you want to save is that one property from
>> CategoryBean, then you should probably just save that, ie
>> <t:saveState value="#{CategoryBean.editmode}"/>
>> rather than the whole bean.
>>
>> Regards,
>>
>> Simon
>
Re: still save it after form validation errors ?
Posted by "df2@wm.ru" <df...@wm.ru>.
Thank you for your answer.
Where should i else start looking ?
I think that i checked everything, the form finally shrinked down and
now it really simple:
<t:saveState value="#{CategoryBean.editmode}"/>
<h:form>
<h:inputText id="name" value="#{CategoryBean.category.name}"
required="true" maxlength="255" />
<h:message for="name" style="color: red" />
<h:commandLink action="#{CategoryBean.submit}" value="Save"
styleClass="cl" />
<h:commandLink action="#{CategoryBean.delete}" value="Delete"
styleClass="dl" rendered="#{CategoryBean.editmode}" />
</h:form>
and commandLink actions:
public String delete() throws SQLException {
CategoryDAO dao = SqlMapDAOFactory.getCategoryDAO();
int deleted = dao.deleteById(category.getId().intValue());
return "category_list";
}
public String submit() throws SQLException {
CategoryDAO dao = SqlMapDAOFactory.getCategoryDAO();
dao.update(category);
return "category_list";
}
But "Delete" button stops working if "Submit" was pressed before and
validation error occurs because of: required="true" in text field.
Everything looks pretty bulletproof :\
>
> Yes, t:saveState will save the data even when validation fails. The
> "saving" process occurs when the JSF component tree is saved, and that
> always occurs at the end of each request.
>
> Your problem must be something else...
>
> By the way, if all you want to save is that one property from
> CategoryBean, then you should probably just save that, ie
> <t:saveState value="#{CategoryBean.editmode}"/>
> rather than the whole bean.
>
> Regards,
>
> Simon
Re: still save it after form validation errors ?
Posted by Simon Kitching <si...@rhe.co.nz>.
df2@wm.ru wrote:
> Hello again.
>
> I have little question about <t:saveState>
> I have following control in my edit form:
>
> <h:commandLink action="#{CategoryBean.delete}" value="Delete"
> styleClass="dl" rendered="#{CategoryBean.editmode}" />
>
> As you can see, it uses rendered attribute and rendered only if someone
> editing item. Because backing bean is request scoped i tried to use
> <t:saveState> to preserve state of bean and added to beginning of the
> form:
> <t:saveState value="#{CategoryBean} id="save1" />
>
> And it seem worked, but if someone submits form with validation errors,
> after form reloads that "Delete" button stops working again.
> Any clue ? Thanx.
Yes, t:saveState will save the data even when validation fails. The
"saving" process occurs when the JSF component tree is saved, and that
always occurs at the end of each request.
Your problem must be something else...
By the way, if all you want to save is that one property from
CategoryBean, then you should probably just save that, ie
<t:saveState value="#{CategoryBean.editmode}"/>
rather than the whole bean.
Regards,
Simon