Retrieving value from selectManyCheckbox
cash1981 May 20, 2008 11:22 AMI am quite new to Seam, and I have tried googling for this, but found only JSF related stuff.
I have another post on this, but since this is a new problem I guess I can post it here.
I am trying to retrieve the values the users chooses from a selectManyCheckbox. The problem is that the List always has the same elements inside. Even if I uncheck all the boxes and submit the form it still is the same list with all the elements.
Hope to get some clarification.
This is my xhtml code:
<h:form id="searchCriteria" styleClass="edit">
<s:decorate template="../layout/display.xhtml">
<label>Søk på Person</label>
<h:inputText id="searchStringPerson" value="#{searchRegisterManager.searchStringPerson}" />
<br/>
<label>Søk på Kommune</label>
<h:inputText id="searchStringKommune" value="#{searchRegisterManager.searchStringKommune}" />
<br/>
<br/>
<label>Inneholder prøvetyper:</label>
<h:selectManyCheckbox value="#{provetypeSokSelectedList}" border="1">
<s:selectItems value="#{proevetypeSokList}" var="proevetype" label="#{proevetype.beskrivelse}"/>
</h:selectManyCheckbox>
<br/>
<h:commandButton id="findProever" value="Finn Prøver" action="#{searchRegisterManager.find}"/>
</s:decorate>
</h:form>This is my Action class:
@Stateful
@Name("searchRegisterManager")
@Scope(ScopeType.SESSION)
//@Restrict("#{identity.loggedIn}")
public class SearchRegisterManagerAction implements SearchRegisterManager, Serializable {
private static final long serialVersionUID = 7218402377558637175L;
@PersistenceContext(type = EXTENDED)
private EntityManager em;
private String searchStringPerson;
private String searchStringKommune;
@SuppressWarnings("unused")
@DataModel
private List<Proeve> proeveSokList;
@SuppressWarnings("unused")
@Out(required=false)
private List<Proevetype> proevetypeSokList;
@SuppressWarnings("unused")
@Out(required=false)
//@In(required=false)
private List<Proevetype> provetypeSokSelectedList;
@Logger
private Log log;
@SuppressWarnings("unchecked")
private void findProever() {
proeveSokList = em.createQuery(
"from " + Proeve.class.getName() + " p "
+ "where (lower(p.person.fornavn) like #{patternPerson} OR lower(p.person.etternavn) like #{patternPerson} "
+ "OR lower(p.person.personnummer) like #{patternPerson})"
+ "AND (lower(p.kommune.navn) like #{patternKommune} OR lower(p.kommune.kommunenummer) like #{patternKommune}) "
+ "order by p.person.etternavn").getResultList();
}
@Factory(value= "proevetypeSokList")
@SuppressWarnings("unchecked")
public void findProevetyper() {
proevetypeSokList = em.createQuery("from " + Proevetype.class.getName() + " pt ").getResultList();
}
@Factory(value= "provetypeSokSelectedList")
@SuppressWarnings("unchecked")
public void findProevetypeSokSelected() {
provetypeSokSelectedList = em.createQuery("from " + Proevetype.class.getName() + " pt ").getResultList();
}
/**
* Creates a factory name patternPerson so you can call it with the \#{name}
* in the query. It will return '%' if it is null and and put '%' in the
* beginning and last of the textfield and also replace '*' with '%'
*/
@Factory(value = "patternPerson", scope = ScopeType.EVENT)
public String getSearchPatternPerson() {
return searchStringPerson == null ? "%" : '%' + searchStringPerson.toLowerCase().replace('*', '%') + '%';
}
/**
* Creates a factory name patternKommune so you can call it with the
* \#{name} in the query. It will return '%' if it is null and and put '%'
* in the beginning and last of the textfield and also replace '*' with '%'
*/
@Factory(value = "patternKommune", scope = ScopeType.EVENT)
public String getSearchPatternKommune() {
return searchStringKommune == null ? "%" : '%' + searchStringKommune.toLowerCase().replace('*', '%') + '%';
}
public String getSearchStringPerson() {
return searchStringPerson;
}
public void setSearchStringPerson(String searchStringPerson) {
this.searchStringPerson = searchStringPerson;
}
public String getSearchStringKommune() {
return searchStringKommune;
}
public void setSearchStringKommune(String searchStringKommune) {
this.searchStringKommune = searchStringKommune;
}
@Override
public void find() {
for (Proevetype pt : provetypeSokSelectedList) {
log.info("prøvetype: " + pt.getBeskrivelse());
}
findProever();
}
@Destroy
@Remove
public void destroy() {
}
}