Product Logos BridgeIt Services Banner
ice selectonelistbox valueChangeListener  XML
Forum Index -> General Help
Author Message
nicevision2020

Joined: 28/Jul/2009 00:00:00
Messages: 10
Offline


Hi

Could you please tell me what i am doing wrong here. Whenever i change the drop down the textbox is not changed with new value. because of this whenever i change the drop down it updates the table from the textbox.

xhtml page...

'<ice:selectOneListbox id="accounts"
value="#{accountManagerService.selectedAccount}" size="1"
valueChangeListener="#{accountManagerService.accountChanged}"
partialSubmit="true" required="true">
<s:selectItems value="#{findAllActiveAccounts}" var="account"
label="#{account.description}" />
<s:convertEntity />
</ice:selectOneListbox>'

'<ice:inputText styleClass="freeFormInput" id="description"
value="${accountManagerService.selectedAccount.description}" required="true" />'

AccountManager.java

@Scope(ScopeType.CONVERSATION)
@Name("accountManagerService")
@AutoCreate
@Restrict("#{identity.loggedIn}")
public class AccountManager implements java.io.Serializable {

@In
private EntityManager entityManager;

private Account selectedAccount;

public void accountChanged(ValueChangeEvent evt) {
if (!evt.getPhaseId().equals(PhaseId.INVOKE_APPLICATION)) {
evt.setPhaseId(PhaseId.INVOKE_APPLICATION);
evt.queue();
return;
}
if (evt.getNewValue() != null) {
entityManager.flush();
FacesContext.getCurrentInstance().getResponseComplete();
selectedAccount = (Account) evt.getNewValue();
}
FacesContext.getCurrentInstance().responseComplete();
}

When the page loades from the s:link it sets the right description based on the drop down list, after everychange there is no change in description. Inside the event the it setting the right selectedaccount object before it displayed in the page, it got updated with old description.

1. How do i refesh the description from the selectedAccount.
2. I think because of not changing the description seam think the object is dirty.

Thanks in advance
judy.guglielmin

Joined: 20/Feb/2007 00:00:00
Messages: 1304
Offline


just to be clear, please specify the version of Seam and ICEfaces. It looks like you are using a factory for your generated list that back the selectItems components, but then you are changing the selected account, and the selectItems, while changing the account the label is not updated (hopefully I have understood the problem correctly).

I'm not sure why you require the valueChangeListener, but perhaps you could try the following:-

Code:
 <ice:selectOneListbox value="#{accountManagerService.selectedAccount}" partialSubmit="true">
     <s:selectItems var="account" value="#{findAllActiveAccounts}" label="#{account.descirption}"/>
     <s:convertEntity/>
 </ice:selectOneListbox>
 


This will automatically update the value selected in the backing bean. Also, you could define #{findAllActiveAccounts} in components.xml this way:-
Code:
   <factory name="findAllActiveAccounts" value="#{accountQuery.resultList}" scope="stateless"/>
 

making the factory stateless so the values aren't cached.
nicevision2020

Joined: 28/Jul/2009 00:00:00
Messages: 10
Offline


Thanks for your response. I tried your way. Whenever i change the drop down the data got updated in the DB. There is no change in the inputtext..

'<ice:inputText styleClass="freeFormInput" id="description"
value="${accountManagerService.selectedAccount.description}" required="true" />'


Here is what i am trying to get it.

1. Retrieve data into dropdown list box.
2. Corresponding dropdown selected description can be shown.
3. User can modify the description and click save it saves into the database.
4. User can do soft delete.

Only thing i noticed even i updated the db with entitymanager persist on the delete, the page is not refreshed.

ICEfaces : 1.8.1_7
Seam : 2.1.1.GA

judy.guglielmin

Joined: 20/Feb/2007 00:00:00
Messages: 1304
Offline


Are you not using manual flush for hibernate? This is the recommended setting for hibernate when using ICEfaces (performance-wise is best as well).
nicevision2020

Joined: 28/Jul/2009 00:00:00
Messages: 10
Offline


Here is the full backing bean code.

'@Scope(ScopeType.CONVERSATION)
@Name("accountManagerService")
@AutoCreate
@Restrict("#{identity.loggedIn}")
public class AccountManagerImpl implements java.io.Serializable {

@In
private EntityManager entityManager;

private Account selectedAccount;

private List<Account> accounts;

/**
*
*/
@Create
public void initialize() {
// Select the first account by default
accounts = findAccounts();
selectedAccount = accounts.get(0);
}

/**
*
*/
public void save() {
entityManager.persist(selectedAccount);
}

/**
* This method used to do soft delete on the record. <br>
*
*/
public void delete() {
selectedAccount.setDeleteFlag(CamsConstants.DELETE);
entityManager.persist(selectedAccount);
}

/**
* This method returns the Selected Account Object to the Calling Methods.
*
* @return Return selectedAccount {@link Account} object
*/
public Account getSelectedAccount() {
return selectedAccount;
}

/**
* This method sets the Account object
*
* @param selectedAccount
* selectedAccount to set
*/
public void setSelectedAccount(Account selectedAccount) {
this.selectedAccount = selectedAccount;
}

@SuppressWarnings("unchecked")
private List<Account> findAccounts() {
List<Account> accounts = (List<Account>) entityManager.createQuery(
Messages.instance().get("findAllActiveAccounts"))
.getResultList();

return accounts;
}

/**
* This is a JSF <code>ValueChangeListener</code> invoked when
* {@link Account} is changed.
*
*/
public void accountChanged(ValueChangeEvent evt) {

if (!evt.getPhaseId().equals(PhaseId.INVOKE_APPLICATION)) {
evt.setPhaseId(PhaseId.INVOKE_APPLICATION);
evt.queue();
return;
}

if (evt.getNewValue() != null) {
entityManager.flush();
FacesContext.getCurrentInstance().responseComplete();
selectedAccount = ((Account) evt.getNewValue());
}
}
}'

nicevision2020

Joined: 28/Jul/2009 00:00:00
Messages: 10
Offline


Please note that i haven't added valuechangelisterner as per your previous response.
judy.guglielmin

Joined: 20/Feb/2007 00:00:00
Messages: 1304
Offline


Hibernate allows you to use either automatic flush (default behaviour) or manual flush which you have to use as a page action defined as follows:-

Code:
<begin-conversation join="true" flush-mode="manual"/> 

just as an example. If you generate a project using seam-gen with the default templates of ICEfaces, then you can see that any of the edit pages will have this feature. Another way to use it is to annotate a method with:-
Code:
@Begin(flushMode=MANUAL)


Otherwise, you may not want to use a managed entity right away. If you extend the EntityHome object of Seam (SMPC), then you can also use the find(id) method to load the managed entity after verifying it's the one you want...so when you select it, you just select the id rather than the entire entity (using page parameters).
nicevision2020

Joined: 28/Jul/2009 00:00:00
Messages: 10
Offline


Sorry this project is not created using seam gen. I just hope into project and going along the flow.
judy.guglielmin

Joined: 20/Feb/2007 00:00:00
Messages: 1304
Offline


Since it looks like you are using SMPC, you really should quickly just reverse generate a table or two to see how things are handled. much easier in the long run (it only takes a few minutes to run it).
 
Forum Index -> General Help
Go to:   
Powered by JForum 2.1.7ice © JForum Team