简体   繁体   中英

JSF CommandButton action before submit

I've created JSF 1.1 page. In the page I have 2 textboxes and commandbutton. The textboxes are connected to object in the backing bean, and thw object's values are showed there, and the user can edit it as he wants, and when he clicks on the button I want to go to the bean and save the new values in the object. The bean must be request, not session!

<h:inputText value="myBean.PersonName"><\h:inputText>
<h:commandButton action="myBean.saveEditName"><\h:inputText>

backingBean:

public String saveEditName(){
//Go to database and save the new object
}

The problem is, when I click on the button, the bean is refreshed, the objects returns to its previous values, and then the action is invoked. Why is that? How can I perform an action before the submit refreshes the bean? (Without using servlet in javascript).

Thanks!

Use Explicit Bean Declarations as Given Below:

<managed-bean>
<managed-bean-name>someName</managed-bean-name>
<managed-bean-class>
somePackage.SomeClass
</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM