[jboss-user] [JBoss Seam] - Re: Handling dynamic data in RDBMS (i.e. no direct column ma
tailor
do-not-reply at jboss.com
Sat Dec 1 07:19:08 EST 2007
After some further investigation I'm now able to do what I want. I can now modify multiple rows at once in one transaction.
My SLSB with an added update() method:
@Stateless
| @Name("recordList")
| public class RecordListAction implements RecordList, Serializable {
|
| private static final long serialVersionUID = 1L;
|
| @PersistenceContext
| private EntityManager em;
|
| @In
| private User user;
|
| @DataModel
| private List<DataValue> dataValues;
|
| @In
| private FacesMessages facesMessages;
|
| // needed to prevent spurious warning
| // getResultList() returns a non generic version of List
| @SuppressWarnings("unchecked")
| @Factory("dataValues")
| public void getDataValues() {
| dataValues = em.createQuery(
| "select dv from DataValue dv "
| + "inner join dv.record as record "
| + "inner join dv.dataType as dataType "
| + "where record.user.id = :userId")
| .setParameter("userId", user.getId())
| .getResultList();
| }
|
| @TransactionAttribute
| public void update() {
| for (DataValue dataValue : dataValues) {
| em.merge(dataValue);
| }
| facesMessages.add("Data successfully saved.");
| }
|
| @Remove
| public void destroy() {
| }
| }
My corresponding facelet:
<h:form>
| <rich:panel>
| <f:facet name="header">Edit Data</f:facet>
|
| <ui:repeat var="dataValue" value="#{dataValues}">
|
| <s:decorate id="idDecoration" template="layout/edit.xhtml">
| <ui:define name="label">
| <h:outputText value="#{dataValue.dataType.name}" />
| </ui:define>
|
| <h:inputText value="#{dataValue.value}" />
| </s:decorate>
|
| </ui:repeat>
|
| <div style="clear: both"><span class="required">*</span>
| required fields</div>
| </rich:panel>
|
| <div class="actionButtons"><h:commandButton
| action="#{recordList.update}" value="submit" /></div>
| </h:form>
Everything fine so far, but I'm now stucked at validating entered data. The actual data is stored in the column "value" of the table "data_value". The column "value" is a varchar(255) in MySQL but its validation rules depend on "data_type_id" which references the table "data_type".
To give you an example:
There are 2 entries in "data_type". One is a type for e-mail addresses and one for surnames. This results in different validation rules that have to be applied to the same column in table "data_value".
Again I'm asking for some hints how to do so. Has anyone some suggestions?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4109528#4109528
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4109528
More information about the jboss-user
mailing list