[jboss-user] [JBoss Seam] - Converters, SelectItems
jumapama
do-not-reply at jboss.com
Sat Oct 13 16:22:03 EDT 2007
Hello, i have a problem which i have spent a lot of time. Somebody can show me a converter and selectItems example. I have the next code:
|
| @Name("cuentaConverter")
| @org.jboss.seam.annotations.faces.Converter(forClass=Cuenta.class)
| public class CuentaConverter implements Converter, Serializable{
|
| private static final long serialVersionUID = 1L;
| @In(create=true)
| private EntityManager entityManager;
|
| @Transactional
| public Object getAsObject(FacesContext context, UIComponent component, String value) throws ConverterException
| {
| String id=value;
| if(id!=null)
| return entityManager.find(Cuenta.class, id);
| return null;
| }
|
| public String getAsString(FacesContext context, UIComponent component, Object value) throws ConverterException
| {
| if(value instanceof Cuenta){
| Cuenta cuenta=(Cuenta) value;
| return cuenta.getIdCuenta().toString();
| }
| else return null;
|
| }
| }
|
| @Name("login")
| @Scope (SESSION)
| @Stateful
| public class LoginFacade implements LoginFacadeLocal{
|
| @PersistenceContext
| private EntityManager entityManager;
|
| @In(required=false) @Out(required=false)
| private Cliente user;
|
| @In(required=false) @Out(required=false)
| private Cuenta account;
|
| public void setUser(Cliente persona){
| this.user=persona;
| }
|
| public Cliente getUser(){
| return this.user;
| }
|
| public void setAccount(Cuenta cuenta){
| this.account=cuenta;
| }
|
| public Cuenta getAccount(){
| return this.account;
| }
|
| public Cliente findPersonaByPassword(){
|
| Cliente entity = null;
| try {
| entity=(Cliente)entityManager.createQuery("SELECT OBJECT(c) FROM Cliente c " +
| "WHERE c.password=#{cliente.password}")
| .getSingleResult();
| }
| catch (NoResultException noneFound) {
| }
| return entity;
| }
|
| public Cliente findPersonaByUsuario(){
|
| Cliente entity = null;
| try {
| entity=(Cliente)entityManager.createQuery("SELECT OBJECT(c) FROM Cliente c " +
| "WHERE c.usuario=#{cliente.usuario}")
| .getSingleResult();
| }
| catch (NoResultException noneFound) {
| }
| return entity;
| }
| @Create
| public String valida(){
| Cliente cliente;
| if((cliente=findPersonaByUsuario())!=null
| && findPersonaByPassword()!=null)
| {
| setUser(cliente);
| if (user instanceof Administrador)return "administradores";
| else if (user instanceof Cliente) return "clientes";
|
| }
| return "clientes";
| }
|
| @Destroy
| @Remove
| public void destroy(){}
|
| }
|
| <h:form>
| <h:panelGroup>
| <h:selectOneMenu id="cuenta" value="#{account}">
| <s:selectItems value="#{user.cuentas}" var="c"
| label="#{c.idCuenta}" />
| <h:message for="cuenta"></h:message>
| </h:selectOneMenu>
| </h:panelGroup>
| <h:commandButton type="submit"
| action="#{clienteFacade.disponibleCuenta}" />
| </h:form>
|
| Config Files
|
| <?xml version="1.0" encoding="UTF-8"?>
| <components xmlns="http://jboss.com/products/seam/components"
| xmlns:core="http://jboss.com/products/seam/core"
| xmlns:persistence="http://jboss.com/products/seam/persistence"
| xmlns:drools="http://jboss.com/products/seam/drools"
| xmlns:security="http://jboss.com/products/seam/security"
| xmlns:web="http://jboss.com/products/seam/web"
| xmlns:mail="http://jboss.com/products/seam/mail"
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
| xsi:schemaLocation="http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.0.xsd
| http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.0.xsd
| http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.0.xsd
| http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.0.xsd
| http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.0.xsd
| http://jboss.com/products/seam/web http://jboss.com/products/seam/web-2.0.xsd
| http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.0.xsd">
|
| <core:manager conversation-timeout="120000"/>
| <core:init jndi-pattern="BancoPopular/#{ejbName}/local"
| debug="true" />
|
| <persistence:managed-persistence-context name="entityManager"
| persistence-unit-jndi-name="java:/uiEntityManagerFactory" />
|
| <component name="org.jboss.seam.ui.entityConverter">
| <property name="entityManager">#{em}</property>
| </component>
|
| <?xml version="1.0" encoding="UTF-8"?>
| <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
| xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
| http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
|
| <!-- Seam -->
|
| <listener>
| <listener-class>
| org.jboss.seam.servlet.SeamListener
| </listener-class>
| </listener>
|
| <!-- JSF -->
|
| <listener>
| <listener-class>
| com.sun.faces.config.ConfigureListener
| </listener-class>
| </listener>
|
| <context-param>
| <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
| <param-value>.xhtml</param-value>
| </context-param>
|
| <servlet>
| <servlet-name>Faces Servlet</servlet-name>
| <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
| <load-on-startup>1</load-on-startup>
| </servlet>
|
| <servlet-mapping>
| <servlet-name>Faces Servlet</servlet-name>
| <url-pattern>*.seam</url-pattern>
| </servlet-mapping>
|
| <session-config>
| <session-timeout>10</session-timeout>
| </session-config>
|
| <context-param>
| <param-name>javax.faces.CONFIG_FILES</param-name>
| <param-value>/WEB-INF/navigation.xml</param-value>
| </context-param>
|
| </web-app>
|
| <?xml version="1.0" encoding="UTF-8"?>
| <faces-config version="1.2"
| xmlns="http://java.sun.com/xml/ns/javaee"
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
| xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
|
| <!-- Facelets support -->
| <application>
| <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
| </application>
|
| </faces-config>
|
The selectitems menu renders well but show me an error when i select an item:
Validation error: it doesn't right error
Please i need help!!, i have been a lot of time and i cant find the solution.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4094913#4094913
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4094913
More information about the jboss-user
mailing list