-
1. Re: 'edit' object through datatable page
gavin.king Jul 1, 2006 9:43 AM (in response to trouby)Way too vague:
What does "injected" mean? @DataModelSelection? Something else?
What scope is myEjbBean? What scope is the object that backs the edit page? etc...
Please show your actual code. -
2. Re: 'edit' object through datatable page
trouby Jul 1, 2006 10:00 AM (in response to trouby)Eh, I'm sorry, here are some more details:
"injected" means 'DataModelSelection'
my 'DataModelSelection' object code (the intersting part)@Scope(ScopeType.EVENT) @Name("role") @Table(name="ROLE") @Entity public class Role implements Serializable { private long roleId; private String name; private String description; public void setRoleId(long roleId) { this.roleId = roleId; } @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name="ROLE_ID") public long getRoleId() { return roleId; } public void setName(String name) { this.name = name; } @Length(min=3, max=40) @NotNull //seam @Column(name="NAME", nullable=false) public String getName() { return name; } .... }
My ejb3 used for actions:@Stateless() @Name("roleManager") @Interceptors( {org.jboss.seam.ejb.SeamInterceptor.class} ) public class RoleBean implements RoleManagerLocal,RoleManagerRemote { //For insertions @In(create=true) @Valid Role role; @DataModel private List<Role> roleList; @DataModelSelection @Out(required=false) private Role selectedRole; /** * Injected entity manager */ //@PersistenceContext @PersistenceContext public EntityManager em; ....
here's the 'listRoles.xhtml' with the datatable of the DataModel (roleList) with the actions edit/delete I explained in the first post,<t:dataTable id="rolesDataTableList" styleClass="scrollerTable" headerClass="standardTable_Header" footerClass="standardTable_Header" rowClasses="standardTable_Row1,standardTable_Row2" columnClasses="standardTable_Column,standardTable_ColumnCentered,standardTable_Column" var="role" value="#{roleList}" preserveDataModel="false" rows="10" > <h:column> <f:facet name="header"> <h:outputText value="#{msgs.id}" /> </f:facet> <h:outputText value="#{role.roleId}" /> </h:column> <h:column> <f:facet name="header"> <h:outputText value="#{msgs.name}" /> </f:facet> <h:outputText value="#{role.name}" /> </h:column> <h:column> <f:facet name="header"> <h:outputText value="#{msgs.description}" /> </f:facet> <h:outputText value="#{role.description}" /> </h:column> <h:column> <f:facet name="header"> <h:outputText value="#{msgs.actions}" /> </f:facet> <f:facet name="header"><h:outputText value="#{msgs.actions}" /></f:facet> <h:outputLink value="roleEdit.seam">Edit <f:param name="roleId" value="#{role.roleId}"/> </h:outputLink> </h:column> </t:dataTable>
clicking on 'edit' link redirects to the page but 'role' seems to be empty.
Thanks a lot. -
3. Re: 'edit' object through datatable page
gavin.king Jul 1, 2006 10:07 AM (in response to trouby)You still didn't show the code for roleEdit.
-
4. Re: 'edit' object through datatable page
trouby Jul 1, 2006 10:12 AM (in response to trouby)Hey again,
It is actually almost empty, I just added one input tag to see if the selected 'role' from last page is accessible...<div class="entry"> <div class="label"><h:outputLabel for="description">#{msgs.description}</h:outputLabel></div> <div class="input"> <h:inputText id="description" value="#{role.description}" required="true"/><br/> <span class="errors"><h:message for="description" /></span> </div> </div>
in order to see if it's injected into role entity...
the plan was add an action for the whole form which merge the updated entity...
Thanks. -
5. Re: 'edit' object through datatable page
gavin.king Jul 1, 2006 10:15 AM (in response to trouby)Actually, your roleManager class looks broken, but its hard to say for sure.
It's a stateless component, hence the @DataModel scope defaults to EVENT, which means that the @DataModelSelection will always be null.
I have no idea what "@In(create=true) @Valid Role role" is for, but since you decided not to post all the code for that class, I can't tell if its right or wrong.
As a first step, you need to use @DataModel(scope=SESSION) to ensure that the @DataModelSelection will work.
In future, if I ask you to post code, please post _all_ of it, TIA. -
6. Re: 'edit' object through datatable page
gavin.king Jul 1, 2006 10:16 AM (in response to trouby)"trouby" wrote:
It is actually almost empty, I just added one input tag to see if the selected 'role' from last page is accessible...
The Java code. -
7. Re: 'edit' object through datatable page
trouby Jul 1, 2006 10:25 AM (in response to trouby)Hey again,
'@In(create=true) @Valid Role role' is irrelevant for this,
I have another page named 'roleAdd.xhtml' which its data is submitted to this entity, I hope it is valid...
I did post the code for that class... see above, it is the class with the @entity / @name("role"); annotations.
regarding the stateless context of 'roleManager', it must be stateful in order to keep the state of the 'DataModelSelection' entity?
I do not need the entity to be accessible for the whole session, just for the next page for editing...
Thanks a lot :) -
8. Re: 'edit' object through datatable page
gavin.king Jul 1, 2006 10:30 AM (in response to trouby)Oh OK, I see what you've tried to do.
No, that will definitely not work. You never outject the value of the @DataModelSelection into the context variable named "role".
Seriously, you would be much better off taking a look at how the booking demo and the blog demo handle navigation from a list. They each use a different approach (booking demo uses @DataModelSelection, blog demo uses @RequestParameter). There are several variations upon both approaches. -
9. Re: 'edit' object through datatable page
trouby Jul 1, 2006 10:51 AM (in response to trouby)yeah,
I see the problem...
Well, I looked at both examples,
blog example has two actions, delete/select, both use an action at the backend and make a usage of the 'DataModelSelection' object,
I couldnt find any example that links from a datatable selected row to another page without passing through an action... :(
Thanks a lot. -
10. Re: 'edit' object through datatable page
trouby Jul 1, 2006 10:53 AM (in response to trouby)yeah,
I see the problem...
Well, I looked at both examples,
I couldnt find any example that links from a datatable selected row to another page without passing through an action... :-/
Thanks a lot. -
11. Re: 'edit' object through datatable page
gavin.king Jul 1, 2006 10:57 AM (in response to trouby)It is *totally* possible to do this in pull-MVC style, without using an action.
Perhaps the easiest way for you us to use an @Factory method. -
12. Re: 'edit' object through datatable page
gavin.king Jul 1, 2006 10:58 AM (in response to trouby)ie. an @Factory method that outjects the Role, after either getting its id from a request parameter, or calling back to the other component to get the @DataModelSelection.
-
13. Re: 'edit' object through datatable page
trouby Jul 1, 2006 11:49 AM (in response to trouby)Cool,
that what I'm looking for, it's really a waste of an action / navigation-rule for raising an 'edit' form for the selected @DataObjectSelection entity,
Are there any examples for this? it'll be nice to see a simple CRUD app,
I appriciate your help. -
14. Re: 'edit' object through datatable page
trouby Jul 2, 2006 4:55 AM (in response to trouby)Hey,
back to this, if someone is interested, I found two options (as directed by Gavin)
1) using factory method for outjecting the selected entity, but since I already have too much factory methods I passed away
2) outjecting the selected object by handling the ID of the selected object as a parameter:
1) in the datatable list, add an '<f:param> tag, specifying the ID of the entity"
2) add under META-INF/pages.xml file the view-id of the page related for editing/handling the selected entity with an action on a bean to outject the selected entity by using '@RequestParameter("paramName')
The 'blog' sample works with an MVC style and makes a usage of pages.xml and parameters, so you can take a look at it.
Cheers.