This content has been marked as final.
Show 2 replies
-
1. Re: action with s:convertEntity doesn't work
nickarls Sep 23, 2008 8:16 AM (in response to gred)Show code.
Add a h:messages to see if there are any validation errors.
-
2. Re: action with s:convertEntity doesn't work
gred Sep 23, 2008 11:10 AM (in response to gred)<h:messages> is already included in my page and no messages appear, neither jsf or log messages.
Here is the code of the EJB which works as a backing bean for my page:
@Name("testAction")
@Stateful
public class TestAction implements TestLocal {
private String myString;
@EJB
CategoryDAO categoryDAO;
List<Category> primaryCategories = null;
Category selectedCategory = null;
public String myAction() {
return null;
}
public List<SelectItem> getStrings() {
return strings;
}
@Create @Begin
public void init() {
primaryCategories = categoryDAO.getAllPrimaryCategories();
}
public void setMyString(String myString){
this.myString = myString;
}
public String getMyString() {
return myString;
}
@Remove @Destroy
public void destroty() {}
/**
* @return the primaryCategories
*/
public List<Category> getPrimaryCategories() {
return primaryCategories;
}
/**
* @param primaryCategories the primaryCategories to set
*/
public void setPrimaryCategories(List<Category> primaryCategories) {
this.primaryCategories = primaryCategories;
}
/**
* @return the selectedCategory
*/
public Category getSelectedCategory() {
return selectedCategory;
}
/**
* @param selectedCategory the selectedCategory to set
*/
public void setSelectedCategory(Category selectedCategory) {
this.selectedCategory = selectedCategory;
}
}
The primaryCategories list (list of Category jpa entity) will feed the s:selectItems and the selectedCategory will be the one that the user will select in the page. The code of the <h:selectOneMenu> is the following:
<h:selectOneMenu value="#{testAction.selectedCategory}" id="categSel">
<s:selectItems value="#{testAction.primaryCategories}" var="cat" label="#{cat.description}"
noSelectionLabel="Select..." hideNoSelection="true"/>
<s:convertEntity/>
</h:selectOneMenu>
And the complete code of the page:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:s="http://jboss.com/products/seam/taglib"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:rich="http://richfaces.ajax4jsf.org/rich"
template="layout/template.xhtml">
<ui:define name="body">
<h:messages globalOnly="true" styleClass="message" id="globalMessages"/>
<h:form id="dummyform" styleClass="edit">
<rich:simpleTogglePanel label="Currency search parameters" switchType="ajax">
<s:decorate template="layout/display.xhtml">
<ui:define name="label">A dummy String</ui:define>
<h:inputText value="#{testAction.myString}" id="myStringTxt"/>
</s:decorate>
<s:decorate template="layout/display.xhtml">
<ui:define name="label">Select Category</ui:define>
<h:selectOneMenu value="#{testAction.selectedCategory}" id="categSel">
<s:selectItems value="#{testAction.primaryCategories}" var="cat" label="#{cat.description}"
noSelectionLabel="Select..." hideNoSelection="true"/>
<s:convertEntity/>
</h:selectOneMenu>
</s:decorate>
</rich:simpleTogglePanel>
<div class="actionButtons">
<h:commandButton id="search" value="Search" action="#{testAction.myAction}"/>
</div>
</h:form>
</ui:define>
</ui:composition>
As I mentioned in my first message, when clicking on the <h:commandButton value="Search" action="testAction.myAction"/> the action myAction - method of the testAction bean - is never called.
After removing just the <s:convertEntity/> everything works as expected and the myAction function is called properly.
Thanks again.